/// <summary>
        /// 卸载
        /// </summary>
        /// <param name="ba">资源</param>
        public void Unload(BaseAsset ba)
        {
            if (ba == null)
            {
                return;
            }

            if (_assetManager != null)
            {
                _assetManager.Unload(ba, SingletonState == SingletonStateEnum.Destroying);
            }
            else
            {
                if (!AssetProcessor.ProcessDestroy(ba))
                {
                    return;
                }

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

                ba.BaseData.Factory.DestroyObject(ba);
            }
        }
Esempio n. 2
0
        public void CleanAllUsing()
        {
            if (_usingAsset == null)
            {
                return;
            }
            for (int i = _usingAsset.Count - 1; i >= 0; i--)
            {
                BaseAsset ba = _usingAsset[i];
                if (!AssetProcessor.ProcessDestroy(ba))
                {
                    continue;
                }

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

                ba.BaseData.Factory.DestroyObject(ba);
                //
                _usingAsset.RemoveAt(i);
            }
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
        private void Awake()
        {
            if (_cmCurve == null)
            {
                GameObject go = GameObject.Find(ConfigFilename);
                if (go == null)
                {
#if UNITY_EDITOR
                    go = (GameObject)Resources.Load(ConfigFilename).ExtInstantiate();
#else
                    ResObj resource = ResService.GetResource(ConfigFilename);
                    if (resource != null)
                    {
                        go = (GameObject)resource.Content.ExtInstantiate();
                        ResService.UnloadResource(resource);
                    }
#endif
                    if (null != go)
                    {
                        ExtObject.ExtDontDestroyOnLoad(go);
                    }
                }

                if (go != null)
                {
                    go.name  = ConfigFilename;
                    _cmCurve = go.ExtGetComponent <UICurveCfg>();
                    _cmAudio = go.ExtGetComponent <UIAudioCfg>();
                }
            }

            _cacheTf       = transform;
            _originalScale = _cacheTf.localScale;
        }
        public byte[] CustomLuaLoader(ref string filepath)
        {
            filepath = filepath.Replace('.', '/');
            filepath = "LuaScripts/" + filepath + ".lua";
            //编辑器 强制走
#if UNITY_EDITOR && !USE_PACK_RES
            string fullPath = JW.Res.FileUtil.CombinePath(Application.dataPath, "Resources/" + filepath);
            return(JW.Res.FileUtil.ReadFile(fullPath));
#else
            ResObj res = ResService.GetResource(filepath);
            if (res != null && res.Content != null)
            {
                BinaryObject binaryObject = res.Content as BinaryObject;
                byte[]       bb           = binaryObject.m_data;
                ResService.UnloadResource(res, false);
                return(bb);
            }
            else
            {
                // 有脚本加载失
                JW.Common.Log.LogE("Load lua script failed, path:{0}.", filepath);
                return(null);
            }
#endif
        }
Esempio n. 6
0
        /// <summary>
        /// 清理
        /// </summary>
        /// <param name="uiState">保留的UI状态名</param>
        public void Clear(JWArrayList <string> uiState)
        {
            if (uiState == null)
            {
                JW.Common.Log.LogE("AssetCache.ClearCache : invalid parameter");
                return;
            }

            Dictionary <string, JWArrayList <BaseAsset> > .Enumerator enumerator = _assets.GetEnumerator();
            while (enumerator.MoveNext())
            {
                JWArrayList <BaseAsset> val = enumerator.Current.Value;
                if (val == null)
                {
                    continue;
                }

                for (int i = val.Count - 1; i >= 0; i--)
                {
                    BaseAsset ba = val[i];
                    if (ba == null)
                    {
                        val.RemoveAt(i);
                        continue;
                    }

                    if (!AssetAssistor.IsAssetDead(ref ba.BaseData, uiState))
                    {
                        continue;
                    }

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

                        ba.BaseData.Factory.DestroyObject(ba);
                    }
                    else
                    {
                        JW.Common.Log.LogE("AssetCache.ClearCache : failed to process Destroy - {0}", ba.BaseData.Name);
                    }

                    val.RemoveAt(i);
                }
            }
        }
        /// 获取文件内容
        public static string GetTextFromFile(string filename)
        {
            string text = string.Empty;
            ResObj res  = ResService.GetResource(filename);

            if (res != null)
            {
                BinaryObject binaryObject = res.Content as BinaryObject;
                byte[]       rawBytes     = binaryObject.m_data;
                if (rawBytes != null && rawBytes.Length > 0)
                {
                    ResService.UnloadResource(res);
                    text = Encoding.UTF8.GetString(rawBytes);
                }
            }
            return(text);
        }
