From cb893e1e5e4820cb800836cf6b8a79a1cd986cdc Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 22 Jul 2021 18:34:47 +0800 Subject: *misc --- Assets/Scripts/Effects/FxClear.cs | 422 +++++++++++++++++++++ Assets/Scripts/Effects/FxClear.cs.meta | 11 + Assets/Scripts/Unit/AnimationData.cs | 70 +++- Assets/Scripts/Unit/Events/AnimationEventBase.cs | 8 +- Assets/Scripts/Unit/Events/EventAfterImage.cs | 16 - Assets/Scripts/Unit/Events/EventAfterImage.cs.meta | 11 - Assets/Scripts/Unit/Events/EventBulletTime.cs | 9 - Assets/Scripts/Unit/Events/EventBulletTime.cs.meta | 11 - Assets/Scripts/Unit/Events/EventCameraBlur.cs | 18 - Assets/Scripts/Unit/Events/EventCameraBlur.cs.meta | 11 - Assets/Scripts/Unit/Events/EventCameraShake.cs | 18 - .../Scripts/Unit/Events/EventCameraShake.cs.meta | 11 - Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs | 18 - .../Unit/Events/EventCameraWhiteOut.cs.meta | 11 - Assets/Scripts/Unit/Events/EventCameraZoom.cs | 18 - Assets/Scripts/Unit/Events/EventCameraZoom.cs.meta | 11 - Assets/Scripts/Unit/Events/EventEffect.cs | 17 +- Assets/Scripts/Unit/Events/EventMeshFade.cs | 8 - Assets/Scripts/Unit/Events/EventMeshFade.cs.meta | 11 - Assets/Scripts/Unit/TimelineEvent.cs | 107 +++++- Assets/Scripts/Utils/ListPool.cs | 65 ++++ Assets/Scripts/Utils/ListPool.cs.meta | 11 + 22 files changed, 688 insertions(+), 205 deletions(-) create mode 100644 Assets/Scripts/Effects/FxClear.cs create mode 100644 Assets/Scripts/Effects/FxClear.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventAfterImage.cs delete mode 100644 Assets/Scripts/Unit/Events/EventAfterImage.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventBulletTime.cs delete mode 100644 Assets/Scripts/Unit/Events/EventBulletTime.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventCameraBlur.cs delete mode 100644 Assets/Scripts/Unit/Events/EventCameraBlur.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventCameraShake.cs delete mode 100644 Assets/Scripts/Unit/Events/EventCameraShake.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs delete mode 100644 Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventCameraZoom.cs delete mode 100644 Assets/Scripts/Unit/Events/EventCameraZoom.cs.meta delete mode 100644 Assets/Scripts/Unit/Events/EventMeshFade.cs delete mode 100644 Assets/Scripts/Unit/Events/EventMeshFade.cs.meta create mode 100644 Assets/Scripts/Utils/ListPool.cs create mode 100644 Assets/Scripts/Utils/ListPool.cs.meta (limited to 'Assets/Scripts') diff --git a/Assets/Scripts/Effects/FxClear.cs b/Assets/Scripts/Effects/FxClear.cs new file mode 100644 index 00000000..83d08003 --- /dev/null +++ b/Assets/Scripts/Effects/FxClear.cs @@ -0,0 +1,422 @@ +using UnityEngine; +using UnityEngine.Events; +using System.Collections; +using System.Collections.Generic; + +public enum EffectPlayTypes +{ + //None 이펙트의 경우는 이펙트 관리 대상에서 제외. + None = 0, + Oneshot, + Loop, +} + +public static class TransformEx +{ + + public static void DoRecursively(this Transform root, System.Action action, bool containMe = true) + { + if (containMe) + action(root); + foreach (Transform child in root) + child.DoRecursively(action); + } + +} + +public struct PlayEffectInfo +{ + public int dbId { get; set; } + public string path { get; set; } + public Transform rootTr { get; set; } + public bool bAttached { get; set; } + public Vector3 posOffset { get; set; } + public Vector3 rot { get; set; } + public Vector3 scale { get; set; } + public EffectPlayTypes playEffectType { get; set; } + public bool bUIEffect { get; set; } + + public PlayEffectInfo(string path, EffectPlayTypes type, Transform rootTr, Vector3 posOffset, Vector3 rot, Vector3 scale, int dbId = 0, bool bAttached = false, bool bUIEffect = false) + { + this.path = path; + this.playEffectType = type; + this.rootTr = rootTr; + this.rot = rot; + this.scale = scale; + this.dbId = dbId; + this.bAttached = bAttached; + this.posOffset = posOffset; + this.bUIEffect = bUIEffect; + } +} + +#if UNITY_EDITOR +[ExecuteInEditMode] +#endif +public class FxClear : MonoBehaviour +{ + #region inspector + + [SerializeField] + public float ClearTime = 2f; + + #endregion + + private EffectPlayTypes m_EffectPlayType = EffectPlayTypes.None; + + /// + /// 이름만 root. effect Tr 싱크 위해 사용. + /// + private Transform m_rootTr = null; + private float m_curTime = 0.0f; + //private bool m_bExistTr = false; + private bool m_bAttached = false; + private Vector3 m_offset = Vector3.zero; + private Vector3 m_rot = Vector3.zero; + private Vector3 m_scale = Vector3.zero; + + private int m_ownerDbId = 0; + + public int ownerDbId + { + get + { + return m_ownerDbId; + } + } + + private bool m_bUIEffect = false; + +#if UNITY_EDITOR + private double m_prevTime = 0.0f; + private float m_removeWaitTime = 0.0f; + private bool m_runInEditor = false; + private bool m_destroyRequested = false; + + private List m_Particles = null; + + public bool RunInEditor + { + get + { + return m_runInEditor; + } + set + { + m_runInEditor = value; + } + } +#endif + + private void Awake() + { + // 0 이면 무한 루프로 삭제하지 않게 사용하기로 그래픽과 합의함 - 해당 룰 그대로 가져옴(FxClear에서) + if (ClearTime <= float.Epsilon) + m_EffectPlayType = EffectPlayTypes.Loop; + } + + private void Start() + { +#if UNITY_EDITOR + if (m_runInEditor) + { + UnityEditor.EditorApplication.update += Update; + m_prevTime = UnityEditor.EditorApplication.timeSinceStartup; + return; + } +#endif + } + + private void OnDestroy() + { + Release(); + +#if UNITY_EDITOR + + if (m_runInEditor) + { + if (m_Particles != null) + { + m_Particles.Clear(); + m_Particles = null; + } + } + +#endif + } + + public void Initialize(PlayEffectInfo info) + { + m_EffectPlayType = info.playEffectType; + //m_bExistTr = info.rootTr != null; + m_rootTr = info.rootTr; + m_curTime = 0.0f; + m_offset = info.posOffset; + m_rot = info.rot; + m_scale = info.scale; + m_bAttached = info.bAttached; + m_ownerDbId = info.dbId; + m_bUIEffect = info.bUIEffect; + +#if UNITY_EDITOR + + if (m_runInEditor) + { + if (m_Particles == null) + { + m_Particles = new List(); + + transform.DoRecursively(x => + { + ParticleSystem sys = x.GetComponent(); + + if (sys != null) + { + m_Particles.Add(sys); + sys.Stop(); + } + }); + } + } +#endif + + SyncTr(); + gameObject.SetActive(true); + } + + public void Release() + { + m_rootTr = null; + m_ownerDbId = 0; + m_curTime = 0.0f; + //m_bExistTr = false; + m_bAttached = false; + m_offset = Vector3.zero; + m_rot = Vector3.zero; + m_scale = Vector3.zero; + m_bUIEffect = false; +#if UNITY_EDITOR + m_removeWaitTime = 0.0f; +#endif + } + + private void SyncTr() + { +#if UNITY_EDITOR + if (m_runInEditor) + { + if (m_rootTr == null) + { + transform.position = m_offset; + } + else + { + + transform.localRotation = m_rootTr.rotation; + + if (m_bAttached) + { + transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset); + } + else + { + transform.position = m_rootTr.position - (m_rootTr.rotation * m_offset); + } + } + } + else + { + if (m_rootTr == null) + { + transform.position = m_offset; + } + else + { + if (m_bAttached) + { + transform.localRotation = m_rootTr.rotation;// * Quaternion.LookRotation(Vector3.back); + } + else + { + transform.localRotation = m_rootTr.rotation * Quaternion.LookRotation(Vector3.back); + } + + transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset); + } + } +#else + if (m_rootTr == null) + { + transform.position = m_offset; + } + else + { + if (m_bAttached) + { + transform.localRotation = m_rootTr.rotation;// * Quaternion.LookRotation(Vector3.back); + } + else + { + transform.localRotation = m_rootTr.rotation * Quaternion.LookRotation(Vector3.back); + } + + transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset); + } +#endif + +#if UNITY_EDITOR + + if (m_runInEditor == false && m_bAttached && m_rootTr != null) + { + transform.SetParent(m_rootTr); + + if (m_bUIEffect) + { + transform.localPosition = m_offset; + } + } + +#else + + if (m_bAttached && m_rootTr != null) + { + transform.SetParent(m_rootTr); + if (m_bUIEffect) + { + transform.localPosition = m_offset; + } + } + +#endif + if (m_rot != Vector3.zero) + { + transform.rotation = Quaternion.Euler(m_rot.x, m_rot.y, m_rot.z); + } + + if (m_scale != Vector3.zero) + { + transform.localScale = m_scale; + } + } + + public void Restore() + { + if (m_EffectPlayType == EffectPlayTypes.None) + { + DestroyImmediate(this.gameObject); + return; + } + + //EffectManager.Instance.RestoreEffect(this); + } + +#if UNITY_EDITOR + + private void UpdateInEditMode() + { + if (!m_destroyRequested) + { + double timeDelta = UnityEditor.EditorApplication.timeSinceStartup - m_prevTime; + m_prevTime = UnityEditor.EditorApplication.timeSinceStartup; + + if (m_removeWaitTime <= 0.0f) // 순서 관계.. + { + if (ClearTime > 0.0f) + { + if (ClearTime < m_curTime) + { + List selectBuffer = new List(); + + if (m_Particles != null) + { + for (int i = 0; i < m_Particles.Count; i++) + { + m_Particles[i].Stop(); + m_Particles[i].gameObject.SetActive(false); + } + + Object[] selectedObjects = UnityEditor.Selection.objects; + for (int i = 0; i < selectedObjects.Length; i++) + { + if (m_Particles.Find(e => e.gameObject.GetInstanceID() == selectedObjects[i].GetInstanceID()) == null) + { + selectBuffer.Add(m_Particles[i]); + } + } + UnityEditor.Selection.objects = selectBuffer.ToArray(); + if (UnityEditor.Selection.selectionChanged != null) + { + UnityEditor.Selection.selectionChanged(); + } + } + + m_removeWaitTime = 1.0f; + } + else + { + if (m_Particles != null) + { + for (int i = 0; i < m_Particles.Count; i++) + { + m_Particles[i].Simulate(m_curTime); + } + } + } + } + } + else + { + m_removeWaitTime -= (float)timeDelta; + if (m_removeWaitTime < 0.0f) + { + transform.parent = null; + UnityEditor.EditorApplication.update -= Update; + DestroyImmediate(gameObject); + + m_destroyRequested = true; + return; + } + } + + SyncTr(); + } + } + +#endif + + private void Update() + { + m_curTime += Time.unscaledDeltaTime; + +#if UNITY_EDITOR + if (m_runInEditor) + { + UpdateInEditMode(); + return; + } +#endif + + if (m_EffectPlayType != EffectPlayTypes.Loop && m_curTime >= ClearTime) + { + Restore(); + return; + } + + //rootTr이 애초에 비어있으면 싱크 맞춰줄 필요 없음. - EffectMgr 통해서 관리되지 않는 이펙트. + //if (m_bExistTr == false) + // return; + // + //if (m_rootTr == null || m_rootTr.gameObject.activeInHierarchy == false) + //{ + // Restore(); + // return; + //} + // + //if (m_bAttached == false) + //{ + // return; + //} + // + //SyncTr(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Effects/FxClear.cs.meta b/Assets/Scripts/Effects/FxClear.cs.meta new file mode 100644 index 00000000..2d25b100 --- /dev/null +++ b/Assets/Scripts/Effects/FxClear.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe3f4700e4af0b34b82b4ff79b1d8fec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: 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 + } diff --git a/Assets/Scripts/Unit/Events/AnimationEventBase.cs b/Assets/Scripts/Unit/Events/AnimationEventBase.cs index bcaf9eae..774f7b38 100644 --- a/Assets/Scripts/Unit/Events/AnimationEventBase.cs +++ b/Assets/Scripts/Unit/Events/AnimationEventBase.cs @@ -1,9 +1,11 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; -public class AnimationEventBase : ScriptableObject +public abstract class AnimationEventBase : ScriptableObject { public int startFrame; - public TimelineEvent.EEventType type; + + public abstract TimelineEvent.EEventType type { get; } } diff --git a/Assets/Scripts/Unit/Events/EventAfterImage.cs b/Assets/Scripts/Unit/Events/EventAfterImage.cs deleted file mode 100644 index 9c0ea5ac..00000000 --- a/Assets/Scripts/Unit/Events/EventAfterImage.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventAfterImage : AnimationEventBase -{ - public enum EAfterImageType - { - None = 0, - BlackWhite, - Golden, - } - - public EAfterImageType afterType; - -} diff --git a/Assets/Scripts/Unit/Events/EventAfterImage.cs.meta b/Assets/Scripts/Unit/Events/EventAfterImage.cs.meta deleted file mode 100644 index 9985730b..00000000 --- a/Assets/Scripts/Unit/Events/EventAfterImage.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d07ec6150f55c1844a54dbc664e0c95d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventBulletTime.cs b/Assets/Scripts/Unit/Events/EventBulletTime.cs deleted file mode 100644 index 22c2b83f..00000000 --- a/Assets/Scripts/Unit/Events/EventBulletTime.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventBulletTime : AnimationEventBase -{ - - -} diff --git a/Assets/Scripts/Unit/Events/EventBulletTime.cs.meta b/Assets/Scripts/Unit/Events/EventBulletTime.cs.meta deleted file mode 100644 index 1d2e22dc..00000000 --- a/Assets/Scripts/Unit/Events/EventBulletTime.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 554b381d61ce5494b9b4e60b72521a6b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventCameraBlur.cs b/Assets/Scripts/Unit/Events/EventCameraBlur.cs deleted file mode 100644 index bab672fa..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraBlur.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventCameraBlur : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Unit/Events/EventCameraBlur.cs.meta b/Assets/Scripts/Unit/Events/EventCameraBlur.cs.meta deleted file mode 100644 index 816be65b..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraBlur.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6f064336a95165d4fa6af02fadb70bc0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventCameraShake.cs b/Assets/Scripts/Unit/Events/EventCameraShake.cs deleted file mode 100644 index f352f415..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraShake.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventCameraShake : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Unit/Events/EventCameraShake.cs.meta b/Assets/Scripts/Unit/Events/EventCameraShake.cs.meta deleted file mode 100644 index 7e19dd10..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraShake.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c9aeba330898fc54fb170f0689e5460c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs b/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs deleted file mode 100644 index b9cb1a2e..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventCameraWhiteOut : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs.meta b/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs.meta deleted file mode 100644 index 2c73556e..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraWhiteOut.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f4a27077d030aa54ebbb7c192ca59979 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventCameraZoom.cs b/Assets/Scripts/Unit/Events/EventCameraZoom.cs deleted file mode 100644 index 8efac028..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraZoom.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventCameraZoom : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Unit/Events/EventCameraZoom.cs.meta b/Assets/Scripts/Unit/Events/EventCameraZoom.cs.meta deleted file mode 100644 index 9fb41c39..00000000 --- a/Assets/Scripts/Unit/Events/EventCameraZoom.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5214828735209264c83cf0e3b1c12efe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/Events/EventEffect.cs b/Assets/Scripts/Unit/Events/EventEffect.cs index 65479cb7..449b1e23 100644 --- a/Assets/Scripts/Unit/Events/EventEffect.cs +++ b/Assets/Scripts/Unit/Events/EventEffect.cs @@ -4,10 +4,23 @@ using UnityEngine; public class EventEffect : AnimationEventBase { - public string effectName; + public override TimelineEvent.EEventType type { get { return TimelineEvent.EEventType.EventEffect; } } + + [Tooltip("Effect path")] + public string effectPath; + + [Tooltip("Is attached to a bone")] public bool attached; + + [Tooltip("Bone path attach to")] public string bone; + + [Tooltip("Position offset")] public Vector3 position; - public Quaternion rotation; + + [Tooltip("Rotation in euler")] + public Vector3 rotation; + + [Tooltip("Scale")] public Vector3 scale; } diff --git a/Assets/Scripts/Unit/Events/EventMeshFade.cs b/Assets/Scripts/Unit/Events/EventMeshFade.cs deleted file mode 100644 index ee256b0f..00000000 --- a/Assets/Scripts/Unit/Events/EventMeshFade.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EventMeshFade : AnimationEventBase -{ - -} diff --git a/Assets/Scripts/Unit/Events/EventMeshFade.cs.meta b/Assets/Scripts/Unit/Events/EventMeshFade.cs.meta deleted file mode 100644 index 5ab8c0bf..00000000 --- a/Assets/Scripts/Unit/Events/EventMeshFade.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 761dbef185f094f439b2710ed7e5fcd1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Unit/TimelineEvent.cs b/Assets/Scripts/Unit/TimelineEvent.cs index f0a28ec6..6a69934b 100644 --- a/Assets/Scripts/Unit/TimelineEvent.cs +++ b/Assets/Scripts/Unit/TimelineEvent.cs @@ -1,6 +1,11 @@ -using System.Collections; +using System; +using System.Collections; +using System.Reflection; using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif // 动画帧事件 [DisallowMultipleComponent] @@ -8,33 +13,103 @@ public partial class TimelineEvent: MonoBehaviour { public enum EEventType { - EventCameraZoom, // 相机聚焦 - EventCameraShake, // 相机晃动 - EventCameraBlur, // 相机模糊 - EventCameraWhiteOut, // 相机白屏 - EventAfterImage, // 角色残像 - EventMeshFade, // 角色透明度 - EventMeshGloss, // 角色泛光 - EventProjectile, // 发射体 - EventEffect, // 特效 - EventSound, // 音效 - EventUIDrift, // + 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; - void EventEffect(EventEffect effect) + private int m_PrevFrame = -1; + + public static Type GetTypeByName(string name) { + Type type = Type.GetType(name); + return type; } - void EventAfterImage(EventAfterImage afterImage) + 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 EventMeshFade(EventMeshFade meshFade) + void EventCamera_Shake(AnimationEventBase animEvent) { } -} \ No newline at end of file + #endregion +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/ListPool.cs b/Assets/Scripts/Utils/ListPool.cs new file mode 100644 index 00000000..b9fbd2b8 --- /dev/null +++ b/Assets/Scripts/Utils/ListPool.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; + +public static class ListPool +{ + public static List Get() + { + return ListPool.m_ListPool.Get(); + } + + public static void Release(List toRelease) + { + ListPool.m_ListPool.Release(toRelease); + } + + private static readonly ObjectPool> m_ListPool = new ObjectPool>(null, delegate (List l) + { + l.Clear(); + }); +} + +internal class ObjectPool where T : new() +{ + private readonly Stack m_Stack = new Stack(); + private readonly UnityAction m_ActionOnGet; + private readonly UnityAction m_ActionOnRelease; + + public int countAll { get; private set; } + public int countActive { get { return countAll - countInactive; } } + public int countInactive { get { return m_Stack.Count; } } + + public ObjectPool(UnityAction actionOnGet, UnityAction actionOnRelease) + { + m_ActionOnGet = actionOnGet; + m_ActionOnRelease = actionOnRelease; + } + + public T Get() + { + T element; + if (m_Stack.Count == 0) + { + element = new T(); + countAll++; + } + else + { + element = m_Stack.Pop(); + } + if (m_ActionOnGet != null) + m_ActionOnGet(element); + return element; + } + + public void Release(T element) + { + if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element)) + Debug.LogError("Internal error. Trying to destroy object that is already released to pool."); + if (m_ActionOnRelease != null) + m_ActionOnRelease(element); + m_Stack.Push(element); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/ListPool.cs.meta b/Assets/Scripts/Utils/ListPool.cs.meta new file mode 100644 index 00000000..61b7dcc3 --- /dev/null +++ b/Assets/Scripts/Utils/ListPool.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 385194156796a3241a248d31172defe5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0