summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/UnitDetail.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-17 20:09:19 +0800
committerchai <chaifix@163.com>2021-09-17 20:09:19 +0800
commit234c25bc8761a4d41bc5b4aa362449cf3e806e13 (patch)
tree69cc0b7002ac8018af1806de366526dfc089d49e /Assets/Scripts/Unit/UnitDetail.cs
parentea4624fbef6e9d8f58da12be363807eb19a37b53 (diff)
*unit image effect
Diffstat (limited to 'Assets/Scripts/Unit/UnitDetail.cs')
-rw-r--r--Assets/Scripts/Unit/UnitDetail.cs82
1 files changed, 57 insertions, 25 deletions
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<EUnitReferencePoint, Transform> { }
+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<SkinnedMeshRenderer>();
- 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