예제 #1
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);
            }
        }
        /// <summary>
        /// 压入状态
        /// </summary>
        /// <param name="stateName">状态名</param>
        /// <param name="stateParam">状态参数</param>
        /// <param name="allowLoadAsset">不要使用</param>
        /// <param name="oldStateName">不要使用</param>
        public bool PushState(string stateName, object stateParam = null, bool allowLoadAsset = false, string oldStateName = null)
        {
            if (string.IsNullOrEmpty(stateName))
            {
                return(false);
            }

            if (_switchState)
            {
                JW.Common.Log.LogE("UIStateService.PushState : state is switching");
                return(false);
            }

            // 状态相同,无须跳转
            if (string.IsNullOrEmpty(oldStateName))
            {
                oldStateName = _state.Count > 0 ? _state[_state.Count - 1].StateName : string.Empty;
            }

            if (stateName.Equals(oldStateName, StringComparison.OrdinalIgnoreCase))
            {
                JW.Common.Log.LogE("UIStateService.PushState error - already in state {0}", stateName);
                return(false);
            }
            _switchState = true;

            JW.Common.Log.LogD("<color=yellow>UIStateService</color>--------PushState----->" + stateName);
            // 跳转
            for (int i = 0; i < _state.Count; i++)
            {
                if (_state[i].StateName.Equals(stateName, StringComparison.OrdinalIgnoreCase))
                {
                    _state.RemoveAt(i);
                    break;
                }
            }

            StateData stateData;

            stateData.StateName = stateName;
            stateData.Param     = stateParam;
            _state.Add(stateData);
            AddStateHistory(stateName);

            SwitchState(UIStateChangeTypePush, oldStateName, stateName, stateParam);

            _switchState = false;

            return(true);
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 同步发送事件
        /// </summary>
        /// <param name="id">事件ID</param>
        /// <param name="arg">事件参数</param>
        public void SendEvent(uint id, EventArg arg)
        {
            bool discard = false;
            int  count   = _eventHandler.Count;

            for (int i = 0; i < count && i < _eventHandler.Count; i++)
            {
                EventHandler handler = _eventHandler[i];
                if (!handler.Valid)
                {
                    discard = true;
                    continue;
                }

                if (!handler.IsEqual(id))
                {
                    continue;
                }

                handler.Invoke(ref arg);
            }

            if (discard)
            {
                for (int i = _eventHandler.Count - 1; i >= 0; --i)
                {
                    if (!_eventHandler[i].Valid)
                    {
                        _eventHandler.RemoveAt(i);
                    }
                }
            }
        }
예제 #5
0
        //预加载Shader
        private bool PreloadCoroutine_Shader()
        {
            if (_shaderFilename == null)
            {
                return(false);
            }

            if (_shaderFilename.Count == 0)
            {
                return(true);
            }
            if (_shaderBundle == null)
            {
                return(true);
            }
            //单个
            if (_shaderRequest != null)
            {
                if (!_shaderRequest.isDone)
                {
                    return(false);
                }
                _shaderRequest = null;
                _shaderFilename.RemoveAt(_shaderFilename.Count - 1);
            }

            if (_shaderFilename.Count > 0)
            {
                _shaderRequest = _shaderBundle.LoadAssetAsync(_shaderFilename[_shaderFilename.Count - 1], typeof(Object));
            }

            return(false);
        }
예제 #6
0
 private void Clean()
 {
     for (int i = _httpSessions.Count - 1; i >= 0; --i)
     {
         if (_httpSessions[i].IsOver)
         {
             _httpSessions.RemoveAt(i);
         }
     }
 }
예제 #7
0
 //延迟清理
 public void ProcessControl()
 {
     for (int i = _forms.Count - 1; i >= 0; --i)
     {
         if (_forms[i] == null)
         {
             _forms.RemoveAt(i);
             continue;
         }
     }
 }
        private void AddStateHistory(string stateName)
        {
            if (string.IsNullOrEmpty(stateName))
            {
                return;
            }

            for (int i = 0; i < _stateHistory.Count; i++)
            {
                if (_stateHistory[i].Equals(stateName, StringComparison.OrdinalIgnoreCase))
                {
                    _stateHistory.RemoveAt(i);
                    break;
                }
            }
            _stateHistory.Add(stateName);

            if (_stateHistory.Count > 100)
            {
                _stateHistory.RemoveAt(0);
            }
        }
예제 #9
0
        /// <summary>
        /// 移除工厂
        /// </summary>
        /// <param name="type">对象标识</param>
        public void RemoveFactory(int type)
        {
            for (int i = 0; i < _data.Count; i++)
            {
                if (_data[i].Type != type)
                {
                    continue;
                }

                _data.RemoveAt(i);
                return;
            }
        }
        /// <summary>
        /// 移除Mediaotr
        /// </summary>
        /// <param name="mediator">mediator</param>
        public void RemoveMediator(UIMediator mediator)
        {
            if (mediator == null)
            {
                return;
            }

            for (int i = 0; i < _mediator.Count; i++)
            {
                if (_mediator[i].Mediator == mediator)
                {
                    _mediator.RemoveAt(i);
                    return;
                }
            }
        }
예제 #11
0
        protected void LateUpdate()
        {
            //清理
            if (_updateCheckers != null)
            {
                for (int i = _updateCheckers.Count - 1; i >= 0; --i)
                {
                    if (_updateCheckers[i].IsDone)
                    {
                        IFSUpdateChecker.Destory(_updateCheckers[i]);
                        _updateCheckers.RemoveAt(i);
                    }
                }
            }
            //
            if (_sessionProcessors != null)
            {
                for (int i = _sessionProcessors.Count - 1; i >= 0; --i)
                {
                    if (_sessionProcessors[i].IsDone)
                    {
                        IFSSessionProcessor.Destory(_sessionProcessors[i]);
                        _sessionProcessors.RemoveAt(i);
                    }
                }
            }

            if (_localCheckers != null)
            {
                for (int i = _localCheckers.Count - 1; i >= 0; --i)
                {
                    if (_localCheckers[i].IsDone)
                    {
                        IFSLocalChecker.Destory(_localCheckers[i]);
                        _localCheckers.RemoveAt(i);
                    }
                }
            }
        }
예제 #12
0
 public void CleanSession()
 {
     for (int i = _prepareSessions.Count - 1; i >= 0; --i)
     {
         if (_prepareSessions[i].IsOver)
         {
             _prepareSessions.RemoveAt(i);
         }
     }
     //
     if (_prepareSessions.Count <= 0)
     {
         //保存记录
         int offset = 0;
         _cachedNetAssetInfoSet.Write(S_Buffer, ref offset);
         if (JW.Res.FileUtil.IsFileExist(S_CachedNetAssetInfoSetFileFullPath))
         {
             JW.Res.FileUtil.DeleteFile(S_CachedNetAssetInfoSetFileFullPath);
         }
         JW.Res.FileUtil.WriteFile(S_CachedNetAssetInfoSetFileFullPath, S_Buffer, 0, offset);
     }
 }
예제 #13
0
        /// <summary>
        /// Mono Behavior 驱动
        /// </summary>
        protected void Update()
        {
            // Update
            bool updateDiscard = false;

            int count = _updates.Count;

            for (int i = 0; i < count && i < _updates.Count; i++)
            {
                IScheduleHandler handler = _updates[i];
                if (handler != null)
                {
                    try
                    {
                        handler.OnScheduleHandle(ScheduleType.Updator, 0);
                    }
                    catch (Exception e)
                    {
                        JW.Common.Log.LogE("ScheduleService.Update : update exception {0} at handler {1}", e, handler.GetType().Name);
                        throw;
                    }
                }
                else
                {
                    updateDiscard = true;
                }
            }

            // Timer
            int deltaTime = (int)(Time.deltaTime * 100000.0f);

            bool timerDiscard = false;

            count = _timers.Count;
            for (int i = 0; i < count && i < _timers.Count; i++)
            {
                Data             data    = _timers[i];
                IScheduleHandler handler = data.Handler;
                if (handler == null)
                {
                    timerDiscard = true;
                    continue;
                }

                data.Remain -= deltaTime;
                if (data.Remain > 0)
                {
                    _timers[i] = data;
                    continue;
                }

                if (data.Repeat)
                {
                    data.Remain += data.Interval;
                }
                else
                {
                    data.Handler = null;
                }

                _timers[i] = data;

                try
                {
                    handler.OnScheduleHandle(ScheduleType.Timer, data.ID);
                }
                catch (Exception e)
                {
                    JW.Common.Log.LogE("ScheduleService.Update : timer exception {0} at handler {1}", e, handler.GetType().Name);
                    throw;
                }
            }

            // 定帧
            bool frameDiscard = false;

            count = _frames.Count;
            for (int i = 0; i < count && i < _frames.Count; i++)
            {
                Data             data    = _frames[i];
                IScheduleHandler handler = data.Handler;
                if (handler == null)
                {
                    frameDiscard = true;
                    continue;
                }

                --data.Remain;
                if (data.Remain > 0)
                {
                    _frames[i] = data;
                    continue;
                }

                if (data.Repeat)
                {
                    data.Remain = data.Interval;
                }
                else
                {
                    data.Handler = null;
                }

                _frames[i] = data;

                try
                {
                    handler.OnScheduleHandle(ScheduleType.Frame, data.ID);
                }
                catch (Exception e)
                {
                    JW.Common.Log.LogE("ScheduleService.Update : frame exception {0} at handler {1}", e, handler.GetType().Name);
                    throw;
                }
            }

            // remove discard
            if (updateDiscard)
            {
                for (int i = _updates.Count - 1; i >= 0; --i)
                {
                    if (_updates[i] == null)
                    {
                        _updates.RemoveAt(i);
                    }
                }
            }

            if (timerDiscard)
            {
                for (int i = _timers.Count - 1; i >= 0; --i)
                {
                    if (_timers[i].Handler == null)
                    {
                        _timers.RemoveAt(i);
                    }
                }
            }

            if (frameDiscard)
            {
                for (int i = _frames.Count - 1; i >= 0; --i)
                {
                    if (_frames[i].Handler == null)
                    {
                        _frames.RemoveAt(i);
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="assetData">资源数据</param>
        public void AddTask(ref AssetData assetData)
        {
            if (assetData.Type == AssetType.UnityScene && assetData.Priority != LoadPriority.Wait)
            {
                JW.Common.Log.LogE("Loader.AddTask : invalid parameter - {0}", assetData.Name);
                assetData.Priority = LoadPriority.Wait;
            }

            if (_synLoading && (assetData.Priority == LoadPriority.Wait))
            {
                JW.Common.Log.LogE("Loader.AddTask : load is runing, can't add wait load asset - {0}", assetData.Name);
                return;
            }

            if (assetData.Priority != LoadPriority.Wait)
            {
                //进行中 重复
                for (int i = 0; i < _resourceRequesting.Count; i++)
                {
                    LoadData loadData = _resourceRequesting[i];
                    if (assetData.Type == loadData.Data.Type &&
                        assetData.Name.Equals(loadData.Data.Name, StringComparison.OrdinalIgnoreCase) &&
                        (assetData.Callback == loadData.Data.Callback))
                    {
                        loadData.Data = assetData;
                        _resourceRequesting.RemoveAt(i);

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

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

                        return;
                    }
                }
            }

            //重复?
            for (int i = 0; i < _data.Count; i++)
            {
                AssetData data = _data[i];

                if (assetData.Callback == data.Callback &&
                    assetData.Type == data.Type &&
                    assetData.Name.Equals(data.Name, StringComparison.OrdinalIgnoreCase))
                {
                    _data.RemoveAt(i);
                    break;
                }
            }


            for (int i = _data.Count - 1; i >= 0; --i)
            {
                if (_data[i].Priority <= assetData.Priority)
                {
                    _data.Insert(i + 1, assetData);
                    return;
                }
            }

            _data.Insert(0, assetData);
        }