示例#1
0
文件: FSMBase.cs 项目: zzhehe/3DDemo
 public void AddState(IStateBase state)
 {
     if (!statesList.Contains(state))
     {
         statesList.Add(state);
     }
 }
示例#2
0
    // Use this for initialization
    void Start()
    {
        m_OwnerEnemy = GetComponent <IEnemy>();
        NewState     = new CStateBossRageAttack(gameObject);

        m_ThreshholdAmt = m_OwnerEnemy.GetStats().MaxHP *healthCondition / 100;
    }
 public StateMachine(Dictionary <TStateEnum, IStateBase <TStateEnum, TStateData> > states)
 {
     Data = default;
     m_CurrentStateType = default;
     m_CurrentState     = null;
     m_States           = states;
 }
示例#4
0
 void Start()
 {
     activeSkin01 = title01;
     activeSkin02 = title02;
     //checker = "MainMenu";
     activeState = new MainMenu(this);
 }
示例#5
0
    // Use this for initialization
    void Start()
    {
        activeState = new BeginState(this);
        Debug.Log("This object is of type: " + activeState);

        gameDataRef=GetComponent<GameData>();
    }
示例#6
0
    /// <summary>
    /// Adds a new state to the Dictionary of states of a Gameobject
    /// </summary>
    /// <param name="_state">New State to be added into dictionary</param>
    public void AddState(IStateBase _state)
    {
        // _state is null
        if (_state == null)
        {
            DebugLogger.LogWarning <StateMachine>("State to be added is null");
            return;
        }
        // _state already in dictionary
        if (m_statesDictionary.ContainsKey(_state.GetStateName))
        {
            DebugLogger.LogWarning <StateMachine>("State has been added before");
            return;
        }
        // if current state is empty, set new state to be current and next state
        if (m_currState == null)
        {
            m_currState = m_nextState = _state;
            DebugLogger.Log <StateMachine>("New state added, current state is now " + _state.GetStateName);
        }

        // Add new states to Dictionary
        m_statesDictionary.Add(_state.GetStateName, _state);
        //DebugLogger.Log<StateMachine>("New state added : " + _state.GetStateName);
    }
 public StateMachine(GameStateBase owner)
 {
     m_owner         = owner;
     m_currentState  = null;
     m_previousState = null;
     m_globalState   = null;
 }
示例#8
0
 public void SetNextState(string _nextStateID)
 {
     if (m_stateMap.ContainsKey(_nextStateID))
     {
         m_nextState = m_stateMap[_nextStateID];
     }
 }
	void Start()
	{
		//starts BeginState, sets it to active state
		//passes this script - statemanager - to BeginState so it can use it as reference
		activeState = new BeginState(this);
		gameDataRef = GetComponent<GameData>();
	}
示例#10
0
        /// <summary>
        /// 状态切换
        /// </summary>
        /// <param name="id"></param>
        public void Change(object id, object changeHandleParam = null)
        {
            if (id.Equals(cur_StateID))
            {
                return;
            }
            else
            {
                //1.退出状态
                if (cur_State != null)
                {
                    cur_State.Exit();
                }
                //2.记录新切换的状态
                cur_StateID = id;
                cur_State   = getSate(id);
                //3.进入新状态
                cur_State.Enter();
                //4.绑定新状态更新内容
                OnUpdateHandle      = cur_State.update;
                OnFixedUpdateHandle = cur_State.fixedUpdate;
                OnLateUpdateHandle  = cur_State.lateUpdate;

                if (onChangeHandle != null && changeHandleParam != null)
                {
                    onChangeHandle.Invoke(changeHandleParam);
                }
            }
        }
        public void SetActiveState(TStateEnum type)
        {
            m_CurrentState?.Stopped(ref Data);
            m_CurrentState = m_States[type];
            var previousState = m_CurrentStateType;

            m_CurrentStateType = type;
            m_CurrentState.Started(previousState, ref Data);
        }
