void OnDestroy() { if (showGOs != null) { foreach (var showGO in showGOs) { var goPoolMgr = GameObjectPoolManager.GetInstance(); goPoolMgr?.ReleaseGameObject(showGO); } showGOs.Clear(); } }
public MyParticleInstance GetParticleInstance(string particleName, Action callback) { GameObject gameObject = GameObjectPoolManager.GetInstance().GetGameObject(mTemplete, rootTrans); MyParticleInstance pi = gameObject.GetComponent <MyParticleInstance>(); pi.load(particleName, callback); pi.gameObject.transform.parent = rootTrans; pi.gameObject.transform.localPosition = Vector3.zero; pi.gameObject.SetActive(true); pi.gameObject.name = particleName; return(pi); }
public Callback <GameObject, int> GetOrNewSprite(string viewCode, bool usePool = false, int maxCount = 20) { string viewName = null; GameObject prefabInstance = null; var callback = Callback <GameObject, int> .GetOrNew(); if (!usePool) { EEntityType entityType = EntityUtil.GetEntityTypeByCode(viewCode); if (poolInfos.TryGetValue(entityType, out var poolInfo)) { usePool = true; maxCount = poolInfo.maxCount; } } if (usePool) { if (!GameObjectPoolManager.GetInstance().HasPool(viewCode)) { AssetManager.GetInstance().LoadSprite(viewCode).onSuccess.Set((prefab) => { GameObjectPoolManager.GetInstance().NewPool(viewCode, prefab, maxCount); prefabInstance = GameObjectPoolManager.GetInstance().GetOrCreateGameObject(viewCode); GameObject viewGO = new GameObject(viewName); prefabInstance.transform.SetParent(viewGO.transform, false); callback.onSuccess?.Invoke(prefabInstance); }); } else { prefabInstance = GameObjectPoolManager.GetInstance().GetOrCreateGameObject(viewCode); GameObject viewGO = new GameObject(viewName); prefabInstance.transform.SetParent(viewGO.transform, false); callback.onSuccess?.Invoke(prefabInstance); } } else { AssetManager.GetInstance().LoadSprite(viewCode).onSuccess.Set((prefab) => { if (prefab) { prefabInstance = Object.Instantiate(prefab); callback.onSuccess?.Invoke(prefabInstance); } }); } return(callback); }
public void RefreshEnemyIcon(List <Monster> monsters) { for (int i = 0; i < m_clonedMonsterIcons.Count; i++) { m_clonedMonsterIcons[i].OnSelected -= SelectMonster; GameObjectPoolManager.Recycle(m_clonedMonsterIcons[i]); } for (int i = 0; i < monsters.Count; i++) { MonsterIcon _cloneIcon = GameObjectPoolManager.GetInstance <MonsterIcon>(m_monsterIconSource); _cloneIcon.LinkMonster(monsters[i]); _cloneIcon.OnSelected += SelectMonster; m_clonedMonsterIcons.Add(_cloneIcon); } }
private void PlayEffect(GameObject fxGO, GameObject hangNode, Vector3 position, Action onCompleted = null) { if (fxGO) { fxGO.transform.position = position; if (hangNode != null) { fxGO.transform.SetParent(hangNode.transform, false); } var fxLenMono = fxGO.GetComponent <EffectLengthMono>(); if (fxLenMono != null) { fxLenMono.onCompleted = () => { onCompleted?.Invoke(); GameObjectPoolManager.GetInstance().ReleaseGameObject(fxGO); }; } } }
/// <summary> /// 播放一个特效 /// </summary> /// <param name="code"></param> /// <param name="hangNode"></param> /// <param name="position"></param> /// <param name="onComplete"></param> public void PlayOnce(string code, GameObject hangNode, Vector3 position, Action onCompleted = null) { Callback <GameObject, int> callback; var pool = GameObjectPoolManager.GetInstance().GetPool(code); if (pool == null) { callback = AssetManager.GetInstance().LoadEffect(code); callback.onSuccess += (prefab) => { pool = GameObjectPoolManager.GetInstance().NewPool(code, prefab, 10); var fxGO = pool.GetOrCreate(); PlayEffect(fxGO, hangNode, position, onCompleted); }; } else { var fxGO = pool.GetOrCreate(); PlayEffect(fxGO, hangNode, position, onCompleted); } }
private void Init() { GameObjectPoolManager.GetInstance().Init(); MyParticleManager.GetInstance().Init(); particleInstanceList = new List <MyParticleInstance>(); //Assets.LoadAssetAsync("shaders", typeof(UnityEngine.Object)).completed += delegate (AssetRequest request) //{ // if (!string.IsNullOrEmpty(request.error)) // { // Debug.LogError(request.error); // return; // } // request.Retain(); //}; //var assetPath = "Assets/Arts/ui/panel/StartPanel.prefab"; //Assets.LoadAssetAsync(assetPath, typeof(UnityEngine.Object)).completed += delegate (AssetRequest request) //{ // if (!string.IsNullOrEmpty(request.error)) // { // Debug.LogError(request.error); // return; // } // GameObject go = (GameObject)Instantiate(request.asset); // go.name = request.asset.name; // go.transform.parent = root; // go.transform.localPosition = Vector3.zero; // go.transform.localScale = Vector3.one; // /// 设置关注对象,当关注对象销毁时,回收资源 // request.Require(go); // //Destroy(go, 3); // /// 设置关注对象后,只需要释放一次 // /// 这里如果之前没有调用 Require,下一帧这个资源就会被回收 // request.Release(); //}; }
public void AddParticleToCache(MyParticleInstance particleInstance) { GameObjectPoolManager.GetInstance().RecycleGameObject(particleInstance.gameObject); particleInstance.Clear(); }