From 494d3f727786ff70753692d8de019d9600a007e1 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 3 Aug 2021 19:33:43 +0800 Subject: *misc --- Assets/Scripts/Unit/UnitTimeline.cs | 115 ++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Assets/Scripts/Unit/UnitTimeline.cs (limited to 'Assets/Scripts/Unit/UnitTimeline.cs') diff --git a/Assets/Scripts/Unit/UnitTimeline.cs b/Assets/Scripts/Unit/UnitTimeline.cs new file mode 100644 index 00000000..ba8e652a --- /dev/null +++ b/Assets/Scripts/Unit/UnitTimeline.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections; +using System.Reflection; +using System.Collections.Generic; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +// 处理动画帧事件和碰撞盒 +[DisallowMultipleComponent] +public partial class UnitTimeline : MonoBehaviour +{ + public enum EEventType + { + EventCamera_Zoom, // 相机聚焦 + EventCamera_Shake, // 相机晃动 + EventCamera_Blur, // 相机模糊 + EventCamera_WhiteOut, // 相机白屏 + + EventMesh_AfterImage, // 角色残像 + EventMesh_Fade, // 角色透明度 + EventMesh_Gloss, // 角色泛光 + + EventEnv_Dark, + EventEnv_Exposure, + + EventUI_Drift, // + EventUI_Blur, // + + EventProjectile, // 发射体 + EventEffect, // 特效 + EventSound, // 音效 + + EventBulletTime, // 子弹时间 + } + + public const int kMaxEventsPerFrame = 10; + + private int m_PrevFrame = -1; + + public static Type GetTypeByName(string name) + { + Type type = Type.GetType(name); + return type; + } + + public void ExecuteAnimationEvents(AnimationData animData, float animFrame) + { + if (animData == null) + return; + int frame = (int)animFrame; + if (frame != m_PrevFrame) + { + for (int i = m_PrevFrame + 1; i <= frame; i++) + { + List framesHasEvent = animData.GetAnimationEventFrameIndices(); + if (framesHasEvent.Contains(i)) + { + List events = animData.GetAnimationEventsAtFrame(i); + ExecuteEvents(events); + ListPool.Release(events); + } + ListPool.Release(framesHasEvent); + } + } + m_PrevFrame = frame; + } + + void ExecuteEvents(List events) + { + if (events == null || events.Count == 0) + return; + foreach (var e in events) + { + string name = e.type.ToString(); + MethodInfo method = GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(AnimationEventBase) }, null); + if (method != null) + { + object[] param = new object[] { e }; + method.Invoke(this, param); + } + } + } + + #region Event handle + + void EventEffect(AnimationEventBase animEvent) + { + EventEffect effect = animEvent as EventEffect; + if (effect == null) + return; + string path = effect.effectPath; +#if UNITY_EDITOR + GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; + if (prefab != null) + { + GameObject root = new GameObject(); + + GameObject go = GameObject.Instantiate(prefab); + go.transform.SetParent(root.transform); + FxClear onClear = root.AddComponent(); + onClear.RunInEditor = true; + onClear.Initialize(new PlayEffectInfo(path, EffectPlayTypes.Oneshot, transform, effect.position, effect.rotation, effect.scale, 0, false)); + } +#endif + } + + void EventCamera_Shake(AnimationEventBase animEvent) + { + + } + + #endregion +} \ No newline at end of file -- cgit v1.1-26-g67d0