コード例 #1
0
ファイル: WaitTask.cs プロジェクト: gylesis/Space-Maze
 public override void UpdateTask(MAnimalBrain brain, int index)
 {
     if (MTools.ElapsedTime(brain.TasksTime[index], brain.TasksVars[index].floatValue))
     {
         brain.TaskDone(index);
     }
 }
コード例 #2
0
ファイル: SetLookAtTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            Transform child;

            if (SetLookAtOn == Affected.Self)
            {
                if (LookAtTargetS == LookAtOption1.CurrentTarget)
                {
                    child = UseTag ? GetGameObjectByTag(brain.Target) : GetChildName(brain.Target);
                }
                else
                {
                    child = UseTag ? GetGameObjectByTag(TargetVar.Value) : GetChildName(TargetVar.Value);
                }
                brain.GetComponentInParent <IAim>()?.SetTarget(child);
            }
            else
            {
                if (LookAtTargetT == LookAtOption2.AIAnimal)
                {
                    child = UseTag ? GetGameObjectByTag(brain.Animal.transform) : GetChildName(brain.Animal.transform);
                }
                else
                {
                    child = UseTag ? GetGameObjectByTag(TargetVar.Value) : GetChildName(TargetVar.Value);
                }

                brain.Target?.GetComponentInParent <IAim>()?.SetTarget(child);
            }

            brain.TaskDone(index);
        }
コード例 #3
0
 private void ArriveToFleePoint(MAnimalBrain brain, int index)
 {
     if (brain.AIMovement.HasArrived)
     {
         brain.TaskDone(index);                              //IF we arrived to the Point we set on the Start Task then set this task as done
     }
 }
コード例 #4
0
ファイル: MoveStopTask.cs プロジェクト: gylesis/Space-Maze
        public override void OnTargetArrived(MAnimalBrain brain, Transform target, int index)
        {
            switch (task)
            {
            case MoveType.MoveToCurrentTarget:
                brain.TaskDone(index);
                break;

            case MoveType.MoveToNextTarget:
                brain.TaskDone(index);
                break;

            default:
                break;
            }
        }
コード例 #5
0
 public override void StartTask(MAnimalBrain brain, int index)
 {
     if (Play == ExecuteTask.OnStart)
     {
         StateActivate(brain);
         brain.TaskDone(index);
     }
 }
コード例 #6
0
ファイル: InvokeEventTask.cs プロジェクト: gylesis/Space-Maze
 public override void UpdateTask(MAnimalBrain brain, int index)
 {
     if (MTools.ElapsedTime(brain.TasksTime[index], Delay))
     {
         Raise.Invoke();
         brain.TaskDone(index);
     }
 }
コード例 #7
0
ファイル: InvokeEventTask.cs プロジェクト: gylesis/Space-Maze
 public override void StartTask(MAnimalBrain brain, int index)
 {
     if (Delay == 0)
     {
         Raise.Invoke();
         brain.TaskDone(index);
     }
 }
コード例 #8
0
ファイル: MessageTask.cs プロジェクト: DevilN31/Wilde-Chase
 public override void ExitTask(MAnimalBrain brain, int index)
 {
     if (when == ExecuteTask.OnExit)
     {
         Execute_Task(brain);
         brain.TaskDone(index); //Set Done to this task
     }
 }
コード例 #9
0
 public override void ExitAIState(MAnimalBrain brain, int index)
 {
     if (Play == ExecuteTask.OnExit) //If the animal is in range of the Target
     {
         StateActivate(brain);
     }
     brain.TaskDone(index);
 }
コード例 #10
0
        private Vector3 CalculateDistance(MAnimalBrain brain, int index, Vector3 DirFromTarget, float DistanceDiff, float halThreshold)
        {
            Vector3 KeepDistPoint = brain.transform.position + DirFromTarget.normalized * (DistanceDiff + halThreshold);

            brain.TaskDone(index, false);
            brain.AIMovement.UpdateTargetPosition = false; //Means the Animal Wont Update the Destination Position with the Target position.
            brain.AIMovement.StoppingDistance     = stoppingDistance;
            brain.AIMovement.SetDestination(KeepDistPoint, true);
            return(KeepDistPoint);
        }