示例#12
0
    void Start()
    {
        cUI          = GetComponent <ControllerUI>();
        canvas       = gameObject.transform.GetChild(0).transform.gameObject;
        audioManager = gameObject.transform.GetChild(1).GetComponent <AudioManager>();
        activeState  = new BeginState(this);

        audioManager.PlaySong("Myspals_introSongStart");
    }
    void Start()
    {
        // initialize state machine and managers
        activeState = new BeginState(this);
        galaxyDataRef = GetComponent<GalaxyData>();  // gets the galaxy data script containing the data structure
        gameDataRef = GetComponent<GlobalGameData>();  // gets global game data (screens, etc) that are used universally

        Debug.Log("This object is of type: " + activeState);
    }
示例#14
0
    void Start()
    {
        // initialize state machine and managers
        activeState   = new BeginState(this);
        galaxyDataRef = GetComponent <GalaxyData>();     // gets the galaxy data script containing the data structure
        gameDataRef   = GetComponent <GlobalGameData>(); // gets global game data (screens, etc) that are used universally

        Debug.Log("This object is of type: " + activeState);
    }
示例#15
0
	void Start () {
		cUI = GetComponent<ControllerUI>();
		canvas = gameObject.transform.GetChild(0).transform.gameObject;
		audioManager = gameObject.transform.GetChild(1).GetComponent<AudioManager>();
		activeState = new BeginState(this);

		audioManager.PlaySong("Myspals_introSongStart");


	}
示例#16
0
    // Use this for initialization
    void Start()
    {
        //we start the game by calling the BeginState() constructor
        //this is the syntax for calling a constructor.
        //the "this" is sending a reference to this object - StateManager that the States use to update managerRef
        activeState = new BeginState (this);

        //Debugging if the type is correct for activeState
        Debug.Log ("What's the type of activeState? " + activeState);
    }
 public bool IsInState(IStateBase t)
 {
     if (t == CurrentState)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#18
0
 /// <summary>
 /// 删除一个状态
 /// </summary>
 /// <param name="state"></param>
 public void Remove(IStateBase state)
 {
     if (states.ContainsValue(state))
     {
         states.Remove(state);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}不存在...", state.ToString()));
     }
 }
示例#19
0
 /// <summary>
 /// 添加状态
 /// </summary>
 /// <param name="state_id">状态ID</param>
 /// <param name="state"></param>
 public virtual void Add(object state_id, IStateBase state)
 {
     if (!states.ContainsValue(state))
     {
         states.Add(state_id, state);
     }
     else
     {
         LogQueue.Add(string.Format("提醒:{0}已存在...", state.ToString()));
     }
 }
示例#20
0
 public void SwapExistingState(IStateBase _newState)
 {
     if (m_stateMap.ContainsKey(_newState.StateID))
     {
         m_stateMap[_newState.StateID] = _newState;
     }
     else
     {
         m_stateMap.Add(_newState.StateID, _newState);
     }
 }
示例#21
0
 /// <summary>
 /// This is where the updating of changing in states takes place
 /// </summary>
 public void Update()
 {
     // if next state != current state, change current to be next state
     if (m_nextState != m_currState)
     {
         m_currState.ExitState();
         m_currState = m_nextState;
         m_currState.EnterState();
     }
     // Update the curr state
     m_currState.UpdateState();
     //DebugLogger.Log<StateMachine>("Curr State: " + m_currState + " Next State: " + m_nextState);
 }
示例#22
0
 // Update is called once per frame
 public void Update()
 {
     if (m_nextState != m_currState)
     {
         m_currState.ExitState();
         m_currState = m_nextState;
         m_currState.EnterState();
     }
     if (m_currState != null)
     {
         m_currState.UpdateState();
     }
 }
