From 172d4723c7405d2e748ed03267ca10be9711212b Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 9 Jul 2021 19:17:38 +0800 Subject: *misc --- Assets/Scripts/Unit/AnimationData.cs | 44 +++++++++++++++++++ Assets/Scripts/Unit/Collider/ColliderData.cs | 63 +++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) (limited to 'Assets/Scripts/Unit') diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs index 4ee79cf9..8717cf87 100644 --- a/Assets/Scripts/Unit/AnimationData.cs +++ b/Assets/Scripts/Unit/AnimationData.cs @@ -27,4 +27,48 @@ public class AnimationData : ScriptableObject return hurt + hit + thro + block + defend; } + public void AddBox(List boxList, ColliderData box) + { + if (boxList == null) + { + boxList = new List(); + return; + } + boxList.Add(box); + } + + public void DeleteBox(ColliderData box) + { + if (hurtBoxes != null) hurtBoxes.Remove(box); + if (hitBoxes != null) hitBoxes.Remove(box); + if (throwBoxes != null) throwBoxes.Remove(box); + if (blockBoxes != null) blockBoxes.Remove(box); + if (defendBoxes != null) defendBoxes.Remove(box); + } + + public ColliderData GetColliderByIndex(int index) + { + if (hurtBoxes != null && hurtBoxes.Count > index) + return hurtBoxes[index]; + else + index -= hurtBoxes.Count; + if (hitBoxes != null && hitBoxes.Count > index) + return hitBoxes[index]; + else + index -= hitBoxes.Count; + if (throwBoxes != null && throwBoxes.Count > index) + return throwBoxes[index]; + else + index -= throwBoxes.Count; + if (blockBoxes != null && blockBoxes.Count > index) + return blockBoxes[index]; + else + index -= blockBoxes.Count; + if (defendBoxes != null && defendBoxes.Count > index) + return defendBoxes[index]; + else + index -= defendBoxes.Count; + return null; + } + } diff --git a/Assets/Scripts/Unit/Collider/ColliderData.cs b/Assets/Scripts/Unit/Collider/ColliderData.cs index 744e6a45..b4ae17c5 100644 --- a/Assets/Scripts/Unit/Collider/ColliderData.cs +++ b/Assets/Scripts/Unit/Collider/ColliderData.cs @@ -3,13 +3,20 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +public struct ColliderInfo +{ + public bool active; + public Vector3 position; + public Vector3 size; +} + [Serializable] public class ColliderData { [Serializable] public class ColliderFrame { - public int frameIndex; + public int frame; public bool active; public Vector3 position; public Vector3 size; @@ -20,4 +27,58 @@ public class ColliderData public ColliderBox.Pivot pivot; public List frames; + + public ColliderData(ColliderBox.EColliderType type, ColliderBox.Pivot pivot) + { + this.type = type; + this.pivot = pivot; + this.frames = new List(); + } + + public ColliderInfo GetColliderInfo() + { + ColliderInfo info = new ColliderInfo(); + + return info; + } + + public void AddFrame(int frameIndex) + { + if (frames == null) + frames = new List(); + ColliderFrame frame = new ColliderFrame(); + frame.frame = frameIndex; + frame.active = true; + frame.position = Vector3.zero; + frame.size = Vector3.one; + frames.Add(frame); + frames.Sort((a, b) => { + if (a == null) + return 1; + if (b == null) + return -1; + if (a.frame < b.frame) + return -1; + if (a.frame > b.frame) + return 1; + return 0; + }); + } + + public void DeleteFrame(int frameIndex) + { + if (frames == null) + return; + ColliderFrame frame = null; + foreach(var f in frames) + { + if (f.frame == frameIndex) + frame = f; + } + if(frame != null) + { + frames.Remove(frame); + } + } + } -- cgit v1.1-26-g67d0