コード例 #11
0
        private void Flee(MAnimalBrain brain, int index)
        {
            if (brain.Target)
            {
                brain.AIMovement.UpdateTargetPosition = false;                      //Means the Animal Wont Update the Destination Position with the Target position.
                var   CurrentPos      = brain.transform.position;
                var   TargetDirection = CurrentPos - brain.Target.transform.position;
                float TargetDistance  = TargetDirection.magnitude;

                if (TargetDistance < distance)
                {
                    float DistanceDiff = distance - TargetDistance;

                    Vector3 fleePoint = CurrentPos + TargetDirection.normalized * distance * 0.5f;   //player is too close from us, pick a point diametrically oppossite at twice that distance and try to move there.


                    brain.TaskDone(index, false);

                    brain.AIMovement.StoppingDistance = stoppingDistance;

                    Debug.DrawRay(fleePoint, Vector3.up * 15, Color.blue, 2f);

                    if (Vector3.Distance(CurrentPos, fleePoint) > stoppingDistance) //If the New flee Point is not in the Stopping distance radius then set a new Flee Point
                    {
                        brain.AIMovement.UpdateTargetPosition = false;              //Means the Animal Wont Update the Destination Position with the Target position.
                        brain.AIMovement.SetDestination(fleePoint, true);

                        if (brain.debug)
                        {
                            Debug.DrawRay(fleePoint, brain.transform.up, Color.blue, 2f);
                        }
                    }
                }
                else
                {
                    // if (brain.AIMovement.HasArrived)
                    {
                        brain.AIMovement.StoppingDistance = distance * 10; //Force a big Stopping distance to ensure the animal can look at the Target
                        brain.TaskDone(index);                             //Means this taks is Done ... it has Reachedn to the Fleeing Position
                    }
                }
            }
        }
コード例 #12
0
ファイル: PatrolTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (patrolType)
            {
            case PatrolType.LastWaypoint:
                if (brain.LastWayPoint != null)                                        //If we had a last Waypoint then move to it
                {
                    brain.TargetAnimal = null;                                         //Clean the Animal Target in case it was one
                    brain.AIMovement.SetTarget(brain.LastWayPoint.WPTransform);        //Move to the last waypoint the animal  used
                }
                break;

            case PatrolType.UseRuntimeSet:
                if (RuntimeSet != null)                                                 //If we had a last Waypoint then move to it
                {
                    brain.TargetAnimal = null;                                          //Clean the Animal Target in case it was one

                    switch (rtype)
                    {
                    case GetRuntimeGameObjects.RuntimeSetTypeGameObject.First:
                        brain.AIMovement.SetTarget(RuntimeSet.Item_GetFirst());
                        break;

                    case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Random:
                        brain.AIMovement.SetTarget(RuntimeSet.Item_GetRandom());
                        break;

                    case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Index:
                        brain.AIMovement.SetTarget(RuntimeSet.Item_Get(RTIndex));
                        break;

                    case GetRuntimeGameObjects.RuntimeSetTypeGameObject.ByName:
                        brain.AIMovement.SetTarget(RuntimeSet.Item_Get(RTName));
                        break;

                    case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Closest:
                        brain.AIMovement.SetTarget(RuntimeSet.Item_GetClosest(brain.Animal.gameObject));
                        break;

                    default:
                        break;
                    }
                    break;
                }

                break;

            default:
                break;
            }



            brain.TaskDone(index);
        }
コード例 #13
0
ファイル: QuickAlignTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            if (AlignTarget != null || AlignTarget.Value == null)
            {
                brain.StartCoroutine(MTools.AlignLookAtTransform(brain.Animal.transform, AlignTarget.Value, alignTime));
            }
            else
            {
                Debug.LogWarning($"The Align Target is empty or Null");
            }

            brain.TaskDone(index);
        }
