Ejemplo n.º 1
0
        /// <summary>
        /// 获取所有正在请求加载资产关联的 的UI状态名
        /// </summary>
        /// <param name="uiStateName">返回UI状态名</param>
        public void GetUIState(ref JWArrayList <string> uiStateName)
        {
            for (int i = 0; i < _resourceRequesting.Count; i++)
            {
                LoadData loadData = _resourceRequesting[i];
                if (loadData.Data.Life == LifeType.UIState && !string.IsNullOrEmpty(loadData.Data.StateName) &&
                    uiStateName.IndexOf(loadData.Data.StateName, StringComparer.OrdinalIgnoreCase) == -1)
                {
                    uiStateName.Add(loadData.Data.StateName);
                }
            }

            for (int i = 0; i < _data.Count; i++)
            {
                AssetData data = _data[i];
                if (data.Priority == LoadPriority.Wait)
                {
                    continue;
                }

                if (data.Life == LifeType.UIState && !string.IsNullOrEmpty(data.StateName) &&
                    uiStateName.IndexOf(data.StateName, StringComparer.OrdinalIgnoreCase) == -1)
                {
                    uiStateName.Add(data.StateName);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 反初始化
        /// </summary>
        public override void Uninitialize()
        {
            if (_updateCheckers != null)
            {
                for(int i = 0; i < _updateCheckers.Count; i++)
                {
                    IFSUpdateChecker.Destory(_updateCheckers[i]);
                }
                _updateCheckers.Clear();
                _updateCheckers = null;
            }

            if (_sessionProcessors != null)
            {
                for (int i = 0; i < _sessionProcessors.Count; i++)
                {
                    IFSSessionProcessor.Destory(_sessionProcessors[i]);
                }
                _sessionProcessors.Clear();
                _sessionProcessors = null;
            }

            if (_localCheckers != null)
            {
                for (int i = 0; i < _localCheckers.Count; i++)
                {
                    IFSLocalChecker.Destory(_localCheckers[i]);
                }
                _localCheckers.Clear();
                _localCheckers = null;
            }
        }
Ejemplo n.º 3
0
 public override bool Initialize()
 {
     StateService.GetInstance().AddCallback(this);
     this.AddTimer(10000, true);
     _modules = new JWArrayList <ModuleBase>();
     return(true);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据UI状态判断资产是否失效
        /// </summary>
        /// <param name="data">资产记录数据</param>
        /// <param name="uiState">UI状态</param>
        /// <returns></returns>
        public static bool IsAssetDead(ref AssetData data, JWArrayList <string> uiState)
        {
            if (uiState == null)
            {
                JW.Common.Log.LogE("AssetHelper.IsAssetDead : invalid parameter");
                return(false);
            }

            if (data.Life == LifeType.Resident)
            {
                return(false);
            }

            if (data.Life == LifeType.Manual)
            {
                return(false);
            }

            if (data.Life == LifeType.UIState &&
                !string.IsNullOrEmpty(data.StateName) &&
                uiState.IndexOf(data.StateName, StringComparer.OrdinalIgnoreCase) != -1)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加资产
        /// </summary>
        /// <param name="ba">资产</param>
        public void AddAsset(BaseAsset ba)
        {
            if (ba == null || string.IsNullOrEmpty(ba.BaseData.Name))
            {
                JW.Common.Log.LogE("AssetCache.AddAsset : invalid parameter");
                return;
            }

            JWArrayList <BaseAsset> ast;

            if (!_assets.TryGetValue(ba.BaseData.Name, out ast))
            {
                ast = new JWArrayList <BaseAsset>();
                _assets.Add(ba.BaseData.Name, ast);
            }

            AssetProcessor.ProcessRestore(ba);

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

            if (ba.RootTf != null)
            {
                ba.RootTf.SetParent(_parentTf, false);
            }

            ast.Add(ba);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="rootTf">根节点</param>
        public void Create(Transform rootTf)
        {
            _cache = new AssetCache();
            _cache.Create(rootTf);

            _usingAsset = new JWArrayList <BaseAsset>();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取所有的UI状态名
        /// </summary>
        /// <param name="uiStateName">返回UI状态名</param>
        public void GetUIState(ref JWArrayList <string> uiStateName)
        {
            Dictionary <string, JWArrayList <BaseAsset> > .Enumerator enumerator = _assets.GetEnumerator();
            while (enumerator.MoveNext())
            {
                JWArrayList <BaseAsset> val = enumerator.Current.Value;
                if (val == null)
                {
                    continue;
                }

                for (int i = 0; i < val.Count; i++)
                {
                    BaseAsset ba = val[i];
                    if (ba == null || ba.BaseData.Life != LifeType.UIState || string.IsNullOrEmpty(ba.BaseData.StateName))
                    {
                        continue;
                    }

                    if (uiStateName.IndexOf(ba.BaseData.StateName, StringComparer.OrdinalIgnoreCase) == -1)
                    {
                        uiStateName.Add(ba.BaseData.StateName);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="assetManager">资产管理器</param>
 public void Initialize(AssetManager assetManager)
 {
     _assetManager       = assetManager;
     _data               = new JWArrayList <AssetData>();
     _resourceRequesting = new JWArrayList <LoadData>();
     //异步一直在运行
     StartCoroutine(AsynchronousLoad());
 }
    void OnGUI()
    {
        if (!AssetService.IsValidate())
        {
            return;
        }

        JW.Framework.Asset.AssetManager am        = AssetService.GetInstance().GetAssetManager();
        JWArrayList <BaseAsset>         usingList = am.GetUsingAssetList();

        GUILayout.Space(3f);
        GUILayout.BeginVertical();


        // list title
        GUILayout.BeginHorizontal("Table Title", GUILayout.MinHeight(20f));
        GUILayout.Label("Index", _labelStyle, GUILayout.Width(60f));
        GUILayout.Label("RefCnt", _labelStyle, GUILayout.Width(60f));
        GUILayout.Label("OriPath", _labelStyle, GUILayout.Width(120f));
        GUILayout.Label("Name", _labelStyle, GUILayout.Width(60f));
        GUILayout.EndHorizontal();

        // list
        mScroll = GUILayout.BeginScrollView(mScroll);

        int index = 0;

        for (int i = 0; i < usingList.Count; i++)
        {
            BaseAsset ba = usingList[i];
            if (ba == null)
            {
                continue;
            }

            index++;

            GUILayout.BeginHorizontal("Table Row", GUILayout.MinHeight(20f));

            // index
            GUILayout.Label(index.ToString(), _labelStyle, GUILayout.Width(60f));

            // ref count
            GUILayout.Label(ba.Resource.RefCnt.ToString(), _labelStyle, GUILayout.Width(60f));

            // tag
            GUILayout.Label(ba.Resource.OriginPath, _labelStyle, GUILayout.Width(120f));

            // path
            GUILayout.Label(ba.Resource.Name, _labelStyle);

            GUILayout.EndHorizontal();
        }

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
        GUILayout.Space(3f);
    }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns>初始化成功/失败</returns>
        public override bool Initialize()
        {
            _mediator = new JWArrayList <MediatorData>();

            _stateHistory       = new JWArrayList <string>();
            _state              = new JWArrayList <StateData>();
            _switchMediatorData = new JWArrayList <KeyValuePair <UIMediator, int> >();
            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 创建,外部不要调用
        /// </summary>
        public void Create(ModuleBase module)
        {
            Module = module;

            _forms   = new JWArrayList <UIFormClass>(1);
            _inState = false;
            //注入到UI状态服务
            UIStateService.GetInstance().AddMediator(this, GetBelongsUIStateName());

            OnInitialize();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 反初始化
        /// </summary>
        public void Uninitialize()
        {
            StopAllCoroutines();

            _assetManager = null;
            _data.Clear();
            _data = null;

            _resourceRequesting     = null;
            _resourceDiscardRequest = null;

            _synLoading = false;
        }
Ejemplo n.º 13
0
        private void Remove(JWArrayList <Data> datas, IScheduleHandler handler)
        {
            for (int i = 0; i < datas.Count; i++)
            {
                if (datas[i].Handler != handler)
                {
                    continue;
                }

                Data data = datas[i];
                data.Handler = null;
                datas[i]     = data;
            }
        }
Ejemplo n.º 14
0
        public override void Uninitialize()
        {
            for (int i = _modules.Count - 1; i >= 0; --i)
            {
                _modules[i].Destroy();
            }

            _modules.Clear();
            _modules.Release();
            _modules = null;

            StateService.GetInstance().RemoveCallback(this);
            this.RemoveTimer();
        }
Ejemplo n.º 15
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);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 清除UIState 相关的任务
        /// </summary>
        /// <param name="uiState">保留的UI状态</param>
        public void ClearTask(JWArrayList <string> uiState)
        {
            if (uiState == null)
            {
                JW.Common.Log.LogE("Loader.ClearTask : invalid parameter");
                return;
            }

            if (_synLoading)
            {
                JW.Common.Log.LogE("Loader.ClearTask : load is running");
                return;
            }

            for (int i = _resourceRequesting.Count - 1; i >= 0; --i)
            {
                LoadData loadData = _resourceRequesting[i];
                if (!AssetAssistor.IsAssetDead(ref loadData.Data, uiState))
                {
                    continue;
                }

                if (loadData.Request != null)
                {
                    if (_resourceDiscardRequest != null)
                    {
                        JW.Common.Log.LogE("Loader.ClearTask : _resourceDiscardRequest != null");
                    }

                    _resourceDiscardRequest = loadData.Request;
                }

                _resourceRequesting.RemoveAt(i);
            }

            for (int i = _data.Count - 1; i >= 0; --i)
            {
                AssetData data = _data[i];
                if (data.Priority == LoadPriority.Wait)
                {
                    continue;
                }

                if (AssetAssistor.IsAssetDead(ref data, uiState))
                {
                    _data.RemoveAt(i);
                }
            }
        }
        public override void Uninitialize()
        {
            Destroy();

            _assetManager.Destroy();
            _assetManager = null;

            _root.gameObject.ExtDestroy();
            _root = null;

            _tempList  = null;
            _tempList2 = null;

            LuaGCHook = null;
        }
Ejemplo n.º 18
0
        private void Remove(JWArrayList <Data> datas, uint id)
        {
            for (int i = 0; i < datas.Count; i++)
            {
                if (datas[i].ID != id)
                {
                    continue;
                }

                Data data = datas[i];
                data.Handler = null;
                datas[i]     = data;

                return;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 销毁
        /// </summary>
        public void Destroy()
        {
            _cache.Destroy();
            _cache = null;

            if (_usingAsset.Count > 0)
            {
                JW.Common.Log.LogE("AssetManager.Destroy : using asset is not empty");
                for (int i = 0; i < _usingAsset.Count; i++)
                {
                    JW.Common.Log.LogE(_usingAsset[i].BaseData.Name);
                }
                JW.Common.Log.LogE("---End---");
            }

            _usingAsset = null;
        }
        /// <summary>
        /// 清理缓存的资源
        /// </summary>
        /// <param name="uiStateHistory">UI状态历史列表(=null标识没有UI状态)</param>
        public void ClearUIStateCache(JWArrayList <string> uiStateHistory)
        {
            if (_loader == null)
            {
                return;
            }

            _tempList.Clear();
            _tempList2.Clear();
            if (uiStateHistory != null)
            {
                _assetManager.GetCacheUIState(ref _tempList);
                _loader.GetUIState(ref _tempList);

                for (int i = uiStateHistory.Count - 1; i >= 0; i--)
                {
                    string stateName = uiStateHistory[i];
                    if (string.IsNullOrEmpty(stateName) || _tempList.IndexOf(stateName, StringComparer.OrdinalIgnoreCase) == -1)
                    {
                        continue;
                    }

                    _tempList2.Add(stateName);
                    if (_tempList2.Count == CacheUIStateCount)
                    {
                        break;
                    }
                }
            }

            _assetManager.ClearCache(_tempList2);
            _loader.ClearTask(_tempList2);

            if (AlwaysGc)
            {
                if (LuaGCHook != null)
                {
                    LuaGCHook(true);
                }
                ResService.GetInstance().UnloadUnusedAssets();
                return;
            }
        }
Ejemplo n.º 21
0
        /// 游戏更新检查后后启动
        public void StartAfterUpdate(Action <bool> allCompletedCallback)
        {
            _allCompletedCallback = allCompletedCallback;
#if USE_PACK_RES
            if (ResService.GetInstance().PackConfig == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : resource initialize failed");
                return;
            }
            //
            _bundleFiles   = BundleMediator.GetInstance().GetPreloadBundles();
            _bundleLoading = false;

            string filename = "main_shaders.ab";
            _shaderBundle = BundleService.GetInstance().GetBundle(filename);
            if (_shaderBundle == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : failed to get shader bundle");
            }

            ResPackInfo pi = ResService.GetInstance().PackConfig.GetPackInfo(filename);
            if (pi == null)
            {
                _shaderFilename = new JWArrayList <string>(0);
            }
            else
            {
                _shaderFilename = new JWArrayList <string>(pi.Resources.Count);
                for (int i = 0; i < pi.Resources.Count; i++)
                {
                    _shaderFilename.Add(pi.Resources[i].Path);
                }
            }
#else
            _bundleFiles    = new JWObjList <string>(0);
            _shaderBundle   = null;
            _shaderFilename = new JWArrayList <string>(0);
#endif

            //真正的开始预加载协成
            StartCoroutine(PreloadCoroutine());
        }
        public override bool Initialize()
        {
            _root = new GameObject("AssetService").transform;
            _root.gameObject.ExtDontDestroyOnLoad();

            _assetManager = new AssetManager();
            _assetManager.Create(_root);

            //必须先构建
            _bundleMediator = _root.gameObject.AddComponent <BundleMediator>();
            _bundleMediator.Initialize();
            //
            _loader = _root.gameObject.AddComponent <AssetLoader>();
            _loader.Initialize(_assetManager);
            //
            _preloader = _root.gameObject.AddComponent <AssetPreloader>();
            _preloader.Initialize(_loader);

            _tempList  = new JWArrayList <string>();
            _tempList2 = new JWArrayList <string>();

            return(true);
        }
        /// <summary>
        /// 反初始化
        /// </summary>
        public override void Uninitialize()
        {
            _stateHistory = null;

            _state.Release();
            _state = null;

            _switchMediatorData.Release();
            _switchMediatorData = null;

            for (int i = 0; i < _mediator.Count; i++)
            {
                MediatorData data = _mediator[i];
                if (data.Mediator == null)
                {
                    continue;
                }

                JW.Common.Log.LogE("UIStateService.Uninitialize error - mediator not destroy {0}", data.Mediator.GetType().FullName);
            }

            _mediator.Release();
            _mediator = null;
        }
Ejemplo n.º 24
0
        public override bool Initialize()
        {
            _eventHandler = new JWArrayList <EventHandler>(200, 8);

            return(true);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// 获取缓存中关联的UI状态
 /// </summary>
 /// <param name="uiStateName">返回UI状态名</param>
 public void GetCacheUIState(ref JWArrayList <string> uiStateName)
 {
     _cache.GetUIState(ref uiStateName);
 }
Ejemplo n.º 26
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);
                    }
                }
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 清理UI 状态关联的
 /// </summary>
 /// <param name="uiState">保留的UI状态名</param>
 public void ClearCache(JWArrayList <string> uiState)
 {
     _cache.Clear(uiState);
 }
Ejemplo n.º 28
0
        private IEnumerator AsynchronousLoad_LoadAssetBundle(JWObjList <string> stringList, JWArrayList <AssetData> assetDataList)
        {
            while (true)
            {
                stringList.Clear();
                assetDataList.Clear();
                for (int i = 0; i < _data.Count;)
                {
                    AssetData data = _data[i];
                    if (data.Priority != _loadAssetBundlePriority)
                    {
                        ++i;
                        continue;
                    }

                    _data.RemoveAt(i);

                    if (_assetManager.GetCacheCount(data.Name) >= data.Count)
                    {
                        if (data.Callback != null)
                        {
                            assetDataList.Add(data);
                        }
                        continue;
                    }

                    LoadData loadData;
                    loadData.Data            = data;
                    loadData.LoadBundleState = LoadStateLoading;
                    loadData.Request         = null;

                    bool insert = false;
                    for (int j = _resourceRequesting.Count - 1; j >= 0; --j)
                    {
                        if (_resourceRequesting[j].Data.Priority <= data.Priority)
                        {
                            _resourceRequesting.Insert(j + 1, loadData);
                            insert = true;
                            break;
                        }
                    }

                    if (!insert)
                    {
                        _resourceRequesting.Insert(0, loadData);
                    }

                    stringList.Add(data.Filename);

                    if (_loadAssetBundlePriority >= LoadPriority.Preprocess)
                    {
                        break;
                    }
                }

                yield return(null);

                if (stringList.Count > 0)
                {
#if USE_PACK_RES
                    BundleMediator.GetInstance().LoadBundle(stringList, OnBundleLoadCompleted);
#else
                    OnBundleLoadCompleted(stringList, true);
#endif
                }

                yield return(null);

                for (int i = 0; i < assetDataList.Count; i++)
                {
                    AssetData data = assetDataList[i];
                    if (data.Callback != null)
                    {
                        data.Callback.OnLoadAssetCompleted(data.Name, AssetLoadResult.Success, null);
                        yield return(null);
                    }
                }

                yield return(InstructionEnd);
            }
        }
Ejemplo n.º 29
0
 public override bool Initialize()
 {
     _connectors = new JWArrayList <NetConnector>(1);
     return(true);
 }