diff options
Diffstat (limited to 'Assets/Scripts/Effects/EffectsManager.cs')
-rw-r--r-- | Assets/Scripts/Effects/EffectsManager.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Assets/Scripts/Effects/EffectsManager.cs b/Assets/Scripts/Effects/EffectsManager.cs new file mode 100644 index 00000000..f62b0bdb --- /dev/null +++ b/Assets/Scripts/Effects/EffectsManager.cs @@ -0,0 +1,73 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System;
+
+public class EffectsManager : MonoBehaviour
+{
+ public static EffectsManager Instance;
+
+ public Effect[] EffectTemplates;
+
+ public Transform Root_Pool;
+
+ List<Effect> m_Pool = new List<Effect>();
+
+ private void Awake()
+ {
+ Instance = this;
+ }
+
+ Effect GetEffectTemplate(string name)
+ {
+ foreach(var effect in EffectTemplates)
+ {
+ if(effect != null && effect.Name == name)
+ {
+ return effect;
+ }
+ }
+ return null;
+ }
+
+ Effect RecycleEffect(string name)
+ {
+ foreach(var effect in m_Pool)
+ {
+ if (effect != null && effect.Name == name)
+ {
+ return effect;
+ }
+ }
+ return null;
+ }
+
+ public void PlayEffect(string name, Vector3 position, Vector3 rotation, Vector3 scale)
+ {
+ Effect effect = RecycleEffect(name);
+ if(effect == null)
+ {
+ Effect temp = GetEffectTemplate(name);
+ effect = UnityEngine.Object.Instantiate(temp);
+ }
+ else
+ {
+ m_Pool.Remove(effect);
+ }
+
+ effect.transform.position = position;
+ effect.transform.rotation = Quaternion.Euler(rotation);
+ effect.transform.localScale = scale;
+ effect.transform.SetParent(this.transform);
+ effect.gameObject.SetActive(true);
+ }
+
+ // 回收特效
+ public void CycleEffect(Effect effect)
+ {
+ effect.gameObject.SetActive(false);
+ effect.transform.SetParent(Root_Pool);
+ m_Pool.Add(effect);
+ }
+
+}
|