Exemple #1
0
        public void Init(GameObject gameObject)
        {
            _gameObject    = gameObject;
            _stateRegister = Utility.GetAIStateRegister();

            // 在FSM所在GameObject添加状态脚本
            if (_fsm.StateTransitionGraph != null)
            {
                foreach (var node in _fsm.StateTransitionGraph)
                {
                    Type state = _stateRegister.GetStateType(node.Key);
                    if (state != null && !_gameObject.GetComponent(state))
                    {
                        _gameObject.AddComponent(state);
                    }
                }
            }

            // 设置当前状态,并初始化
            Type initStateType = _stateRegister.GetStateType(_fsm.initStateName);

            if (initStateType != null)
            {
                _currState     = (_gameObject.GetComponent(initStateType) as AIState);
                _currStateName = _fsm.initStateName;
                _currState.Init();
            }
        }
 void OnEnable()
 {
     _register = target as AIStateRegister;
 }
 void OnEnable()
 {
     _currentFSMData = target as AIFSMData;
     _stateRegister  = Utility.GetAIStateRegister();
 }