public override void Initialize(GameObject agent, IChalkboard chalkboard) { base.Initialize(agent, chalkboard); navMeshAgent = agent.GetComponent <NavMeshAgent>(); Debug.Assert(navMeshAgent != null, "MoveTo behaviour requires a NavMeshAgent component on the agent."); }
public override void Initialize(GameObject agent, IChalkboard chalkboard) { base.Initialize(agent, chalkboard); this.agent = agent; variableRegex = new Regex(@"\{([^}]*)\}", RegexOptions.Compiled); }
public override void Initialize(GameObject agent, IChalkboard chalkboard) { base.Initialize(agent, chalkboard); noInteractablesBehaviour.Initialize(agent, chalkboard); interactablesBehaviour.Initialize(agent, chalkboard); transform = agent.transform; }
public override void Initialize(GameObject agent, IChalkboard chalkboard) { base.Initialize(agent, chalkboard); homePosition = agent.transform.position; sqrMagnitudeRange = maxRange * maxRange; navMeshAgent = agent.GetComponent <NavMeshAgent>(); Debug.Assert(navMeshAgent != null, "MoveTo behaviour requires a NavMeshAgent component on the agent."); }
private string ReplaceVariables(IChalkboard chalkboard, string expandedMessage) { MatchCollection matches = variableRegex.Matches(expandedMessage); for (int i = 0; i < matches.Count; i++) { string token = matches[i].Groups[0].Value; int index = matches[i].Groups[0].Index; string variableName = matches[i].Groups[1].Value; string stringValue; if (variableName == "agent") { stringValue = agent.name; } else { UnityEngine.Object unityValue = chalkboard.GetUnity <UnityEngine.Object>(variableName); if (unityValue != null) { stringValue = unityValue.ToString(); } else { System.Object systemValue = chalkboard.GetSystem <System.Object>(variableName); if (systemValue != null) { stringValue = systemValue.ToString(); } else { stringValue = "[Missing or unrecognized type for variable " + token + "]"; } } } expandedMessage = expandedMessage.Remove(index, token.Length).Insert(index, stringValue); } return(expandedMessage); }
public override void Tick(IChalkboard chalkboard) { base.Tick(chalkboard); List <Interactable> detectedInteractables = new List <Interactable>(); Collider[] colliders = Physics.OverlapSphere(transform.position, radius, layerMask); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != transform.gameObject) { Interactable interactable = colliders[i].GetComponentInParent <Interactable>(); if (interactable) { detectedInteractables.Add(interactable); } } } chalkboard.AddOrUpdate(interactablesListName, detectedInteractables); if (detectedInteractables.Count == 0) { if (noInteractablesBehaviour) { noInteractablesBehaviour.Tick(chalkboard); } } else { Vector3 pos = detectedInteractables[0].GetInteractionPosition(); chalkboard.AddOrUpdate(chosenInteractablePositionName, pos); if (interactablesBehaviour) { interactablesBehaviour.Tick(chalkboard); } Debug.Log(transform.name + " detected " + chalkboard.GetSystem <List <Interactable> >(interactablesListName).Count + " Colliders"); } }
public override void Tick(IChalkboard chalkboard) { base.Tick(chalkboard); Vector3 position = chalkboard.GetSystem <Vector3>(targetPositionVariable); if (position == currentTargetPosition) { return; } currentTargetPosition = position; NavMeshHit hit; if (NavMesh.SamplePosition(position, out hit, 1.0f, NavMesh.AllAreas)) { position = hit.position; } navMeshAgent.SetDestination(position); navMeshAgent.isStopped = false; }
public override void Tick(IChalkboard chalkboard) { Debug.Log(ReplaceVariables(chalkboard, message)); }
/// <summary> /// Tick is where the behaviour does it's work. In the curren implementation of /// the development framework this is called on a timed basis that is controlled /// by the `AiBehaviourRunner`. However, most Ai Frameworks assume the equivalent to this /// method is called every frame. We should consider /// REFACTOR: move tick timing from `AiBehaviorRunner` to `AiBehaviour` /// See issue #3 /// </summary> /// <param name="chalkboard"></param> public virtual void Tick(IChalkboard chalkboard) { }
/// <summary> /// Initialize is called once per behavour. It is used to configure the /// behaviour and is a place where you can cache values in the chalkboard /// etc. /// </summary> /// <param name="agent">The agent this behaviour belongs to.</param> /// <param name="chalkboard">The chalkboard for sharing variables between behaviours</param> public virtual void Initialize(GameObject agent, IChalkboard chalkboard) { this.agent = agent; }
public override void Tick(IChalkboard chalkboard) { navMeshAgent.SetDestination(GetValidWanderPosition(navMeshAgent.transform, 0)); navMeshAgent.isStopped = false; }