コード例 #1
0
ファイル: StateMachineBase.cs プロジェクト: DaveKoz/DTanks
 private void ApplyState(Type type, object[] args = null)
 {
     if (State != null)
     {
         PreviousState                 = State.GetType();
         State.NeedApplyState         -= ApplyState;
         State.NeedApplyPreviousState -= ApplyPreviousState;
         State.NeedApplyCommand       -= ApplyCommand;
         _lstCommands.ForEach(command =>
         {
             if (!command.IsIndependentFromState)
             {
                 command.Terminate();
             }
         });
         State.Finish();
         OnStateFinished();
     }
     if (!_mapStates.ContainsKey(type))
     {
         _mapStates.Add(type, Activator.CreateInstance(type) as StateBase);
         BindState(_mapStates[type]);
     }
     State = _mapStates[type];
     State.NeedApplyState         += ApplyState;
     State.NeedApplyPreviousState += ApplyPreviousState;
     State.NeedApplyCommand       += ApplyCommand;
     #if UNITY_EDITOR
     gameObject.name = _basicName + " -> " + State;
     #endif
     OnStateStarted();
     StateChanged.SafeRaise(PreviousState, type);
     State.Start(args);
 }