//------------------------------------------------------------------------/ // Methods: Static //------------------------------------------------------------------------/ /// <summary> /// Returns an instance of this behavior system to be used by a single agent. /// </summary> /// <param name="agent"></param> /// <returns></returns> public StratusBehaviorSystem Instantiate(StratusAgent agent) { var behaviorSystem = Instantiate(this); behaviorSystem.agent = agent; return(behaviorSystem); }
protected override Status OnTaskUpdate(StratusAgent agent) { // If not within range of the target, approach it TargetType target = GetTarget(agent); Vector3 targetPosition = this.GetTargetPosition(target); if (!IsWithinRange(agent, targetPosition)) { if (!isApproaching) { bool canApproach = this.Approach(agent, targetPosition); if (canApproach) { this.isApproaching = true; } else { return(Status.Failure); } } // If there's a valid target, approach it //this.Approach(); return(Status.Running); } // If it's in range, perform the underlying action this.isApproaching = false; return(OnTargetActionUpdate(agent, target)); }
//------------------------------------------------------------------------/ // Static Methods //------------------------------------------------------------------------/ public static bool DispatchMoveToEvent(StratusAgent agent, Vector3 position) { MoveEvent e = new MoveEvent(position); agent.gameObject.Dispatch(e); return(e.accepted); }
/// <summary> /// Selects an agent to control /// </summary> /// <param name="hit"></param> protected override void OnLeftMouseButtonDown(RaycastHit hit) { var target = hit.transform.GetComponent <StratusAgent>(); if (target) { this.agent = target; StratusDebug.Log("Now controlling " + this.agent); } }
/// <summary> /// Initializes an instance of this system, unique for the given agent /// </summary> /// <param name="agent"></param> /// <param name="system"></param> public static StratusBehaviorSystem InitializeSystemInstance(StratusAgent agent, StratusBehaviorSystem system) { if (!agentBehaviors.ContainsKey(agent)) { agentBehaviors.Add(agent, system.Instantiate(agent)); } StratusBehaviorSystem instance = agentBehaviors[agent]; instance.InitializeSystem(); return(instance); }
//------------------------------------------------------------------------/ // Methods: Public //------------------------------------------------------------------------/ public void Execute(StratusAgent agent) { if (!this.initialized) { this.timer = new StratusStopwatch(interval + Random.Range(0, deviation)); this.initialized = true; } this.timer.Update(); if (this.timer.isFinished) { this.OnExecute(agent); this.timer.Reset(); } }
protected override Status OnTaskUpdate(StratusAgent agent) { // Update the progress timer. bool isFinished = timer.Update(Time.deltaTime); // Update the action if (!isFinished) { var status = this.OnTimedActionUpdate(agent); return(status); //if (status != Status.Success) // return Status.Running; } // If the timer has finished, end the action return(Status.Success); }
protected override void OnExecute(StratusAgent agent) { Vector3 position = Vector3.zero; switch (this.type) { case Type.Point: position = agent.transform.position; Vector2 offset = Random.insideUnitCircle * this.radius; position.x += offset.x; position.z += offset.y; break; case Type.Target: Transform[] targets = agent.transform.GetTransformsWithinRadius(this.radius); position = targets.Random().position; break; } agent.blackboard.SetLocal(agent.gameObject, this.key, position); }
protected abstract Status OnTaskUpdate(StratusAgent agent);
protected override void OnTaskEnd(StratusAgent agent) { this.OnTimedActionEnd(agent); }
//------------------------------------------------------------------------/ // Interface //------------------------------------------------------------------------/ protected abstract void OnTaskStart(StratusAgent agent);
//------------------------------------------------------------------------/ // Interface //------------------------------------------------------------------------/ protected override void OnTaskStart(StratusAgent agent) { this.timer = new StratusCountdown(this.duration); }
protected override void OnTaskEnd(StratusAgent agent) { TargetType target = GetTarget(agent); this.OnTargetActionEnd(agent, target); }
/// <summary> /// Updates an instance of the system that is unique for the given agent /// </summary> /// <param name="agent"></param> /// <param name="system"></param> public static void UpdateSystemInstance(StratusAgent agent) { agentBehaviors[agent].UpdateSystem(); }
protected override void OnTaskStart(StratusAgent agent) { }
protected abstract Status OnTargetActionUpdate(StratusAgent agent, TargetType target);
//------------------------------------------------------------------------/ // Interface //------------------------------------------------------------------------/ protected abstract void OnTimedActionStart(StratusAgent agent);
protected override void OnTargetActionEnd(StratusAgent agent, Vector3 target) { StratusDebug.Log($"Arrived at target"); }
//------------------------------------------------------------------------/ // Methods //------------------------------------------------------------------------/ /// <summary> /// Checks whether the agent is within range of its target /// </summary> /// <returns></returns> protected bool IsWithinRange(StratusAgent agent, Vector3 targetPosition) { return(StratusDetection.CheckRange(agent.transform, targetPosition, this.range)); }
protected override void OnTargetActionStart(StratusAgent agent, Vector3 target) { }
protected override Status OnTargetActionUpdate(StratusAgent agent, Vector3 target) { return(Status.Success); }
protected override void OnTaskEnd(StratusAgent agent) { StratusDebug.Log(message); }
protected abstract void OnTaskEnd(StratusAgent agent);
protected abstract Status OnTimedActionUpdate(StratusAgent agent);
protected abstract void OnTargetActionEnd(StratusAgent agent, TargetType target);
protected abstract void OnTimedActionEnd(StratusAgent agent);
/// <summary> /// Resets the behaviour system so that it must evaluate from the beginning /// </summary> public void ResetSystemInstance(StratusAgent agent) { agentBehaviors[agent].ResetSystem(); }
protected override Status OnTaskUpdate(StratusAgent agent) { return(Status.Success); }
private void OnAgentSelected(StratusAgent agent) { this.selectedAgent = agent; }
protected override void OnManagedAwake() { base.OnManagedAwake(); this.agent = GetComponent <StratusAgent>(); }