123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class EffectUtil
- {
- public static GameObject CreateLanding()
- {
- GameObject gameObj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/Effects/Landing"));
- return gameObj;
- }
- public static GameObject CreateDisappear()
- {
- GameObject gameObj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/Effects/Disappear"));
- return gameObj;
- }
- private static Dictionary<string, List<GameObject>> effectCacheDict = new Dictionary<string, List<GameObject>>();
- public static GameObject CreateEffect(string path)
- {
- GameObject gameObj = null;
- if(effectCacheDict.ContainsKey(path) && effectCacheDict[path].Count > 0)
- {
- gameObj = effectCacheDict[path][0];
- effectCacheDict[path].RemoveAt(0);
- gameObj.SetActive(true);
- ParticleSystem ps = gameObj.GetComponent<ParticleSystem>();
- if(ps != null)
- ps.Play();
- }
- else
- {
- GameObject prefabObj = Resources.Load<GameObject>("Prefabs/Effects/"+path);
- if(prefabObj == null)
- {
- Debuger.LogError("Could not load effect from : "+path);
- return null;
- }
- gameObj = GameObject.Instantiate<GameObject>(prefabObj);
- }
- EffectDelayDestroy delayDes = gameObj.GetComponent<EffectDelayDestroy>();
- if(delayDes != null)
- delayDes.path = path;
- return gameObj;
- }
- public static void Recycle(string path, GameObject obj)
- {
- if(StringUtil.Empty(path))
- {
- GameObject.Destroy(obj);
- Debuger.LogError("Recycal Effect path is empty "+obj);
- return;
- }
- // Debuger.Log("Recycal Effect["+path+"] "+obj);
- if(obj.transform.parent != null)
- obj.transform.SetParent(null);
- ParticleSystem ps = obj.GetComponent<ParticleSystem>();
- if(ps != null)
- ps.Stop();
- obj.SetActive(false);
- if(effectCacheDict.ContainsKey(path))
- {
- effectCacheDict[path].Add(obj);
- }
- else
- {
- List<GameObject> list = new List<GameObject>();
- list.Add(obj);
- effectCacheDict.Add(path, list);
- }
- }
- public static void ClearCache()
- {
- effectCacheDict.Clear();
- }
- }
|