示例#23
0
    void Start()
    {
        gameStateMachine_Ref = this;

        if (canvas_Ref == null)
        {
            if (transform.GetChild(0).gameObject != null)
            {
                canvas_Ref = transform.GetChild(0).gameObject;
            }
            else
            {
                Debug.Log("GameStateMachine is missing a reference to the Canvas");
            }
        }

        if (gameState == null)
        {
            gameState = new BeginState(this);
        }

        if (bordersParent_Ref == null)
        {
            if (GameObject.Find("BordersParent") != null)
            {
                bordersParent_Ref = GameObject.Find("BordersParent");
            }
            else
            {
                Debug.Log("GameStateMachine is missing a reference to BordersParent");
            }
        }

        if (playerInfoOne_Ref == null)
            Debug.Log("GameStateMachine is missing a reference to playerOneInfo");
        
        if (playerInfoTwo_Ref == null)
            Debug.Log("GameStateMachine is missing a reference to playerTwoInfo");

        playerOneSpawner_Ref.GetComponent<Spawner>().PlayerParent = playerOneParent_Ref;
        playerTwoSpawner_Ref.GetComponent<Spawner>().PlayerParent = playerTwoParent_Ref;

        gameState.ShowIt();

        playerOneBlocksCollected = new bool[playerOneSpawner_Ref.GetComponent<Spawner>().groups.Length];
        playerTwoBlocksCollected = new bool[playerTwoSpawner_Ref.GetComponent<Spawner>().groups.Length];

       if(gamesPlayedBeforeRefill == 0) { gamesPlayedBeforeRefill = 28; }
        inGameUIManager_Ref.UpdatePlayerStatus(WhoIsInTheLead());
    }
示例#24
0
 public bool CheckNewState(IStateBase newState)
 {
     if (newState != ActualState)
     {
         Console.WriteLine($"{GetType()} - State: {newState.GetType().Name} entered");
         _t.Stop();
         ActualState?.Exit();
         newState.Enter();
         _t.Start();
         ActualState = newState;
         return(true);
     }
     return(false);
 }
示例#25
0
        /// <summary>
        /// 通过ID获取一个状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        protected virtual IStateBase getSate(object id)
        {
            IStateBase _state = default(IStateBase);

            if (states.ContainsKey(id))
            {
                states.TryGetValue(id, out _state);
            }
            else
            {
                LogQueue.Add(string.Format("提醒:状态机中并不存在ID为{0}的状态", id.ToString()));
            }
            return(_state);
        }
示例#26
0
    void Start()
    {
        if (gameState == null)
        {
            gameState = new SplashScreenState(this);
        }

        audioManagerRef  = AudioManager.GetInstance();
        canvasManagerRef = CanvasManager.GetInstance();

        cam = Camera.main;

        loadManagerRef = new LoadManager();
    }
 public void ChangeState(IStateBase newState)
 {
     if (null == newState)
     {
         return;
     }
     PreviousState = CurrentState;
     if (null != CurrentState)
     {
         CurrentState.Exit(Owner);
     }
     CurrentState = newState;
     CurrentState.Enter(Owner);
 }
示例#28
0
        public void ForceChangeState(StateType nextState, params object[] objs)
        {
            if (currentState != null)
            {
                currentState.StateEnd();
            }

            currentState     = StateFactory.CreateState(nextState);
            currentStateType = nextState;
            if (currentState != null)
            {
                currentState.StateEnter(objs);
            }
        }
示例#29
0
        public void ProcessAction(IAction action)
        {
            bool       forceCallStateMethod = false;
            IStateBase newState             = ActualState.ProcessAction(action, ref forceCallStateMethod);

            if (!CheckNewState(newState))
            {
                if (forceCallStateMethod)
                {
                    ActualState.ProcessTimerElapsed();
                    _t.Stop();
                    _t.Start();
                }
            }
        }
示例#30
0
    public void AddState(IStateBase _newState)
    {
        if (_newState == null)
        {
            return;
        }
        if (m_stateMap.ContainsKey(_newState.StateID))
        {
            return;
        }
        if (m_currState == null)
        {
            m_currState = m_nextState = _newState;
        }

        m_stateMap.Add(_newState.StateID, _newState);
    }
