private void OnEnable()
        {
            _gameMain     = target as GameMain;
            _defaultColor = GUI.color;

            _listState = new List <string>();
            Type[] types = typeof(GameMain).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];
                object             obj            = Activator.CreateInstance(item);
                GameState          gs             = obj as GameState;
                if (gs != null)
                {
                    _listState.Add("[" + stateAttribute.StateType.ToString() + "]\t" + item.FullName);
                }
            }

            //Debug.Log("Count: " + _listState.Count);
        }
Exemple #2
0
        private void OnEnable()
        {
            _gameMode = target as GameMode;

            _defaultColor = GUI.color;

            #region 获取当前状态

            _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);
                }
            }

            #endregion

            #region 获取所有可操作的物体

            _operationAssets = new Dictionary <long, OperationAssetConfig>();
            OperationAssetConfig[] assetConfig = GameObject.FindObjectsOfType <OperationAssetConfig>();
            foreach (var item in assetConfig)
            {
                if (!_operationAssets.ContainsKey(item.OperationId))
                {
                    _operationAssets.Add(item.OperationId, item);
                }
                else
                {
                    long oldId = item.OperationId;
                    item.OperationId = IdGenerater.GenerateId();
                    _operationAssets.Add(item.OperationId, item);
                    Debug.Log("场景中存在两个Id一样的物体!!" + oldId + "  new Id:" + item.OperationId);
                }
            }

            #endregion
        }
 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);
         }
     }
 }
Exemple #4
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;
        }