diff options
Diffstat (limited to 'Assets/Scripts/Effects')
-rw-r--r-- | Assets/Scripts/Effects/Spark.cs | 36 | ||||
-rw-r--r-- | Assets/Scripts/Effects/Spark.cs.meta (renamed from Assets/Scripts/Effects/SparkManager.cs.meta) | 2 | ||||
-rw-r--r-- | Assets/Scripts/Effects/SparkManager.cs | 18 | ||||
-rw-r--r-- | Assets/Scripts/Effects/SparksManager.cs | 91 | ||||
-rw-r--r-- | Assets/Scripts/Effects/SparksManager.cs.meta | 11 |
5 files changed, 139 insertions, 19 deletions
diff --git a/Assets/Scripts/Effects/Spark.cs b/Assets/Scripts/Effects/Spark.cs new file mode 100644 index 00000000..5f8856c4 --- /dev/null +++ b/Assets/Scripts/Effects/Spark.cs @@ -0,0 +1,36 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Spark : MonoBehaviour
+{
+ public string Name;
+ public float LifeTime;
+
+ private float time;
+
+ public Transform Host;
+
+ private void Awake()
+ {
+ }
+
+ private void OnEnable()
+ {
+ time = 0;
+ }
+
+ private void Update()
+ {
+ time += Time.deltaTime;
+ if(time > LifeTime)
+ {
+ SparksManager.Instance.CycleSpark(this);
+ }
+ if (Host != null)
+ {
+ transform.position = Host.position;
+ }
+ }
+
+}
diff --git a/Assets/Scripts/Effects/SparkManager.cs.meta b/Assets/Scripts/Effects/Spark.cs.meta index af46cd69..c1c05447 100644 --- a/Assets/Scripts/Effects/SparkManager.cs.meta +++ b/Assets/Scripts/Effects/Spark.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 91eb1bc63c2a55144830875dedab3793 +guid: 35fa504215dc5194a944721d5cc378af MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Effects/SparkManager.cs b/Assets/Scripts/Effects/SparkManager.cs deleted file mode 100644 index 0146d2e6..00000000 --- a/Assets/Scripts/Effects/SparkManager.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class SparkManager : MonoBehaviour -{ - // Start is called before the first frame update - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } -} diff --git a/Assets/Scripts/Effects/SparksManager.cs b/Assets/Scripts/Effects/SparksManager.cs new file mode 100644 index 00000000..6825f615 --- /dev/null +++ b/Assets/Scripts/Effects/SparksManager.cs @@ -0,0 +1,91 @@ +using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System;
+
+public class SparksManager : MonoBehaviour
+{
+ public static SparksManager Instance;
+
+ public Spark[] SparkTemplates;
+
+ public Transform Root_Pool;
+
+ List<Spark> m_Pool = new List<Spark>();
+
+ private void Awake()
+ {
+ Instance = this;
+ }
+
+ Spark GetSparkTemplate(string name)
+ {
+ foreach (var effect in SparkTemplates)
+ {
+ if (effect != null && effect.Name == name)
+ {
+ return effect;
+ }
+ }
+ return null;
+ }
+
+ Spark RecycleSpark(string name)
+ {
+ foreach (var effect in m_Pool)
+ {
+ if (effect != null && effect.Name == name)
+ {
+ return effect;
+ }
+ }
+ return null;
+ }
+
+ public void PlaySpark(string name, Vector3 position)
+ {
+ Spark effect = RecycleSpark(name);
+ if (effect == null)
+ {
+ Spark temp = GetSparkTemplate(name);
+ effect = UnityEngine.Object.Instantiate(temp);
+ }
+ else
+ {
+ m_Pool.Remove(effect);
+ }
+
+ effect.Host = null;
+ effect.transform.position = position;
+ effect.transform.SetParent(this.transform);
+ effect.gameObject.SetActive(true);
+ }
+
+
+ public void PlaySpark(string name, Transform host)
+ {
+ Spark effect = RecycleSpark(name);
+ if (effect == null)
+ {
+ Spark temp = GetSparkTemplate(name);
+ effect = UnityEngine.Object.Instantiate(temp);
+ }
+ else
+ {
+ m_Pool.Remove(effect);
+ }
+ effect.Host = host;
+ effect.transform.position = host.position;
+ effect.transform.SetParent(this.transform);
+ effect.gameObject.SetActive(true);
+ }
+
+ // 回收特效
+ public void CycleSpark(Spark effect)
+ {
+ effect.gameObject.SetActive(false);
+ effect.transform.SetParent(Root_Pool);
+ m_Pool.Add(effect);
+ }
+
+}
diff --git a/Assets/Scripts/Effects/SparksManager.cs.meta b/Assets/Scripts/Effects/SparksManager.cs.meta new file mode 100644 index 00000000..84d3b608 --- /dev/null +++ b/Assets/Scripts/Effects/SparksManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1cf80a321371944a9a3e8dfbe7e5134 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |