private bool CalculateCondition(FSMStateData state)
        {
            var condition = state.Condition;
            var result    = false;

            for (int i = 0; i < condition.conditionNames.Count; i++)
            {
                var statement = false;
                if (condition.conditionPrefixes [i] == FSMCondition.EConditionPrefix.Negative)
                {
                    statement = !m_Conditions [condition.conditionNames [i]] ();
                }
                else
                {
                    statement = m_Conditions [condition.conditionNames [i]] ();
                }
                if (condition.conditionOperators [i] == FSMCondition.EConditionOperator.And)
                {
                    result &= statement;
                }
                else if (condition.conditionOperators [i] == FSMCondition.EConditionOperator.Or)
                {
                    result |= statement;
                }
                else
                {
                    result = statement;
                }
//				UnityEngine.Debug.Log (condition.conditionNames [i] + " - " + condition.conditionPrefixes [i].ToString () + " - " + condition.conditionOperators [i].ToString ());
            }
            return(result);
        }
 public void LoadFSM(string path)
 {
     m_FSMLoader.LoadJSON(path);
     m_Map = m_FSMLoader.FSMCurrentState;
     m_AnyState = m_FSMLoader.FSMAnyState;
     m_Conditions["IsRoot"] = IsRoot;
     m_Conditions["IsAnyState"] = IsAnyState;
 }
 public void LoadFSM(string jsonText)
 {
     m_FSMLoader.LoadJSON(jsonText);
     m_Map                      = m_FSMLoader.FSMCurrentState;
     m_AnyState                 = m_FSMLoader.FSMAnyState;
     m_Conditions["IsRoot"]     = IsRoot;
     m_Conditions["IsAnyState"] = IsAnyState;
     m_Init                     = true;
 }
Beispiel #4
0
        public void UpdateState(float dt)
        {
            if (m_Inited == false)
            {
                return;
            }
            for (int i = 0; i < m_AnyState.ListStates.Count; i++)
            {
                var stateNext = m_AnyState.ListStates[i];
                if (stateNext.StateName.Equals(m_Map.StateName))
                {
                    continue;
                }
                else if (CalculateCondition(stateNext))
                {
                    m_Map          = m_AnyState.ListStates[i];
                    m_CurrentState = EState.StartState;
                    break;
                }
            }
            var stateNow = m_States[m_Map.StateName];

            currentStateName = m_Map.StateName;
            switch (m_CurrentState)
            {
            case EState.StartState:
                stateNow.StartState();
                m_CurrentState = EState.UpdateState;
                if (OnStartState != null)
                {
                    OnStartState(currentStateName);
                }
                break;

            case EState.UpdateState:
                CalculateStateCondition();
                if (m_CurrentState == EState.UpdateState)
                {
                    stateNow.UpdateState(dt);
                    if (OnUpdateState != null)
                    {
                        OnUpdateState(currentStateName);
                    }
                }
                break;

            case EState.EndState:
                if (OnEndState != null)
                {
                    OnEndState(currentStateName);
                }
                stateNow.ExitState();
                m_Map          = m_LastState;
                m_CurrentState = EState.StartState;
                break;
            }
        }
Beispiel #5
0
 public void SetState(string name)
 {
     if (m_Inited == false)
     {
         return;
     }
     m_Map          = m_FSMLoader.FSMMaps [name];
     m_CurrentState = EState.StartState;
 }
Beispiel #6
0
        private void LoadFSM(Dictionary <string, object> data, ref FSMStateData stateData)
        {
            var state = new FSMStateData();

            state.Condition         = LoadCondition(data["condition_name"].ToString());
            state.StateName         = data["state_name"].ToString();
            m_Maps[state.StateName] = state;
            LoadChild(data["states"] as List <object>, state.ListStates);
            stateData = state;
        }