コード例 #14
0
        private void KeepDistance(MAnimalBrain brain, int index)
        {
            if (brain.Target)
            {
                brain.AIMovement.StoppingDistance = stoppingDistance;

                Vector3 KeepDistPoint = brain.transform.position;

                var DirFromTarget = KeepDistPoint - brain.Target.position;

                float halThreshold = distanceThreshold * 0.5f;
                float TargetDist   = DirFromTarget.magnitude;

                if ((TargetDist /*- halThreshold*/) < distance - distanceThreshold) //Flee
                {
                    float DistanceDiff = distance - TargetDist;
                    KeepDistPoint = CalculateDistance(brain, index, DirFromTarget, DistanceDiff, halThreshold);
                    brain.TaskDone(index, false);
                }
                else if (TargetDist > distance + distanceThreshold) //Go to Target
                {
                    float DistanceDiff = TargetDist - distance;
                    KeepDistPoint = CalculateDistance(brain, index, -DirFromTarget, DistanceDiff, -halThreshold);
                    brain.TaskDone(index, false);
                }
                else
                {
                    brain.AIMovement.HasArrived       = true;
                    brain.AIMovement.StoppingDistance = distance + distanceThreshold; //Force to have a greater Stopping Distance so the animal can rotate around the target
                    brain.TaskDone(index);
                }

                if (brain.debug)
                {
                    Debug.DrawRay(KeepDistPoint, brain.transform.up, Color.cyan, interval);
                }
            }
        }
コード例 #15
0
ファイル: SetTargetTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (targetType)
            {
            case TargetToFollow.Transform:
                brain.AIMovement.SetTarget(TargetT.Value, MoveToTarget);
                break;

            case TargetToFollow.GameObject:
                brain.AIMovement.SetTarget(TargetG.Value, MoveToTarget);
                break;

            case TargetToFollow.RuntimeGameObjects:
                switch (rtype)
                {
                case GetRuntimeGameObjects.RuntimeSetTypeGameObject.First:
                    brain.AIMovement.SetTarget(TargetRG.Item_GetFirst());
                    break;

                case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Random:
                    brain.AIMovement.SetTarget(TargetRG.Item_GetRandom());
                    break;

                case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Index:
                    brain.AIMovement.SetTarget(TargetRG.Item_Get(RTIndex));
                    break;

                case GetRuntimeGameObjects.RuntimeSetTypeGameObject.ByName:
                    brain.AIMovement.SetTarget(TargetRG.Item_Get(RTName));
                    break;

                case GetRuntimeGameObjects.RuntimeSetTypeGameObject.Closest:
                    brain.AIMovement.SetTarget(TargetRG.Item_GetClosest(brain.Animal.gameObject));
                    break;

                default:
                    break;
                }
                break;

            case TargetToFollow.ClearTarget:
                brain.AIMovement.ClearTarget();
                break;

            default:
                break;
            }

            brain.TaskDone(index);
        }
コード例 #16
0
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (affect)
            {
            case Affected.Self:
                ChangeSpeed(brain.Animal);
                break;

            case Affected.Target:
                ChangeSpeed(brain.TargetAnimal);
                break;
            }
            brain.TaskDone(index); //Set Done to this task
        }
コード例 #17
0
        public override void UpdateTask(MAnimalBrain brain, int index)
        {
            if (Play == PlayWhen.Forever) //If the animal is in range of the Target
            {
                if (near && !brain.ArrivedToTarget)
                {
                    return;                                 //Dont play if Play on target is true but we are not near the target.
                }
                if (MTools.ElapsedTime(brain.TasksTime[index], CoolDown))
                {
                    PlayMode(brain);
                    brain.SetElapsedTaskTime(index);
                }
            }
            else
            {
                switch (affect)
                {
                case Affected.Self:
                    if (!brain.Animal.IsPlayingMode)
                    {
                        brain.TaskDone(index);
                    }
                    break;

                case Affected.Target:
                    if (brain.TargetAnimal && !brain.TargetAnimal.IsPlayingMode)
                    {
                        brain.TaskDone(index);
                    }
                    break;

                default:
                    break;
                }
            }
        }
