void Reset() { remainInState = MalbersTools.GetInstance <MAIState>("Remain in State"); Animal.isPlayer.Value = false; //Make sure this animal is not the Main Player AIMovement = GetComponent <MAnimalAIControl>(); if (AIMovement) { AIMovement.AutoInteract = false; AIMovement.AutoNextTarget = false; AIMovement.UpdateTargetPosition = false; AIMovement.MoveAgentOnMovingTarget = false; AIMovement.LookAtTargetOnArrival = false; } }
private void OnEnable() { m = (MAIState)target; tasks = serializedObject.FindProperty("tasks"); transitions = serializedObject.FindProperty("transitions"); GizmoStateColor = serializedObject.FindProperty("GizmoStateColor"); ID = serializedObject.FindProperty("ID"); GizmoStateColor = serializedObject.FindProperty("GizmoStateColor"); TasksType = MTools.GetAllTypes <MTask>(); DecisionType = MTools.GetAllTypes <MAIDecision>(); TasksList(); TransitionList(); }
public virtual void TransitionToState(MAIState nextState, bool decisionValue, MAIDecision decision) { if (Time.time - TransitionLastTime >= TransitionCoolDown) //This avoid making transition on the same Frame ****IMPORTANT { if (nextState != remainInState) { TransitionLastTime = Time.time; if (debug) { Debug.Log($"Changed from <B>{currentState.name} </B> to <B>{nextState.name}</B> with the decision <b>{decision.name}</b> been <B>{decisionValue}</B>."); } InvokeDecisionEvent(decisionValue, decision); StartNewState(nextState); } } }
public virtual void StartNewState(MAIState newState) { StateLastTime = Time.time; //Store the last time the Animal made a transition if (currentState != null && currentState != newState) { currentState.Finish_Tasks(this); //Finish all the Task on the Current State // currentState.Finish_Decisions(this); //Finish all the Decisions on the Current State } currentState = newState; //Set a new State ResetVarsOnNewState(); OnAIStateChanged.Invoke(currentState.ID); currentState.Start_AIState(this); //Start all Tasks on the new State currentState.Prepare_Decisions(this); //Start all Tasks on the new State }
public virtual void TransitionToState(MAIState nextState, bool decisionValue, MAIDecision decision, int Index) { if (MTools.ElapsedTime(TransitionLastTime, TransitionCoolDown)) //This avoid making transition on the same Frame ****IMPORTANT { if (nextState != null && nextState != remainInState && nextState != currentState) //Do not transition to itself! { TransitionLastTime = Time.time; decision.FinishDecision(this, Index); Debuging($"<color=white>Changed AI State from <B>[{currentState.name}]</B> to <B>[{nextState.name}]</B>. Decision: <b>[{decision.name}]</b> = <B>[{decisionValue}]</B>.</color>"); InvokeDecisionEvent(decisionValue, decision); StartNewState(nextState); } } }
void Reset() { remainInState = MTools.GetInstance <MAIState>("Remain in State"); AIMovement = this.FindComponent <MAnimalAIControl>(); if (AIMovement) { //AIMovement.AutoInteract = false; AIMovement.AutoNextTarget = false; AIMovement.UpdateTargetPosition = false; AIMovement.MoveAgentOnMovingTarget = false; AIMovement.LookAtTargetOnArrival = false; if (Animal) { Animal.isPlayer.Value = false; //Make sure this animal is not the Main Player } } else { Debug.LogWarning("There's AI Control in this GameObject"); } }
void StartNewState(MAIState newState) { StateLastTime = Time.time; //Store the last time the Animal made a transition currentState.Finish_Tasks(this); //Finish all the Task on the Current State currentState.Finish_Decisions(this); //Finish all the Decisions on the Current State currentState = newState; //Set a new State PrepareVarsOnNewState(); currentState.Start_Taks(this); //Start all Tasks on the new State currentState.Prepare_Decisions(this); //Start all Tasks on the new State foreach (var tasks in currentState.tasks) //Invoke the Task Events in case anyone wants to listen { int taskID = tasks.MessageID; if (taskID != 0) { OnTaskStarted.Invoke(taskID); } } }