Example #1
0
        /// <summary>
        /// Sepcs the proc4 assets.
        /// </summary>
        /// <param name="unit">Unit.</param>
        /// <param name="cb">Cb.</param>
        /// <param name="args">Arguments.</param>
        public virtual void sepcProc4Assets(T unit, object cb, object args, object progressCB)
        {
            GameObject go = null;

            if (typeof(T) == typeof(GameObject))
            {
                go = unit as GameObject;
            }
            else if (unit is MonoBehaviour)
            {
                go = (unit as MonoBehaviour).gameObject;
            }
            if (go != null)
            {
                CLSharedAssets sharedAsset = go.GetComponent <CLSharedAssets> ();
                if (sharedAsset != null)
                {
                    NewList param = ObjPool.listPool.borrowObject();
                    param.Add(cb);
                    param.Add(unit);
                    param.Add(args);
                    sharedAsset.init((Callback)onGetSharedAssets, param, progressCB);
                }
                else
                {
                    finishSetPrefab(unit);
                    Utl.doCallback(cb, unit, args);
                }
            }
            else
            {
                finishSetPrefab(unit);
                Utl.doCallback(cb, unit, args);
            }
        }
        public static void finishGetPanel(string pName, AssetBundle ab, object callback, object paras)
        {
            if (ab != null)
            {
                GameObject prefab = ab.mainAsset as GameObject;
                ab.Unload(false);
                ab = null;
                GameObject go = GameObject.Instantiate(prefab) as GameObject;
                go.name                    = pName;
                go.transform.parent        = self.transform;
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = Vector3.zero;

                CLPanelBase p = go.GetComponent <CLPanelBase>();
                if (p.isNeedResetAtlase)
                {
                    CLUIUtl.resetAtlasAndFont(p.transform, false);
                }
                panelBuff[pName]        = p;
                panelAssetBundle[pName] = p;

                CLSharedAssets sharedAsset = go.GetComponent <CLSharedAssets>();
                if (sharedAsset != null)
                {
                    NewList param = ObjPool.listPool.borrowObject();
                    param.Add(callback);
                    param.Add(p);
                    param.Add(paras);
                    sharedAsset.init((Callback)onGetSharedAssets, param, null);
                }
                else
                {
                    if (p != null)
                    {
                        Utl.doCallback(callback, p, paras);
                    }
                }
            }
            NGUITools.SetActive(self.mask, false);
            return;// null;
        }
Example #3
0
        //释放资源
        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);
            }
        }