コード例 #1
0
        //------------------------------------------------------------------------/
        // 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));
        }
コード例 #3
0
        //------------------------------------------------------------------------/
        // Static Methods
        //------------------------------------------------------------------------/
        public static bool DispatchMoveToEvent(StratusAgent agent, Vector3 position)
        {
            MoveEvent e = new MoveEvent(position);

            agent.gameObject.Dispatch(e);
            return(e.accepted);
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        /// <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);
        }
コード例 #8
0
        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);
        }
コード例 #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();
 }
コード例 #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);
コード例 #27
0
 /// <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;
 }
コード例 #30
0
 protected override void OnManagedAwake()
 {
     base.OnManagedAwake();
     this.agent = GetComponent <StratusAgent>();
 }