From cb893e1e5e4820cb800836cf6b8a79a1cd986cdc Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 22 Jul 2021 18:34:47 +0800 Subject: *misc --- Assets/Scripts/Unit/AnimationData.cs | 70 ++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'Assets/Scripts/Unit/AnimationData.cs') diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs index 72a3db24..f1204a50 100644 --- a/Assets/Scripts/Unit/AnimationData.cs +++ b/Assets/Scripts/Unit/AnimationData.cs @@ -1,6 +1,10 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif // 某个动画的数据,包括帧事件、碰撞盒 [CreateAssetMenu(fileName = "Animation Data")] @@ -16,7 +20,7 @@ public class AnimationData : ScriptableObject public List throwBoxes; public List blockBoxes; public List defendBoxes; - + public int GetBoxesCount() { int hurt = hurtBoxes != null ? hurtBoxes.Count : 0; @@ -71,4 +75,66 @@ public class AnimationData : ScriptableObject return null; } + public void AddEvent(AnimationEventBase animEvent) + { + if (this.animationEvents == null) + this.animationEvents = new List(); + animationEvents.Add(animEvent); + } + + public List GetAnimationEventsAtFrame(int frame) + { + if (animationEvents == null) + return null; + + List events = ListPool.Get(); + events.Clear(); + foreach (var animeEvent in animationEvents) + { + if(animeEvent.startFrame == frame) + { + events.Add(animeEvent); + } + } + return events; + } + + public List GetAnimationEventFrameIndices() + { + if (animationEvents == null) + return null; + + List frames = ListPool.Get(); + frames.Clear(); + foreach (var animeEvent in animationEvents) + { + if (!frames.Contains(animeEvent.startFrame)) + { + frames.Add(animeEvent.startFrame); + } + } + return frames; + } + + public void DeleteEvent(AnimationEventBase animEvent) + { + if(animationEvents.Contains(animEvent)) + { + animationEvents.Remove(animEvent); + } + } + +#if UNITY_EDITOR + public void OnSaveToDisk() + { + foreach(var animEvent in animationEvents) + { + if(!AssetDatabase.IsSubAsset(animEvent)) + { + AssetDatabase.AddObjectToAsset(animEvent, this); + } + } + } +#endif + } -- cgit v1.1-26-g67d0