//------------------------------------------------------------------------/
        // 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);
        }
예제 #2
0
        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);
        }
예제 #6
0
        //------------------------------------------------------------------------/
        // 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();
            }
        }
예제 #7
0
        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);
        }
예제 #9
0
 protected abstract Status OnTaskUpdate(StratusAgent agent);
예제 #10
0
 protected override void OnTaskEnd(StratusAgent agent)
 {
     this.OnTimedActionEnd(agent);
 }
예제 #11
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected abstract void OnTaskStart(StratusAgent agent);
예제 #12
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected override void OnTaskStart(StratusAgent agent)
 {
     this.timer = new StratusCountdown(this.duration);
 }
예제 #13
0
        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();
 }
예제 #15
0
 protected override void OnTaskStart(StratusAgent agent)
 {
 }
예제 #16
0
 protected abstract Status OnTargetActionUpdate(StratusAgent agent, TargetType target);
예제 #17
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected abstract void OnTimedActionStart(StratusAgent agent);
예제 #18
0
 protected override void OnTargetActionEnd(StratusAgent agent, Vector3 target)
 {
     StratusDebug.Log($"Arrived at target");
 }
예제 #19
0
 //------------------------------------------------------------------------/
 // 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));
 }
예제 #20
0
 protected override void OnTargetActionStart(StratusAgent agent, Vector3 target)
 {
 }
예제 #21
0
 protected override Status OnTargetActionUpdate(StratusAgent agent, Vector3 target)
 {
     return(Status.Success);
 }
예제 #22
0
 protected override void OnTaskEnd(StratusAgent agent)
 {
     StratusDebug.Log(message);
 }
예제 #23
0
 protected abstract void OnTaskEnd(StratusAgent agent);
예제 #24
0
 protected abstract Status OnTimedActionUpdate(StratusAgent agent);
예제 #25
0
 protected abstract void OnTargetActionEnd(StratusAgent agent, TargetType target);
예제 #26
0
 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();
 }
예제 #28
0
 protected override Status OnTaskUpdate(StratusAgent agent)
 {
     return(Status.Success);
 }
예제 #29
0
 private void OnAgentSelected(StratusAgent agent)
 {
     this.selectedAgent = agent;
 }
 protected override void OnManagedAwake()
 {
     base.OnManagedAwake();
     this.agent = GetComponent <StratusAgent>();
 }