コード例 #18
0
ファイル: SetStanceTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (affect)
            {
            case Affected.Self:
                Stance_Set(brain.Animal);
                break;

            case Affected.Target:
                Stance_Set(brain.TargetAnimal);
                break;
            }

            brain.TaskDone(index);
        }
コード例 #19
0
ファイル: ChanceTask.cs プロジェクト: DevilN31/Wilde-Chase
        public override void StartTask(MAnimalBrain brain, int index)
        {
            var Random = UnityEngine.Random.Range(0f, 1f);

            if (brain.debug)
            {
                Debug.Log($"Change to Try : <B>{Task.name} </B>  Chance:<B> {Chance}/{Random.ToString("F2")}</B> is <B>{Chance >= Random} </B>");
            }

            if (Chance >= Random)
            {
                Task.StartTask(brain, 0);
                brain.TaskDone(index); //Set Done to this task
            }
        }
コード例 #20
0
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (affect)
            {
            case Affected.Self:
                brain.Animal.SpeedSet_Set_Active(SpeedSet, SpeedIndex);
                brain.AIMovement.SetDefaultGroundIndex(SpeedIndex.Value);
                break;

            case Affected.Target:
                brain.TargetAnimal?.SpeedSet_Set_Active(SpeedSet, SpeedIndex);
                brain.TargetAnimal?.GetComponent <MAnimalAIControl>()?.SetDefaultGroundIndex(SpeedIndex.Value);
                break;
            }
            brain.TaskDone(index); //Set Done to this task
        }
コード例 #21
0
ファイル: SetVarListener.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (checkOn)
            {
            case Affected.Self:
                Set_VarListener(brain.Animal);
                break;

            case Affected.Target:
                Set_VarListener(brain.Target);
                break;

            default:
                break;
            }

            brain.TaskDone(index);
        }
コード例 #22
0
 /// <summary>While a AI State Ends, run this Code</summary>
 public virtual void ExitAIState(MAnimalBrain brain, int index)
 {
     brain.TaskDone(index);
 }
コード例 #23
0
ファイル: MoveStopTask.cs プロジェクト: gylesis/Space-Maze
        public override void StartTask(MAnimalBrain brain, int index)
        {
            switch (task)
            {
            case MoveType.MoveToCurrentTarget:
                if (brain.AIMovement.Target)
                {
                    if (!brain.AIMovement.CheckAirTarget())
                    {
                        brain.AIMovement.DefaultMoveToTarget();
                        brain.AIMovement.ResumeAgent();
                    }
                    brain.AIMovement.LookAtTargetOnArrival = LookAtTarget;
                }
                else
                {
                    Debug.LogWarning("The Animal does not have a current Target");
                }
                break;

            case MoveType.MoveToNextTarget:
                brain.AIMovement.SetNextTarget();
                brain.AIMovement.LookAtTargetOnArrival = LookAtTarget;
                break;

            case MoveType.Stop:
                brain.AIMovement.Stop();
                brain.AIMovement.UpdateTargetPosition = false;      //IMPORTANT or the animal will try to Move if the Target moves
                brain.TaskDone(index);
                break;

            case MoveType.StopAnimal:
                brain.Animal.LockMovement = true;
                brain.TaskDone(index);
                break;

            case MoveType.RotateInPlace:
                RotateInPlace(brain);
                break;

            case MoveType.Flee:
                Flee(brain, index);
                break;

            case MoveType.KeepDistance:
                KeepDistance(brain, index);
                break;

            case MoveType.CircleAround:
                CalculateClosestCirclePoint(brain, index);
                break;

            case MoveType.MoveToLastKnownDestination:
                var LastDestination = brain.AIMovement.DestinationPosition; //Store the Last Destination
                brain.AIMovement.DestinationPosition = Vector3.zero;
                brain.AIMovement.SetDestination(LastDestination, true);     //Go to the last Destination position


                break;

            default:
                break;
            }
        }