Exemplo n.º 1
0
        private BaseAsset CreateAsset(AssetData data, ResObj resource)
        {
            if (resource == null || resource.Content == null)
            {
                JW.Common.Log.LogE("AssetManager.CreateAsset : invalid parameter - {0}", data.Name);
                return(null);
            }

            data.Callback = null;

            BaseAsset ba = data.Factory.CreateObject();

            if (ba == null)
            {
                JW.Common.Log.LogE("AssetManager.CreateAsset : failed to create asset - {0}", data.Name);
                return(null);
            }

            ba.BaseData = data;
            ba.Resource = resource;

            if (!AssetProcessor.ProcessCreate(ba))
            {
                JW.Common.Log.LogE("AssetManager.CreateAsset : failed to process create - {0}", data.Name);

                ba.BaseData.Callback = null;
                ba.BaseData.Factory  = null;
                ba.Resource          = null;
                data.Factory.DestroyObject(ba);
                return(null);
            }

            //AssetProcessor.ProcessAssociateResource(ba);

            return(ba);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 装载
        /// </summary>
        /// <param name="data">资产数据</param>
        /// <param name="clone">是否Clone一个副本</param>
        /// <returns>资产</returns>
        public BaseAsset Load(ref AssetData data, bool clone)
        {
            if (string.IsNullOrEmpty(data.Filename))
            {
                JW.Common.Log.LogE("AssetManager.Load : invalid parameter");
                return(null);
            }

            //缓存找
            BaseAsset ba = _cache.GetAsset(data.Name);

            if (ba != null)
            {
                //缓存复制
                if (clone)
                {
                    BaseAsset cloneBa = AssetProcessor.ProcessClone(ba);
                    _cache.AddAsset(ba);
                    ba = cloneBa;
                }

                if (ba != null)
                {
                    if (!AssetProcessor.ProcessCreate(ba))
                    {
                        JW.Common.Log.LogE("AssetManager.CreateAsset : failed to process create - {0}", data.Name);
                        ba.BaseData.Callback = null;
                        ba.BaseData.Factory  = null;
                        ba.Resource          = null;
                        data.Factory.DestroyObject(ba);
                        return(null);
                    }
                    _usingAsset.Add(ba);
                }
                return(ba);
            }

            //没在缓存 同步创建
            ResObj resource = ResService.GetResource(data.Filename);

            if (resource == null)
            {
                JW.Common.Log.LogE("AssetManager.Load : failed to load resource - {0}", data.Filename);
                return(null);
            }

            if (resource.Content == null)
            {
                JW.Common.Log.LogE("AssetManager.Load : failed to load resource - {0}", data.Filename);

                ResService.UnloadResource(resource);
                return(null);
            }

            ba = CreateAsset(data, resource);
            if (ba == null)
            {
                ResService.UnloadResource(resource);
                return(null);
            }

            if (clone)
            {
                BaseAsset cloneBa = AssetProcessor.ProcessClone(ba);
                _cache.AddAsset(ba);
                ba = cloneBa;
            }

            if (ba != null)
            {
                _usingAsset.Add(ba);
            }

            return(ba);
        }