From 234c25bc8761a4d41bc5b4aa362449cf3e806e13 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 17 Sep 2021 20:09:19 +0800 Subject: *unit image effect --- Assets/Scripts/Unit/UnitDetail.cs | 82 +++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 25 deletions(-) (limited to 'Assets/Scripts/Unit/UnitDetail.cs') diff --git a/Assets/Scripts/Unit/UnitDetail.cs b/Assets/Scripts/Unit/UnitDetail.cs index 3d075451..3f7f23e9 100644 --- a/Assets/Scripts/Unit/UnitDetail.cs +++ b/Assets/Scripts/Unit/UnitDetail.cs @@ -1,4 +1,5 @@ using System; +using UnityEngine.Serialization; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -110,63 +111,86 @@ public enum EUnitReferencePoint [Serializable] public class UnitReferencePointDictionary : SerializableDictionary { } +public enum EBodyPart +{ + Body = 0, // main body +} + +[Serializable] +public class BodyPartRenderer +{ + [SerializeField] public EBodyPart tag; + [SerializeField] public Renderer renderer; +} + +public interface IBodyRendererAgent +{ + BodyPartRenderer mainRenderer { get; } + BodyPartRenderer[] renderers{ get; } +} + +public interface IBodyJointAgent +{ + UnitBoneDictionary bones { get; } + UnitReferencePointDictionary referencePoints { get; } +} + // 角色的prefab附加数据 // * afterimage的prefab // * 骨骼映射 // * 武器 [DisallowMultipleComponent] -public class UnitDetail : MonoBehaviour +public class UnitDetail : MonoBehaviour, IBodyRendererAgent, IBodyJointAgent { public bool showGizmos; [Tooltip("残影用的prefab")] - public string afterImageAvatarPath; - - public UnitBoneDictionary bones; - - public UnitReferencePointDictionary referencePoints; + public string afterImageAvatarPath; + + UnitBoneDictionary IBodyJointAgent.bones { get { return m_Bones; } } + [FormerlySerializedAs("bones")] + public UnitBoneDictionary m_Bones; + + UnitReferencePointDictionary IBodyJointAgent.referencePoints { get { return m_ReferencePoints; } } + [FormerlySerializedAs("referencePoints")] + public UnitReferencePointDictionary m_ReferencePoints; - //public Vector2 snapshotBound; public float snapshotBound; - private SkinnedMeshRenderer m_meshRenderer; - public SkinnedMeshRenderer meshRenderer - { - get - { - if (!m_meshRenderer) - m_meshRenderer = this.gameObject.GetComponentInChildren(); - return m_meshRenderer; - } - } + BodyPartRenderer IBodyRendererAgent.mainRenderer { get { return m_MainRenderer; } } + [SerializeField] private BodyPartRenderer m_MainRenderer; + BodyPartRenderer[] IBodyRendererAgent.renderers { get { return m_Renderers; } } + [SerializeField] private BodyPartRenderer[] m_Renderers; public Vector3 center { get { - return meshRenderer.bounds.center; + if (m_MainRenderer == null || m_MainRenderer.renderer == null) + return Vector3.zero ; + return m_MainRenderer.renderer.bounds.center; } } public UnitDetail() - { - bones = new UnitBoneDictionary(); + { + m_Bones = new UnitBoneDictionary(); foreach(EUnitBone e in Enum.GetValues(typeof(EUnitBone))) - { - bones.Add(e, null); + { + m_Bones.Add(e, null); } } public Transform GetBone(EUnitBone bone) { - if (bones.ContainsKey(bone)) - return bones[bone]; + if (m_Bones.ContainsKey(bone)) + return m_Bones[bone]; return null; } public bool HasBone(EUnitBone bone) { - return bones.ContainsKey(bone); + return m_Bones.ContainsKey(bone); } private void OnDrawGizmos() @@ -176,4 +200,12 @@ public class UnitDetail : MonoBehaviour Gizmos.DrawWireCube(center, new Vector3(snapshotBound, snapshotBound, 0)); } + IEnumerator GetRenderers() + { + for(int i = 0; i < m_Renderers.Length; ++i) + { + yield return m_Renderers[i].renderer; + } + } + } \ No newline at end of file -- cgit v1.1-26-g67d0