示例#31
0
	void Start ()
	{ //Initialization
	
		Debug.Log ("Hello from StateManager");
		activeState = new BeginState (this);
		Debug.Log ("This object is of type: " + activeState);
		gameDataRef = GetComponent<GameData> ();
		timeForCoroutine = 5;
		base_url = "http://titan.csd.auth.gr:8081/api/v1/current?name=";
		Debug.Log ("url" + base_url);

		//Load a skin for the buttons
		skin = Resources.Load ("GUISkin") as GUISkin;
		audio = GetComponent<AudioSource> ();
		//if (continueCoroutine) {
		//	StartCoroutine(CallCoroutine(timeForCoroutine));
		//}

	}
示例#32
0
文件: FSMBase.cs 项目: zzhehe/3DDemo
 public void ChangeState(StateType stateType)
 {
     foreach (var item in statesList)
     {
         if (item.stateType == stateType)
         {
             if (currentState != null && IsCanChange)
             {
                 currentState.OnExit();
                 currentState = item;
                 currentState.OnEnter();
             }
             else if (currentState == null)
             {
                 currentState = item;
                 currentState.OnEnter();
             }
         }
     }
 }
示例#33
0
    void Awake()
    {
        if (instanceRef == null)
        {
                        instanceRef = this;
                        DontDestroyOnLoad (gameOject);
        }
        else
        {
            DestroyImmediate(gameObject);
        }

        void Start ()
        {
        activeState = new BeginnState(this);
        }
        void update()
        {
        if (activeState != null)
            activeState.StateUpdate();
        }
示例#34
0
        public static IStateBase CreateState(StateType stateType)
        {
            IStateBase ret = null;

            switch (stateType)
            {
            case StateType.GAME_STATE_LAUNCHER:
                ret = new GameStateLauncher();
                break;

            case StateType.GAME_STATE_LOGIN:
                ret = new GameStateLogin();
                break;

            case StateType.GAME_STATE_LOADING:
                ret = new GameStateLoading();
                break;

            default:
                ret = null;
                break;
            }
            return(ret);
        }
示例#35
0
 void Start()
 {
     activeState = new BeginState(this);
     gameDataRef = GetComponent<GameData>();
 }
示例#36
0
 public void SwitchStates(IStateBase newState)
 {
     activeState = newState;
 }
示例#37
0
 public void SwitchState(IStateBase newState)
 {
     activeState = newState;
     //StartCoroutine(ChangeLevel());
 }
示例#38
0
 void Start()
 {
     activeState = new BeginState(this);
     //print("This object of type: " + activeState);
 }
 void Start()
 {
     activeState = new BeginState(this);		// Instantiates BeginState() and assigns it to activeStateDebug.Log("This object is of type: " + activeState);
 }
 public void SwitchState(IStateBase newState)
 {
     activeState = newState;
     //StartCoroutine(ChangeLevel());
 }
示例#41
0
 // Use this for initialization
 void Start()
 {
     activeState = new ConstruktionState (this);
 }
示例#42
0
 public void SwitchState(IStateBase aNewState)
 {
     _activeState = aNewState;
     Debug.Log("Switching State!");
     _activeState.Initialize();
 }
	public void SwitchState(IStateBase newState)
	{
		//if the activeState decides it needs to change to another state
		//this function is called, and the manager updates the activeState reference
		activeState = newState;
	}
示例#44
0
 public void SwitchState(IStateBase newState)
 {
     activeState = newState;
 }
 void Start()
 {
     // this = manageRef
     activeState = new BeginState(this);
     Debug.Log("This object is of type: " + activeState);
 }
示例#46
0
    private IStateBase activeState; //reference to activeState

    #endregion Fields

    #region Methods

    //Called from the current state to notify StateManager that a new state is the activeState
    public void SwitchState( IStateBase newState)
    {
        activeState = newState;  //change the reference to the current active state
    }
示例#47
0
 //Unity-Hook: Called once when a new scene is initiated
 void Start()
 {
     activeState= new BeginState(this);   //pass in a reference to this manager
     Debug.Log ("in stateManager start" + activeState);
 }
示例#48
0
	void Start () {
		activeState = new MenüSate (this);
	}
示例#49
0
 void Start()
 {
     activeState = new BeginState(this);
 }
示例#50
0
 public void SwitchState(IStateBase newState);