//------------------------------------------------------------------------/
        // 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 protected abstract Status OnTaskUpdate(StratusAgent agent);
Exemplo n.º 10
0
 protected override void OnTaskEnd(StratusAgent agent)
 {
     this.OnTimedActionEnd(agent);
 }
Exemplo n.º 11
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected abstract void OnTaskStart(StratusAgent agent);
Exemplo n.º 12
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected override void OnTaskStart(StratusAgent agent)
 {
     this.timer = new StratusCountdown(this.duration);
 }
Exemplo n.º 13
0
        protected override void OnTaskEnd(StratusAgent agent)
        {
            TargetType target = GetTarget(agent);

            this.OnTargetActionEnd(agent, target);
        }
Exemplo n.º 14
0
 /// <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();
 }
Exemplo n.º 15
0
 protected override void OnTaskStart(StratusAgent agent)
 {
 }
Exemplo n.º 16
0
 protected abstract Status OnTargetActionUpdate(StratusAgent agent, TargetType target);
Exemplo n.º 17
0
 //------------------------------------------------------------------------/
 // Interface
 //------------------------------------------------------------------------/
 protected abstract void OnTimedActionStart(StratusAgent agent);
Exemplo n.º 18
0
 protected override void OnTargetActionEnd(StratusAgent agent, Vector3 target)
 {
     StratusDebug.Log($"Arrived at target");
 }
Exemplo n.º 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));
 }
Exemplo n.º 20
0
 protected override void OnTargetActionStart(StratusAgent agent, Vector3 target)
 {
 }
Exemplo n.º 21
0
 protected override Status OnTargetActionUpdate(StratusAgent agent, Vector3 target)
 {
     return(Status.Success);
 }
Exemplo n.º 22
0
 protected override void OnTaskEnd(StratusAgent agent)
 {
     StratusDebug.Log(message);
 }
Exemplo n.º 23
0
 protected abstract void OnTaskEnd(StratusAgent agent);
Exemplo n.º 24
0
 protected abstract Status OnTimedActionUpdate(StratusAgent agent);
Exemplo n.º 25
0
 protected abstract void OnTargetActionEnd(StratusAgent agent, TargetType target);
Exemplo n.º 26
0
 protected abstract void OnTimedActionEnd(StratusAgent agent);
Exemplo n.º 27
0
 /// <summary>
 /// Resets the behaviour system so that it must evaluate from the beginning
 /// </summary>
 public void ResetSystemInstance(StratusAgent agent)
 {
     agentBehaviors[agent].ResetSystem();
 }
Exemplo n.º 28
0
 protected override Status OnTaskUpdate(StratusAgent agent)
 {
     return(Status.Success);
 }
Exemplo n.º 29
0
 private void OnAgentSelected(StratusAgent agent)
 {
     this.selectedAgent = agent;
 }
Exemplo n.º 30
0
 protected override void OnManagedAwake()
 {
     base.OnManagedAwake();
     this.agent = GetComponent <StratusAgent>();
 }