Пример #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;
        }
Пример #2
0
        /// <summary>
        /// 资产创建预处理
        /// </summary>
        /// <param name="ba"></param>
        /// <returns></returns>
        public static bool ProcessCreate(BaseAsset ba)
        {
            if (ba == null || ba.Resource == null || ba.Resource.Content == null)
            {
                JW.Common.Log.LogE("AssetProcessor.ProcessCreate : invalid parameter");
                return(false);
            }

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

                if (!InstantiateAsset(ast))
                {
                    return(false);
                }
                //逻辑处理
                ast.OnFormAssetCreate();
            }
            break;

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

                if (!InstantiateAsset(ast))
                {
                    return(false);
                }

                ast.Render       = ast.RootGo.ExtGetComponentsInChildren <Renderer>(true);
                ast.AnimationCpt = ast.RootGo.ExtGetComponentInChildren <Animation>();
                ast.AnimatorCtrl = ast.RootGo.ExtGetComponentInChildren <Animator>();
            }
            break;

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

                if (!InstantiateAsset(ba))
                {
                    return(false);
                }
                ast.FormCom  = ast.RootGo.ExtGetComponent <UIForm>();
                ast.PLinkCom = ast.RootGo.ExtGetComponent <PrefabLink>();
            }
            break;

            //基础实例
            case AssetType.Instantiate:
            {
                if (!InstantiateAsset(ba))
                {
                    return(false);
                }
            }
            break;

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

                ast.Clip = ba.Resource.Content as AudioClip;
                if (ast.Clip == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessCreate : resource is not audioclip - {0}", ba.BaseData.Name);
                    return(false);
                }
            }
            break;

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

#if UNITY_EDITOR || !USE_PACK_RES
                Texture2D tt = ba.Resource.Content as Texture2D;
                ast.SpriteObj = Sprite.Create(tt, new Rect(0, 0, tt.width, tt.height), new Vector2(0.5f, 0.5f));
#else
                Sprite ss = ba.Resource.Content as Sprite;
                if (ss == null)
                {
                    JW.Common.Log.LogD("SpriteAsset Load From AB Is Texture2D Type");
                    Texture2D tt1 = ba.Resource.Content as Texture2D;
                    ast.SpriteObj = Sprite.Create(tt1, new Rect(0, 0, tt1.width, tt1.height), new Vector2(0.5f, 0.5f));
                }
                else
                {
                    ast.SpriteObj = ss;
                }
#endif
                if (ast.SpriteObj == null)
                {
                    JW.Common.Log.LogE("AssetProcessor.ProcessCreate : resource is not Sprite - {0}", ba.BaseData.Name);
                    return(false);
                }
            }
            break;
            }

            return(true);
        }
Пример #3
0
        /// <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);
        }