//--------------------------------------------------- // Play //--------------------------------------------------- public void Play(string prefabPath, Vector3 pos, Vector3 rot, playeDelegate callback = null) { if (_effectList.ContainsKey(prefabPath) == false) { StartCoroutine(LoadCoroutine(prefabPath, pos, rot, callback)); } else { bool isCacheUse = false; EffectData data = _effectList[prefabPath]; for (int i = 0; i < data._cacheList.Count; i++) { GameObject go = data._cacheList[i]; if (go.activeSelf == false) { isCacheUse = true; go.transform.position = pos; go.transform.Rotate(rot); go.SetActive(true); if (callback != null) { callback(go); } break; } } if (isCacheUse == false) { GameObject go = Instantiate(data._originalPrefab); go.transform.position = pos; go.transform.Rotate(rot); data._cacheList.Add(go); if (callback != null) { callback(go); } } } }
//--------------------------------------------------- // LoadCoroutine //--------------------------------------------------- IEnumerator LoadCoroutine(string path, Vector3 pos, Vector3 rot, playeDelegate callback) { yield return(Common.LoadAsync(path, (obj) => { EffectData data = new EffectData(path); data._originalPrefab = obj as GameObject; GameObject go = GameObject.Instantiate(data._originalPrefab); data._cacheList.Add(go); go.transform.position = pos; go.transform.Rotate(rot); _effectList.Add(path, data); if (callback != null) { callback(go); } })); }