summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Unit/TimelineEventProxy.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-08-09 08:47:48 +0800
committerchai <chaifix@163.com>2021-08-09 08:47:48 +0800
commit7669c3afcbd71f06233bce12bb521c582c07ee5b (patch)
tree92a15b1c214385a53362a7e704fef8e67c7102ad /Assets/Scripts/Unit/TimelineEventProxy.cs
parent754ceacd8ab62e7094f1827ae45ea16a502725ad (diff)
*misc
Diffstat (limited to 'Assets/Scripts/Unit/TimelineEventProxy.cs')
-rw-r--r--Assets/Scripts/Unit/TimelineEventProxy.cs125
1 files changed, 125 insertions, 0 deletions
diff --git a/Assets/Scripts/Unit/TimelineEventProxy.cs b/Assets/Scripts/Unit/TimelineEventProxy.cs
new file mode 100644
index 00000000..00b5f1dc
--- /dev/null
+++ b/Assets/Scripts/Unit/TimelineEventProxy.cs
@@ -0,0 +1,125 @@
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Collections.Generic;
+using UnityEngine;
+#if UNITY_EDITOR
+using UnityEditor;
+#endif
+
+// 执行帧事件
+[DisallowMultipleComponent]
+public partial class TimelineEventProxy
+{
+ 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;
+ public const int FPS = 30; // timeline 每秒采样30次
+
+ private int m_PrevFrame = -1;
+
+ private UnitAnimation m_UnitAnimation;
+
+ private Transform m_Root;
+
+ public TimelineEventProxy(Transform root, UnitAnimation unitAnimation = null)
+ {
+ m_Root = root;
+ }
+
+ 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<int> framesHasEvent = animData.GetAnimationEventFrameIndices();
+ if (framesHasEvent.Contains(i))
+ {
+ List<AnimationEventBase> events = animData.GetAnimationEventsAtFrame(i);
+ ExecuteEvents(events);
+ ListPool<AnimationEventBase>.Release(events);
+ }
+ ListPool<int>.Release(framesHasEvent);
+ }
+ }
+ m_PrevFrame = frame;
+ }
+
+ void ExecuteEvents(List<AnimationEventBase> 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<FxClear>();
+ onClear.RunInEditor = true;
+ onClear.Initialize(new PlayEffectInfo(path, EffectPlayTypes.Oneshot, m_Root, effect.position, effect.rotation, effect.scale, 0, false));
+ }
+#endif
+ }
+
+ void EventCamera_Shake(AnimationEventBase animEvent)
+ {
+
+ }
+
+ #endregion
+} \ No newline at end of file