예제 #1
0
        public HotfixBasicEnvironment(Assembly hotfixAssembly)
        {
            Type[] types = hotfixAssembly.GetTypes();
            for (int i = 0; i < types.Length; i++)
            {
                if (types[i].BaseType == typeof(HotfixProcedure))
                {
                    HotfixProcedureStateAttribute hpsa = types[i].GetCustomAttribute <HotfixProcedureStateAttribute>();
                    if (hpsa != null)
                    {
                        if (hpsa.State == HotfixProcedureState.Entrance)
                        {
                            _entranceProcedure = types[i];
                            if (!_procedureInstances.ContainsKey(types[i]))
                            {
                                _procedureInstances.Add(types[i], Activator.CreateInstance(types[i]) as HotfixProcedure);
                            }
                        }
                        else if (hpsa.State == HotfixProcedureState.Normal)
                        {
                            if (!_procedureInstances.ContainsKey(types[i]))
                            {
                                _procedureInstances.Add(types[i], Activator.CreateInstance(types[i]) as HotfixProcedure);
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair <Type, HotfixProcedure> procedureInstance in _procedureInstances)
            {
                procedureInstance.Value.OnInit();
            }

            if (_entranceProcedure != null)
            {
                _currentProcedure = _procedureInstances[_entranceProcedure];
                _currentProcedure.OnEnter();
            }
            else
            {
                GlobalTools.LogError("进入热更新流程失败:未指定热更新入口流程!");
            }

            Main.m_Hotfix.UpdateHotfixLogicEvent += UpdateHotfixLogic;
        }
예제 #2
0
        /// <summary>
        /// 切换热更新流程
        /// </summary>
        public void SwitchProcedure <T>() where T : HotfixProcedure
        {
            if (_procedureInstances.ContainsKey(typeof(T)))
            {
                if (_currentProcedure == _procedureInstances[typeof(T)])
                {
                    return;
                }

                if (_currentProcedure != null)
                {
                    _currentProcedure.OnLeave();
                }

                _currentProcedure = _procedureInstances[typeof(T)];
                _currentProcedure.OnEnter();
            }
            else
            {
                GlobalTools.LogError("切换热更新流程失败:不存在流程 " + typeof(T).Name + " 或者流程未激活!");
            }
        }