Esempio n. 8
0
        /// <summary>
        /// 卸载
        /// </summary>
        /// <param name="ba">待卸载的资产</param>
        /// <param name="forceDestroy">是否强制销毁</param>
        public void Unload(BaseAsset ba, bool forceDestroy = false)
        {
            if (ba == null)
            {
                JW.Common.Log.LogE("AssetManager.Unload : invalid parameter");
                return;
            }

            int found = _usingAsset.IndexOf(ba);

            if (found == -1)
            {
                JW.Common.Log.LogE("AssetManager.Unload : can't find asset - {0}", ba.BaseData.Name);
                return;
            }

            _usingAsset.RemoveAt(found);

            //销毁手动和Imediate
            if (forceDestroy || ba.BaseData.Life == LifeType.Immediate || ba.BaseData.Life == LifeType.Manual)
            {
                if (!AssetProcessor.ProcessDestroy(ba))
                {
                    return;
                }

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

                ba.BaseData.Factory.DestroyObject(ba);
            }
            else
            {
                _cache.AddAsset(ba);
            }
        }
        //------------------------------------------

        /// <summary>
        /// 取资源二进制数据
        /// </summary>
        /// <param name="resPath">资源路径</param>
        /// <returns>二进制数据</returns>
        public static byte[] GetResourceBytes(string resPath)
        {
            ResObj res = ResService.GetResource(resPath);

            if (res == null)
            {
                return(null);
            }

            BinaryObject binaryObject = res.Content as BinaryObject;

            if (binaryObject == null)
            {
                return(null);
            }

            byte[] rawBytes = binaryObject.m_data;

            ResService.UnloadResource(res);

            return(rawBytes);
        }
        private void Awake()
        {
            if (ApplyButtonClickCurve)
            {
                GameObject go = GameObject.Find(ConfigFilename);
                if (go == null)
                {
#if UNITY_EDITOR
                    go = (GameObject)Resources.Load(ConfigFilename).ExtInstantiate();
#else
                    ResObj resource = ResService.GetResource(ConfigFilename);
                    if (resource != null)
                    {
                        go = (GameObject)resource.Content.ExtInstantiate();
                        ResService.UnloadResource(resource);
                    }
#endif
                    if (null != go)
                    {
                        ExtObject.ExtDontDestroyOnLoad(go);
                    }
                }

                if (go != null)
                {
                    go.name = ConfigFilename;
                    UICurveCfg cfg = go.ExtGetComponent <UICurveCfg>();
                    _curve = cfg.GetCurve("Normal");
                }
            }
            //
            if (_curve != null)
            {
                Keyframe lastKf = _curve[_curve.length - 1];
                _lastKeyTime = lastKf.time;
            }
            _cacheTf       = transform;
            _originalScale = _cacheTf.localScale;
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        private IEnumerator AsynchronousLoad_InstantiateResource()
        {
            while (true)
            {
                int find = 0;
                for (; find < _resourceRequesting.Count; find++)
                {
                    if (_resourceRequesting[find].Request != null)
                    {
                        break;
                    }
                }

                if (find >= _resourceRequesting.Count)
                {
                    yield return(InstructionEnd);

                    continue;
                }

                LoadData loadData = _resourceRequesting[find];
                if (!loadData.Request.isDone)
                {
                    yield return(null);

                    continue;
                }

                _resourceRequesting.RemoveAt(find);

                if (loadData.Request.resource == null)
                {
                    JW.Common.Log.LogE("Loader.AsynchronousLoad_InstantiateResource : load failed - {0}", loadData.Data.Name);
                    if (loadData.Data.Callback != null)
                    {
                        loadData.Data.Callback.OnLoadAssetCompleted(loadData.Data.Name, AssetLoadResult.ResourceFail, null);
                        yield return(null);
                    }

                    yield return(InstructionEnd);

                    continue;
                }

                if (loadData.Request.resource.Content == null)
                {
                    JW.Common.Log.LogE("Loader.AsynchronousLoad_InstantiateResource : load failed - {0}", loadData.Data.Name);
                    ResService.UnloadResource(loadData.Request.resource);

                    if (loadData.Data.Callback != null)
                    {
                        loadData.Data.Callback.OnLoadAssetCompleted(loadData.Data.Name, AssetLoadResult.ResourceFail, null);
                        yield return(null);
                    }

                    yield return(InstructionEnd);

                    continue;
                }

                if (_assetManager.AddCache(loadData.Data, loadData.Request.resource) == null)
                {
                    JW.Common.Log.LogE("Loader.AsynchronousLoad_Resource : add cache failed - {0}", loadData.Data.Name);
                    ResService.UnloadResource(loadData.Request.resource);

                    if (loadData.Data.Callback != null)
                    {
                        loadData.Data.Callback.OnLoadAssetCompleted(loadData.Data.Name, AssetLoadResult.ResourceFail, null);
                        yield return(null);
                    }

                    yield return(InstructionEnd);

                    continue;
                }

                yield return(null);

                //个数
                if (_assetManager.GetCacheCount(loadData.Data.Name) < loadData.Data.Count)
                {
                    loadData.Request.resource = ResService.GetResource(loadData.Data.Filename);
                    _resourceRequesting.Insert(find, loadData);

                    yield return(InstructionEnd);

                    continue;
                }

                if (loadData.Data.Callback != null)
                {
                    loadData.Data.Callback.OnLoadAssetCompleted(loadData.Data.Name, AssetLoadResult.Success, null);
                    yield return(null);
                }

                yield return(InstructionEnd);
            }
        }
Esempio n. 13
0
        private IEnumerator AsynchronousLoad()
        {
            JWObjList <string>      stringList    = new JWObjList <string>();
            JWArrayList <AssetData> assetDataList = new JWArrayList <AssetData>();

            IEnumerator loadBundleEnumerator   = AsynchronousLoad_LoadAssetBundle(stringList, assetDataList);
            IEnumerator loadResourceEnumerator = AsynchronousLoad_LoadResource();
            IEnumerator instantiateEnumerator  = AsynchronousLoad_InstantiateResource();

            if (loadBundleEnumerator == null || loadResourceEnumerator == null || instantiateEnumerator == null)
            {
                yield break;
            }

            while (true)
            {
                yield return(null);

                if (_synLoading)
                {
                    continue;
                }

                while (_resourceDiscardRequest != null)
                {
                    if (!_resourceDiscardRequest.isDone)
                    {
                        yield return(null);

                        continue;
                    }

                    if (_resourceDiscardRequest.resource != null)
                    {
                        ResService.UnloadResource(_resourceDiscardRequest.resource);
                    }

                    _resourceDiscardRequest = null;
                    yield return(null);
                }

                if (_resourceRequesting.Count > 0)
                {
                    while (instantiateEnumerator.MoveNext())
                    {
                        if (instantiateEnumerator.Current == InstructionEnd)
                        {
                            break;
                        }

                        yield return(null);
                    }
                }

                if (_resourceRequesting.Count > 0)
                {
                    while (loadResourceEnumerator.MoveNext())
                    {
                        if (loadResourceEnumerator.Current == InstructionEnd)
                        {
                            break;
                        }

                        yield return(null);
                    }
                }

                _loadAssetBundlePriority = AsynchronousLoad_CalculatePriority();
                if (_loadAssetBundlePriority != int.MaxValue &&
                    (_loadAssetBundlePriority < LoadPriority.Preprocess ||
                     (!BundleService.GetInstance().IsWorking() && _resourceDiscardRequest == null && _resourceRequesting.Count == 0)))
                {
                    while (loadBundleEnumerator.MoveNext())
                    {
                        if (loadBundleEnumerator.Current == InstructionEnd)
                        {
                            break;
                        }

                        yield return(null);
                    }
                }
            }
        }