/// <summary> /// 设置开始状态 /// </summary> /// <param name="state"></param> public void SetStartState(PEIState state, params object[] parameters) { if (_curState == null) { if (_allStates.ContainsValue(state)) { _curState = state; _curState.OnEnter(parameters); } } }
/// <summary> /// 设置开始状态 /// </summary> /// <typeparam name="T"></typeparam> public void SetStartState <T>(params object[] parameters) where T : PEIState { if (_curState == null) { int hashCode = typeof(T).GetHashCode(); if (_allStates.ContainsKey(hashCode)) { _curState = _allStates[hashCode]; _curState.OnEnter(parameters); } } }
/// <summary> /// 创建游戏状态的环境 /// </summary> /// <param name="assembly">重写游戏状态所在的程序集</param> public void CreateContext(Assembly assembly) { if (_stateContext != null) { return; } PEIState_Context stateContext = new PEIState_Context(); List <PEIState> listState = new List <PEIState>(); Type[] types = assembly.GetTypes(); foreach (var item in types) { object[] attribute = item.GetCustomAttributes(typeof(PEIStateAttribute), false); if (attribute.Length <= 0 || item.IsAbstract) { continue; } PEIStateAttribute stateAttribute = (PEIStateAttribute)attribute[0]; if (stateAttribute.StateType == PEIState_Type.Ignore) { continue; } object obj = Activator.CreateInstance(item); PEIState gs = obj as PEIState; if (gs != null) { listState.Add(gs); if (stateAttribute.StateType == PEIState_Type.Start) { _startState = gs; } } } stateContext.SetAllState(listState.ToArray()); _stateContext = stateContext; }
public PEIState_ModuleEditor(string name, Color mainColor, PEIMEN_Entity gameMode) : base(name, mainColor, gameMode) { _listState = new List <string>(); Type[] types = typeof(PEIMEN_Entity).Assembly.GetTypes(); foreach (var item in types) { object[] attribute = item.GetCustomAttributes(typeof(PEIStateAttribute), false); if (attribute.Length <= 0 || item.IsAbstract) { continue; } PEIStateAttribute stateAttribute = (PEIStateAttribute)attribute[0]; //if (stateAttribute.StateType == VirtualStateType.Ignore) // continue; object obj = Activator.CreateInstance(item); PEIState gs = obj as PEIState; if (gs != null) { _listState.Add("[" + stateAttribute.StateType.ToString() + "]\t" + item.FullName); } //PEIKDE.Log("UDE", "_listState C " + gs); } }