/// <summary> /// Returns the object. 当参数unit是null时,说明是共享资源 /// </summary> /// <param name="name">Name.</param> /// <param name="unit">Unit.</param> public virtual void _returnObj(string name, T unit, bool inActive = true, bool setParent = true) { if (unit != null) { object obj = poolMap [name]; ObjsPubPool pool = getObjPool(name); pool.returnObject(unit); poolMap [name] = pool; if (unit is MonoBehaviour) { MonoBehaviour unitObj = unit as MonoBehaviour; if (inActive) { unitObj.gameObject.SetActive(false); } if (setParent) { unitObj.transform.parent = null; } } else if (unit is GameObject) { GameObject unitObj = unit as GameObject; if (inActive) { unitObj.SetActive(false); } if (setParent) { unitObj.transform.parent = null; } } } CLAssetsManager.self.unUseAsset(getAssetPath(name)); }
public ObjsPubPool getObjPool(string name) { object obj = poolMap [name]; ObjsPubPool pool = null; if (obj == null) { pool = new ObjsPubPool(prefabMap); poolMap [name] = pool; } else { pool = (ObjsPubPool)obj; } return(pool); }
public virtual T _borrowObj(string name, bool isSharedResource) { T r = null; if (isSharedResource) { r = (T)(prefabMap [name]); } else { object obj = poolMap [name]; ObjsPubPool pool = getObjPool(name); r = pool.borrowObject(name); poolMap [name] = pool; } if (_havePrefab(name)) { CLAssetsManager.self.useAsset(getAssetPath(name)); } return(r); }
//释放资源 public virtual void realseAsset(params object[] paras) { string name = ""; try { name = paras [0].ToString(); object obj = poolMap [name]; ObjsPubPool pool = null; T unit = null; MonoBehaviour unitObj = null; if (obj != null) { pool = obj as ObjsPubPool; } if (pool != null) { while (pool.queue.Count > 0) { unit = pool.queue.Dequeue(); if (unit != null) { if (unit is MonoBehaviour) { unitObj = unit as MonoBehaviour; GameObject.DestroyImmediate(unitObj.gameObject, true); } else if (unit is GameObject) { GameObject.DestroyImmediate((unit as GameObject), true); } } unit = null; } pool.queue.Clear(); } unit = (T)(prefabMap [name]); prefabMap.Remove(name); if (unit != null) { if (unit is AssetBundle) { //do nothing, CLAssetsManager will unload assetbundle } else { if (unit is MonoBehaviour) { unitObj = unit as MonoBehaviour; CLSharedAssets sharedAsset = unitObj.GetComponent <CLSharedAssets> (); if (sharedAsset != null) { sharedAsset.returnAssets(); } GameObject.DestroyImmediate(unitObj.gameObject, true); } else if (unit is GameObject) { CLSharedAssets sharedAsset = (unit as GameObject).GetComponent <CLSharedAssets> (); if (sharedAsset != null) { sharedAsset.returnAssets(); } GameObject.DestroyImmediate((unit as GameObject), true); } else { //UnityEngine.Resources.UnloadAsset ((Object)unit); GameObject.DestroyImmediate(unit, true); } } } unit = null; } catch (System.Exception e) { Debug.LogError("name==" + name + ":" + e); } }