示例#1
0
        /// <summary>
        /// 销毁
        /// </summary>
        public void Destroy()
        {
            foreach (KeyValuePair <string, JWArrayList <BaseAsset> > ast in _assets)
            {
                for (int i = 0; i < ast.Value.Count; i++)
                {
                    BaseAsset ba = ast.Value[i];

                    UIFormAsset oa = ba as UIFormAsset;
                    if (oa != null)
                    {
                        oa.OnFormAssetDestroy();
                    }

                    if (ba.RootGo != null)
                    {
                        ba.RootGo.ExtDestroy();
                    }

                    if (ba.Resource != null)
                    {
                        ResService.UnloadResource(ba.Resource);
                    }
                }
            }

            _assets = null;
            _parentTf.gameObject.ExtDestroy();
            _parentTf = null;
        }
        /// <summary>
        /// 处理销毁
        /// </summary>
        /// <param name="ba"></param>
        /// <returns></returns>
        public static bool ProcessDestroy(BaseAsset ba)
        {
            if (ba == null)
            {
                JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : invalid parameter");
                return(false);
            }

            switch (ba.BaseData.Type)
            {
            case AssetType.UIForm:
            {
                UIFormAsset ast = ba as UIFormAsset;
                if (ast == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : type is not object - {0}", ba.BaseData.Name);
                    return(false);
                }

                ast.OnFormAssetDestroy();
                DestroyAsset(ast);
            }
            break;

            case AssetType.Model:
            {
                ModelAsset ast = ba as ModelAsset;
                if (ast == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : type is not model - {0}", ba.BaseData.Name);
                    return(false);
                }

                ast.AnimationCpt = null;
                ast.AnimatorCtrl = null;
                DestroyAsset(ast);
            }
            break;

            case AssetType.UI:
            {
                UIAsset ast = ba as UIAsset;
                if (ast == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : type is not ui - {0}", ba.BaseData.Name);
                    return(false);
                }

                ast.FormCom  = null;
                ast.PLinkCom = null;
                DestroyAsset(ast);
            }
            break;

            case AssetType.Instantiate:
            {
                DestroyAsset(ba);
            }
            break;

            case AssetType.Audio:
            {
                AudioAsset ast = ba as AudioAsset;
                if (ast == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : type is not audio - {0}", ba.BaseData.Name);
                    return(false);
                }
                ast.Clip = null;
            }

            break;

            case AssetType.Sprite:
            {
                SpriteAsset ast = ba as SpriteAsset;
                if (ast == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessDestroy : type is not SpriteAsset - {0}", ba.BaseData.Name);
                    return(false);
                }
                ast.SpriteObj = null;
            }
            break;
            }
            return(true);
        }