Пример #1
0
 public StateModuleEditor(string name, Color mainColor, GameMode gameMode)
     : base(name, mainColor, gameMode)
 {
     _listState = new List <string>();
     Type[] types = typeof(GameMode).Assembly.GetTypes();
     foreach (var item in types)
     {
         object[] attribute = item.GetCustomAttributes(typeof(GameStateAttribute), false);
         if (attribute.Length <= 0 || item.IsAbstract)
         {
             continue;
         }
         GameStateAttribute stateAttribute = (GameStateAttribute)attribute[0];
         //if (stateAttribute.StateType == VirtualStateType.Ignore)
         //    continue;
         object    obj = Activator.CreateInstance(item);
         GameState gs  = obj as GameState;
         if (gs != null)
         {
             _listState.Add("[" + stateAttribute.StateType.ToString() + "]\t" + item.FullName);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 创建游戏状态的环境
        /// </summary>
        /// <param name="assembly">重写游戏状态所在的程序集</param>
        public void CreateContext(Assembly assembly)
        {
            if (_stateContext != null)
            {
                return;
            }

            GameStateContext stateContext = new GameStateContext();
            List <GameState> listState    = new List <GameState>();

            Type[] types = assembly.GetTypes();
            foreach (var item in types)
            {
                object[] attribute = item.GetCustomAttributes(typeof(GameStateAttribute), false);
                if (attribute.Length <= 0 || item.IsAbstract)
                {
                    continue;
                }
                GameStateAttribute stateAttribute = (GameStateAttribute)attribute[0];
                if (stateAttribute.StateType == GameStateType.Ignore)
                {
                    continue;
                }
                object    obj = Activator.CreateInstance(item);
                GameState gs  = obj as GameState;
                if (gs != null)
                {
                    listState.Add(gs);
                    if (stateAttribute.StateType == GameStateType.Start)
                    {
                        _startState = gs;
                    }
                }
            }
            stateContext.SetAllState(listState.ToArray());
            _stateContext = stateContext;
        }