using System; using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif // 某个动画的数据,包括帧事件、碰撞盒、速度曲线 [CreateAssetMenu(fileName = "Animation Data")] public class AnimationData : ScriptableObject { public string animationName; public string animationPath; public List animationEvents; public List hurtBoxes; public List hitBoxes; public List throwBoxes; public List blockBoxes; public List defendBoxes; // 对应的进度的播放速度,默认是1 public AnimationCurve curve; public int GetBoxesCount() { int hurt = hurtBoxes != null ? hurtBoxes.Count : 0; int hit = hitBoxes != null ? hitBoxes.Count : 0; int thro = throwBoxes != null ? throwBoxes.Count : 0; int block = blockBoxes != null ? blockBoxes.Count : 0; int defend = defendBoxes != null ? defendBoxes.Count : 0; return hurt + hit + thro + block + defend; } public void AddBox(ref 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; } 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 }