diff options
author | chai <chaifix@163.com> | 2021-07-22 18:34:47 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-07-22 18:34:47 +0800 |
commit | cb893e1e5e4820cb800836cf6b8a79a1cd986cdc (patch) | |
tree | c96f8020c760d89d418684b71de294556d6961d3 /Assets/Scripts/Unit/AnimationData.cs | |
parent | f7f2ebc0ce06aaf7d34325258c9bfe689043de94 (diff) |
*misc
Diffstat (limited to 'Assets/Scripts/Unit/AnimationData.cs')
-rw-r--r-- | Assets/Scripts/Unit/AnimationData.cs | 70 |
1 files changed, 68 insertions, 2 deletions
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<ColliderData> throwBoxes;
public List<ColliderData> blockBoxes;
public List<ColliderData> 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<AnimationEventBase>();
+ animationEvents.Add(animEvent);
+ }
+
+ public List<AnimationEventBase> GetAnimationEventsAtFrame(int frame)
+ {
+ if (animationEvents == null)
+ return null;
+
+ List<AnimationEventBase> events = ListPool<AnimationEventBase>.Get();
+ events.Clear();
+ foreach (var animeEvent in animationEvents)
+ {
+ if(animeEvent.startFrame == frame)
+ {
+ events.Add(animeEvent);
+ }
+ }
+ return events;
+ }
+
+ public List<int> GetAnimationEventFrameIndices()
+ {
+ if (animationEvents == null)
+ return null;
+
+ List<int> frames = ListPool<int>.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
+
}
|