protected virtual void Start() { if (_sensorTrigger != null) { AISensor sensor = _sensorTrigger.GetComponent <AISensor>(); } // 获取物体上所有的AIState AIState[] states = GetComponents <AIState>(); foreach (AIState s in states) { if (s != null && !_allStates.ContainsKey(s.GetStateType())) { _allStates[s.GetStateType()] = s; s.SetStateMachine(this); } } if (_allStates.ContainsKey(_currentStateType)) { _currentState = _allStates[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } }
public override void Initialize() { base.Initialize(); AISensor = GetComponentInChildren <AISensor>(); if (AISensor != null) { AISensor.Initialize(this); } Brain = GetComponent <AIBrain>(); if (Brain != null) { Brain.Initialize(this, AISensor); } ////FSM TESTING //FSMState normalState = FSMManager.GetState("ZombieWander"); //if (normalState != null) // EntityFSM.ChangeState(normalState); //else //{ // Debug.LogError("Can't find Zombie Wander state"); //} }
public bool HasTarget(GameObject source) { bool result = false; AISensor enemyAI = (source.Entity() as EntityEnemy).AISensor; result = enemyAI.ClosestTarget != null; return(result); }
// ----------------------------------------------------------------- // Name : Start // Desc : Called by Unity prior to first update to setup the object // ----------------------------------------------------------------- protected virtual void Start() { // Set the sensor trigger's parent to this state machine if (_sensorTrigger != null) { AISensor script = _sensorTrigger.GetComponent <AISensor>(); if (script != null) { script.parentStateMachine = this; } } // Fetch all states on this game object AIState[] states = GetComponents <AIState>(); // Loop through all states and add them to the state dictionary foreach (AIState state in states) { if (state != null && !_states.ContainsKey(state.GetStateType())) { // Add this state to the state dictionary _states[state.GetStateType()] = state; // And set the parent state machine of this state state.SetStateMachine(this); } } // Set the current state if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } // Fetch all AIStateMachineLink derived behaviours from the animator // and set their State Machine references to this state machine if (_animator) { AIStateMachineLink[] scripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in scripts) { script.stateMachine = this; } } }
protected virtual void Start() { // Setta il parent del Sensor Trigger a questa State Machine if (_sensorTrigger != null) { AISensor script = _sensorTrigger.GetComponent <AISensor>(); if (script != null) { script.parentStateMachine = this; } } // Raggruppo tutti gli stati AIState[] states = GetComponents <AIState>(); // Scorro tutti gli Stati e gli aggiungo allo State Dictionary foreach (AIState state in states) { if (state != null && !_states.ContainsKey(state.GetStateType())) { // Aggiungo lo stato allo State Dictionary _states[state.GetStateType()] = state; // Setto il parent state machine di questo stato state.SetStateMachine(this); } } // Setto lo stato attuale if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } // Raggruppo tutti gli AIStateMachineLink presi dall'Animator // e setto la referenza alla loro State Machine a questa SM if (_animator) { AIStateMachineLink[] scripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in scripts) { script.stateMachine = this; } } }
private void ProcessSensor(AISensor sensor) { for (int n = 0; n < sensor.InterestList.Count; n++) { //we are no interested in things that we can no see or hear if (sensor.InterestList[n].inRange) { if (ShouldUpdateCurrentInterest(sensor.InterestList[n])) { currentInterest = sensor.InterestList[n]; } } } }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID); _currentWorldStates = new List <GoapWorldState>(); _parentCharacter.MyEventHandler.OnCurrentActionComplete -= OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnPerFrameTimer -= PerFrameUpdate; _parentCharacter.MyEventHandler.OnPerFrameTimer += PerFrameUpdate; //update parent character for each action foreach (GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } //BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f); //BlackBoard.PatrolRange = new Vector3(30, 10, 15); if (ControlType != AIControlType.Player) { BlackBoard.GuardLevel = 1; _parentCharacter.SendCommand(CharacterCommands.SetAlert); } _currentGoal = null; _currentAction = null; _parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer; }
// Start is called before the first frame update protected virtual void Start() { if (_sensorTrigger != null) { AISensor script = _sensorTrigger.GetComponent <AISensor>(); if (script) { script.parentStateMachine = this; } } // Fetch all states on this gameobject AIState[] states = GetComponents <AIState>(); //Loop through all states and add them to the state dictionary foreach (AIState state in states) { if (state != null && !_states.ContainsKey(state.GetStateType())) { // Add this state to the state dictionary _states[state.GetStateType()] = state; // For each state found in the gameobject, we setup the state's state machine. state.SetStateMachine(this); } } // Initialize current state if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } if (_animator) { AIStateMachineLink[] _scripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in _scripts) { script.stateMachine = this; } } }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.GoapID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.GoapID); _currentWorldStates = new List<GoapWorldState>(); _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; _parentCharacter.MyEventHandler.OnPerFrameTimer += PerFrameUpdate; //update parent character for each action foreach(GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } //BlackBoard.PatrolLoc = new Vector3(63.9f, 0.3f, -13.3f); //BlackBoard.PatrolRange = new Vector3(30, 10, 15); if(ControlType != AIControlType.Player) { BlackBoard.GuardLevel = 1; _parentCharacter.SendCommand(CharacterCommands.SetAlert); } _currentGoal = null; _currentAction = null; _parentCharacter.MyEventHandler.OnOneSecondTimer += OnOneSecondTimer; }
protected override void Awake() { InitStats(); AISensor = GetComponentInChildren <AISensor>(); if (AISensor != null) { AISensor.Initialize(this); } Brain = GetComponent <AIBrain>(); if (Brain != null) { Brain.Initialize(this, AISensor); } base.Awake(); }
protected virtual void Start() { if (_sensorTrigger != null) { AISensor sensor = _sensorTrigger.GetComponent <AISensor>(); if (sensor != null) { //Debug.Log("Setting Sensor Trigger"); sensor.parentStateMachine = this; } } AIState[] states = GetComponents <AIState>(); foreach (AIState aiState in states) { if (aiState != null && !_states.ContainsKey(aiState.GetStateType())) { _states.Add(aiState.GetStateType(), aiState); aiState.SetStateMachine(this); } } if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; Debug.LogErrorFormat("Wrong State Type : " + _currentStateType); } if (_animator != null) { AIStateMachineLink[] scripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink link in scripts) { link.stateMachine = this; } } }
protected virtual void Start() { if (_sensorColiiderTrigger != null) { AISensor script = _sensorColiiderTrigger.GetComponent <AISensor>(); if (script != null) { script.SetAIStateMachine(this); } } AIState[] states = GetComponents <AIState>(); //我们在怪物本身上挂载,多个【AIState】来分别控制。 foreach (AIState state in states) { if (state != null && !_states.ContainsKey(state.GetStateType())) { _states.Add(state.GetStateType(), state); state.SetAIStateMachine(this); } } if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } // 获取从动画器派生的所有AIStateMachineLink行为, // 并将它们的状态机引用设置为该状态机. if (_anim) { AIStateMachineLink[] scripts = _anim.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in scripts) { script.stateMachine = this; } } }
protected virtual void Start() { if (_sensorTrigger != null) { AISensor script = _sensorTrigger.GetComponent <AISensor>(); if (script != null) { script.parentStateMachine = this; } } AIState[] states = GetComponents <AIState>(); foreach (AIState state in states) { if (state != null && !_states.ContainsKey(state.GetStateType())) { _states[state.GetStateType()] = state; state.SetStateMachine(this); } } if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; } if (_animator) { AIStateMachineLink[] scripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in scripts) { script.stateMachine = this; } } }
void OnEnable() { agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); animator = GetComponent <Animator>(); AIHealth = GetComponent <AIHealth>(); AISensor = GetComponentInChildren <AISensor>(); AIRender = GetComponent <AIRender>(); AITransform = transform; targetPlayer = null; currentState = FSMState.Dead; agent.enabled = false; if (autoInit) { Born(); } }
protected virtual void Start() { if (_sensorTrigger != null) { AISensor sensorScript = _sensorTrigger.GetComponent <AISensor>(); if (sensorScript != null) { sensorScript.parentStateMachine = this; } } AIState[] states = GetComponents <AIState>(); foreach (AIState state in states) { if (state != null & !_states.ContainsKey(state.GetStateType())) { // Add this state to the state dictionary _states[state.GetStateType()] = state; state.SetStateMachine(this); } } if (_states.ContainsKey(_currentStateType)) { _currentState = _states[_currentStateType]; _currentState.OnEnterState(); } else { _currentState = null; Debug.LogWarning("Cannot find state"); } if (_animator) { AIStateMachineLink[] behaviourScripts = _animator.GetBehaviours <AIStateMachineLink>(); foreach (AIStateMachineLink script in behaviourScripts) { //script.stateMachine = this; } } }
public void AddSensor(ref AISensor newSensor) { newSensor.Owner = this; sensors.Add(ref newSensor); }
public void Initialize(EntityEnemy owner, AISensor sensor) { this.Owner = owner; this.sensor = sensor; }
public ChaseTargetAction(Entity owner, bool runUpdate) : base(owner, runUpdate) { aiSensor = ((EntityEnemy)owner).AISensor; }
public void Initialize(Character character) { _parentCharacter = character; WorkingMemory = new WorkingMemory(); WorkingMemory.Initialize(_parentCharacter); BlackBoard = new BlackBoard(); Sensor = new AISensor(); Sensor.Initialize(_parentCharacter); TargetingSystem = new AITargeting(); TargetingSystem.Initialize(_parentCharacter); WeaponSystem = new AIWeapon(); WeaponSystem.Initialize(_parentCharacter); Planner = new GoapPlanner(this); _goals = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterGoalSet(_parentCharacter.ID); _actions = GameManager.Inst.DBManager.DBHandlerAI.GetCharacterActionSet(_parentCharacter.ID); _currentWorldStates = new List<GoapWorldState>(); _parentCharacter.MyEventHandler.OnNewEnemyTargetFound += OnImportantEvent; _parentCharacter.MyEventHandler.OnCurrentActionComplete += OnCurrentActionComplete; //update parent character for each action foreach(GoapAction action in _actions) { action.ParentCharacter = _parentCharacter; } BlackBoard.PatrolLoc = new Vector3(-15, 0, -15); BlackBoard.PatrolRange = new Vector3(20, 10, 20); BlackBoard.HasPatrolInfo = true; if(ControlType != AIControlType.Player) { _currentGoal = null; _currentAction = null; FindAndExecuteAction(); } }