Beispiel #7
0
 public void LoadFSM(string jsonText)
 {
     m_FSMLoader.LoadJSON(jsonText);
     m_Map                      = m_FSMLoader.FSMRootStates;
     m_AnyState                 = m_FSMLoader.FSMAnyStates;
     m_Conditions["IsRoot"]     = IsRoot;
     m_Conditions["IsAnyState"] = IsAnyState;
     m_Inited                   = true;
     firstStateName             = m_FSMLoader.FSMRootStates.StateName;
 }
 private void LoadFSM(Dictionary<string, object> data, ref FSMStateData stateData)
 {
     var state = new FSMStateData();
     state.ConditionName = data["condition_name"].ToString();
     state.ConditionValue = bool.Parse (data ["condition_value"].ToString ());
     state.StateName = data["state_name"].ToString();
     m_Maps[state.StateName] = state;
     LoadChild(data["states"] as List<object>, state.ListStates);
     stateData = state;
 }
 private void CalculateStateCondition()
 {
     for (int i = 0; i < m_Map.ListStates.Count; i++)
     {
         var stateNext = m_Map.ListStates[i];
         if (CalculateCondition(stateNext))
         {
             m_CurrentState = EState.EndState;
             m_LastState    = m_Map.ListStates[i];
             break;
         }
     }
 }
Beispiel #10
0
 private void LoadChild(List <object> value, List <FSMStateData> states)
 {
     for (int i = 0; i < value.Count; i++)
     {
         var data      = value[i] as Dictionary <string, object>;
         var stateName = data["state_name"].ToString();
         var state     = new FSMStateData();
         state.Condition = LoadCondition(data["condition_name"].ToString());
         if (m_Maps.ContainsKey(stateName))
         {
             state.StateName  = stateName;
             state.ListStates = m_Maps[stateName].ListStates;
         }
         else
         {
             state.StateName   = stateName;
             m_Maps[stateName] = state;
             LoadChild(data["states"] as List <object>, state.ListStates);
         }
         states.Add(state);
     }
 }
 private void LoadChild(List<object> value, List<FSMStateData> states)
 {
     for (int i = 0; i < value.Count; i++)
     {
         var data = value[i] as Dictionary<string, object>;
         var stateName 			= data["state_name"].ToString();
         var state 				= new FSMStateData();
         state.ConditionValue 	= bool.Parse (data ["condition_value"].ToString ());
         if (m_Maps.ContainsKey(stateName))
         {
             state.ConditionName = data["condition_name"].ToString();
             state.StateName 	= stateName;
             state.ListStates 	= m_Maps[stateName].ListStates;
         }
         else
         {
             state.ConditionName = data["condition_name"].ToString();
             state.StateName 	= stateName;
             m_Maps[stateName] 	= state;
             LoadChild(data["states"] as List<object>, state.ListStates);
         }
         states.Add(state);
     }
 }
 public void SetState(string name)
 {
     m_Map          = m_FSMLoader.FSMMaps [name];
     m_CurrentState = EState.StartState;
 }
        public void UpdateState()
        {
            for (int i = 0; i < m_AnyState.ListStates.Count; i++)
            {
                var stateNext = m_AnyState.ListStates[i];
                if (stateNext.StateName.Equals(m_Map.StateName))
                {
                    continue;
                }
                else if (m_Conditions[stateNext.ConditionName]() == stateNext.ConditionValue)
                {
                    m_Map = m_AnyState.ListStates[i];
                    m_CurrentState = EState.StartState;
                    break;
                }
            }

            var stateNow = m_States[m_Map.StateName];
            StateCurrentName = m_Map.StateName;
            switch (m_CurrentState)
            {
                case EState.StartState:
                    stateNow.StartState();
                    m_CurrentState = EState.UpdateState;
                    break;
                case EState.UpdateState:
                    stateNow.UpdateState();
                    for (int i = 0; i < m_Map.ListStates.Count; i++)
                    {
                        var stateNext = m_Map.ListStates[i];
                        if (m_Conditions[stateNext.ConditionName]() == stateNext.ConditionValue)
                        {
                            m_CurrentState = EState.EndState;
                            m_LastState = m_Map.ListStates[i];
                            break;
                        }
                    }
                    break;
                case EState.EndState:
                    stateNow.ExitState();
                    m_Map = m_LastState;
                    m_CurrentState = EState.StartState;
                    break;
            }
        }
 public void SetState(string name)
 {
     m_Map = m_FSMLoader.FSMMaps [name];
     m_CurrentState = EState.StartState;
 }