// Returns success if an object was found otherwise failure
 public override TaskStatus OnUpdate()
 {
     // If the target object is null then determine if there are any objects within hearing range based on the layer mask
     if (targetObject.Value == null)
     {
         if (usePhysics2D)
         {
             returnedObject.Value = MovementUtility.WithinHearingRange2D(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
         }
         else
         {
             returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
         }
     }
     else     // If the target is not null then determine if that object is within sight
     {
         returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, targetObject.Value);
     }
     if (returnedObject.Value != null)
     {
         // returnedObject success if an object was heard
         return(TaskStatus.Success);
     }
     // An object is not within heard so return failure
     return(TaskStatus.Failure);
 }
 public virtual TaskStatus OnUpdate()
 {
     if (Object.op_Equality((Object)((Task)this).transform, (Object)null) || this.objects == null)
     {
         return((TaskStatus)1);
     }
     for (int index = 0; index < this.objects.Count; ++index)
     {
         if (!Object.op_Equality((Object)this.objects[index], (Object)null) && (double)Vector3.SqrMagnitude(Vector3.op_Subtraction(this.objects[index].get_transform().get_position(), Vector3.op_Addition(((Transform)((Task)this).transform).get_position(), this.offset.get_Value()))) < (double)this.sqrMagnitude)
         {
             if (this.lineOfSight.get_Value())
             {
                 if (Object.op_Implicit((Object)MovementUtility.LineOfSight((Transform)((Task)this).transform, this.offset.get_Value(), this.objects[index], this.targetOffset.get_Value(), this.usePhysics2D, ((LayerMask) ref this.ignoreLayerMask).get_value())))
                 {
                     this.returnedObject.set_Value(this.objects[index]);
                     return((TaskStatus)2);
                 }
             }
             else
             {
                 this.returnedObject.set_Value(this.objects[index]);
                 return((TaskStatus)2);
             }
         }
     }
     return((TaskStatus)1);
 }
Exemple #3
0
 // Returns success if an object was found otherwise failure
 public override TaskStatus OnUpdate()
 {
     if (usePhysics2D)
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject.Value == null)
         {
             returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
         }
         else     // If the target is not null then determine if that object is within sight
         {
             returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask);
         }
     }
     else
     {
         // If the target object is null then determine if there are any objects within sight based on the layer mask
         if (targetObject.Value == null)
         {
             returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
         }
         else     // If the target is not null then determine if that object is within sight
         {
             returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask);
         }
     }
     if (returnedObject.Value != null)
     {
         // Return success if an object was found
         return(TaskStatus.Success);
     }
     // An object is not within sight so return failure
     return(TaskStatus.Failure);
 }
Exemple #4
0
        public static GameObject WithinSight2D(
            Transform transform,
            Vector3 positionOffset,
            float fieldOfViewAngle,
            float viewDistance,
            LayerMask objectLayerMask,
            Vector3 targetOffset,
            float angleOffset2D,
            LayerMask ignoreLayerMask)
        {
            GameObject gameObject1 = (GameObject)null;

            Collider2D[] collider2DArray = Physics2D.OverlapCircleAll(Vector2.op_Implicit(transform.get_position()), viewDistance, LayerMask.op_Implicit(objectLayerMask));
            if (collider2DArray != null)
            {
                float num = float.PositiveInfinity;
                for (int index = 0; index < collider2DArray.Length; ++index)
                {
                    float      angle;
                    GameObject gameObject2;
                    if (Object.op_Inequality((Object)(gameObject2 = MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, ((Component)collider2DArray[index]).get_gameObject(), targetOffset, true, angleOffset2D, out angle, LayerMask.op_Implicit(ignoreLayerMask), false, (HumanBodyBones)0)), (Object)null) && (double)angle < (double)num)
                    {
                        num         = angle;
                        gameObject1 = gameObject2;
                    }
                }
            }
            return(gameObject1);
        }
 public virtual TaskStatus OnUpdate()
 {
     if (this.targetObjects.get_Value() != null && this.targetObjects.get_Value().Count > 0)
     {
         GameObject gameObject1 = (GameObject)null;
         for (int index = 0; index < this.targetObjects.get_Value().Count; ++index)
         {
             float      audibility = 0.0f;
             GameObject gameObject2;
             if ((double)Vector3.Distance(this.targetObjects.get_Value()[index].get_transform().get_position(), ((Transform)((Task)this).transform).get_position()) < (double)this.hearingRadius.get_Value() && Object.op_Inequality((Object)(gameObject2 = MovementUtility.WithinHearingRange((Transform)((Task)this).transform, this.offset.get_Value(), this.audibilityThreshold.get_Value(), this.targetObjects.get_Value()[index], ref audibility)), (Object)null))
             {
                 gameObject1 = gameObject2;
             }
         }
         this.returnedObject.set_Value(gameObject1);
     }
     else if (Object.op_Equality((Object)this.targetObject.get_Value(), (Object)null))
     {
         if (this.usePhysics2D)
         {
             this.returnedObject.set_Value(MovementUtility.WithinHearingRange2D((Transform)((Task)this).transform, this.offset.get_Value(), this.audibilityThreshold.get_Value(), this.hearingRadius.get_Value(), this.objectLayerMask));
         }
         else
         {
             this.returnedObject.set_Value(MovementUtility.WithinHearingRange((Transform)((Task)this).transform, this.offset.get_Value(), this.audibilityThreshold.get_Value(), this.hearingRadius.get_Value(), this.objectLayerMask));
         }
     }
     else if ((double)Vector3.Distance((string.IsNullOrEmpty(this.targetTag.get_Value()) ? this.targetObject.get_Value() : GameObject.FindGameObjectWithTag(this.targetTag.get_Value())).get_transform().get_position(), ((Transform)((Task)this).transform).get_position()) < (double)this.hearingRadius.get_Value())
     {
         this.returnedObject.set_Value(MovementUtility.WithinHearingRange((Transform)((Task)this).transform, this.offset.get_Value(), this.audibilityThreshold.get_Value(), this.targetObject.get_Value()));
     }
     return(Object.op_Inequality((Object)this.returnedObject.get_Value(), (Object)null) ? (TaskStatus)2 : (TaskStatus)1);
 }
Exemple #6
0
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
            // If the target object is null then determine if there are any objects within hearing range based on the layer mask
            if (targetObject.Value == null)
            {
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
                if (usePhysics2D)
                {
                    objectHeard.Value = MovementUtility.WithinHearingRange2D(transform, offset.Value, linearAudibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
                }
                else
                {
#endif
                objectHeard.Value = MovementUtility.WithinHearingRange(transform, offset.Value, linearAudibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            }
#endif
            }
            else     // If the target is not null then determine if that object is within sight
            {
                objectHeard.Value = MovementUtility.WithinHearingRange(transform, offset.Value, linearAudibilityThreshold.Value, targetObject.Value);
            }
            if (objectHeard.Value != null)
            {
                // Return success if an object was heard
                return(TaskStatus.Success);
            }
            // An object is not within heard so return failure
            return(TaskStatus.Failure);
        }
Exemple #7
0
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
            if (targetObjects.Value != null && targetObjects.Value.Count > 0)   // If there are objects in the group list then search for the object within that list
            {
                GameObject objectFound = null;
                for (int i = 0; i < targetObjects.Value.Count; ++i)
                {
                    float      audibility = 0;
                    GameObject obj;
                    if (Vector3.Distance(targetObjects.Value[i].transform.position, transform.position) < hearingRadius.Value)
                    {
                        if ((obj = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, targetObjects.Value[i], ref audibility)) != null)
                        {
                            objectFound = obj;
                        }
                    }
                }
                returnedObject.Value = objectFound;
            }
            else if (targetObject.Value == null)     // If the target object is null then determine if there are any objects within hearing range based on the layer mask
            {
                if (usePhysics2D)
                {
                    returnedObject.Value = MovementUtility.WithinHearingRange2D(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask.Value);
                }
                else
                {
                    returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask.Value);
                }
            }
            else
            {
                GameObject target;
                if (!string.IsNullOrEmpty(targetTag.Value))
                {
                    target = GameObject.FindGameObjectWithTag(targetTag.Value);
                }
                else
                {
                    target = targetObject.Value;
                }
                if (Vector3.Distance(target.transform.position, transform.position) < hearingRadius.Value)
                {
                    returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, targetObject.Value);
                }
            }

            if (returnedObject.Value != null)
            {
                // returnedObject success if an object was heard
                return(TaskStatus.Success);
            }
            // An object is not within heard so return failure
            return(TaskStatus.Failure);
        }
        // Keep searching until an object is seen or heard (if senseAudio is enabled)
        public override TaskStatus OnUpdate()
        {
            if (HasArrived())
            {
                // The agent should pause at the destination only if the max pause duration is greater than 0
                if (maxPauseDuration.Value > 0)
                {
                    if (destinationReachTime == -1)
                    {
                        destinationReachTime = Time.time;
                        pauseTime            = Random.Range(minPauseDuration.Value, maxPauseDuration.Value);
                    }
                    if (destinationReachTime + pauseTime <= Time.time)
                    {
                        // Only reset the time if a destination has been set.
                        if (TrySetTarget())
                        {
                            destinationReachTime = -1;
                        }
                    }
                }
                else
                {
                    TrySetTarget();
                }
            }

            // Detect if any objects are within sight
            if (overlapColliders == null)
            {
                overlapColliders = new Collider[maxCollisionCount];
            }
            returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, overlapColliders, objectLayerMask, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
            // If an object was seen then return success
            if (returnedObject.Value != null)
            {
                return(TaskStatus.Success);
            }
            // Detect if any object are within audio range (if enabled)
            if (senseAudio.Value)
            {
                returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, overlapColliders, objectLayerMask);
                // If an object was heard then return success
                if (returnedObject.Value != null)
                {
                    return(TaskStatus.Success);
                }
            }

            // No object has been seen or heard so keep searching
            return(TaskStatus.Running);
        }
Exemple #9
0
 public static GameObject WithinSight(
     Transform transform,
     Vector3 positionOffset,
     float fieldOfViewAngle,
     float viewDistance,
     GameObject targetObject,
     Vector3 targetOffset,
     LayerMask ignoreLayerMask,
     bool useTargetBone,
     HumanBodyBones targetBone)
 {
     return(MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, targetObject, targetOffset, false, 0.0f, out float _, LayerMask.op_Implicit(ignoreLayerMask), useTargetBone, targetBone));
 }
Exemple #10
0
        // Draw the line of sight representation within the scene window
        public override void OnDrawGizmos()
        {
            if (fieldOfViewAngle == null || viewDistance == null)
            {
                return;
            }

            bool is2D = false;

#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            is2D = usePhysics2D;
#endif
            MovementUtility.DrawLineOfSight(Owner.transform, fieldOfViewAngle.Value, viewDistance.Value, is2D);
        }
Exemple #11
0
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            if (usePhysics2D)
            {
                // If the target object is null then determine if there are any objects within sight based on the layer mask
                if (targetObject.Value == null)
                {
                    objectInSight.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask);
                }
                else     // If the target is not null then determine if that object is within sight
                {
                    objectInSight.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
                }
            }
            else
            {
#endif
            // If the target object is null then determine if there are any objects within sight based on the layer mask
            if (targetObject.Value == null)
            {
                objectInSight.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask);
            }
            else         // If the target is not null then determine if that object is within sight
            {
                objectInSight.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
            }
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
        }
#endif
            if (objectInSight.Value != null)
            {
                for (int i = 0; i < ground.Length; i++)//ÅжÏÊÇ·ñÔÚ±ßԵλÖÃ
                {
                    if ((ground[i].transform.position - targetObject.Value.position).magnitude < 2)
                    {
                        return(TaskStatus.Failure);
                    }
                }
                // Return success if an object was found
                return(TaskStatus.Success);
            }

            // An object is not within sight so return failure
            return(TaskStatus.Failure);
        }
Exemple #12
0
        // Update is called once per frame
        public override TaskStatus OnUpdate()
        {
            if (transform == null || objects == null)
            {
                return(TaskStatus.Failure);
            }

            Vector3 direction;

            // check each object. All it takes is one object to be able to return success
            for (int i = 0; i < objects.Count; ++i)
            {
                if (objects[i] == null)
                {
                    continue;
                }
                direction = objects[i].transform.position - (transform.position + offset.Value);
                // check to see if the square magnitude is less than what is specified
                if (Vector3.SqrMagnitude(direction) < sqrMagnitude)
                {
                    // the magnitude is less. If lineOfSight is true do one more check
                    if (lineOfSight.Value)
                    {
                        if (MovementUtility.LineOfSight(transform, offset.Value, objects[i], targetOffset.Value, false, ignoreLayerMask.value))
                        {
                            // the object has a magnitude less than the specified magnitude and is within sight. Set the object and return success
                            objects[i].transform.root.GetComponent <Health>().ApplyDamage(damageToApply.Value);
                            return(TaskStatus.Success);
                        }
                    }
                    else
                    {
                        // the object has a magnitude less than the specified magnitude. Set the object and return success
                        objects[i].transform.root.GetComponent <Health>().ApplyDamage(damageToApply.Value);
                        return(TaskStatus.Success);
                    }
                }
            }
            // no objects are within distance. Return failure
            return(TaskStatus.Failure);
        }
Exemple #13
0
        // returns success if any object is within distance of the current object. Otherwise it will return failure
        public override TaskStatus OnUpdate()
        {
            if (transform == null || objects.Value == null)
            {
                return(TaskStatus.Failure);
            }

            Vector3 direction;

            // check each object. All it takes is one object to be able to return success
            for (int i = 0; i < objects.Value.Count; ++i)
            {
                direction = objects.Value[i].position - (transform.position + offset.Value);
                // check to see if the square magnitude is less than what is specified
                if (Vector3.SqrMagnitude(direction) < sqrMagnitude)
                {
                    // the magnitude is less. If lineOfSight is true do one more check
                    if (lineOfSight.Value)
                    {
                        bool is2D = false;
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
                        is2D = usePhysics2D;
#endif
                        if (MovementUtility.LineOfSight(transform, offset.Value, objects.Value[i], is2D))
                        {
                            // the object has a magnitude less than the specified magnitude and is within sight. Set the object and return success
                            foundObject.Value = objects.Value[i];
                            return(TaskStatus.Success);
                        }
                    }
                    else
                    {
                        // the object has a magnitude less than the specified magnitude. Set the object and return success
                        foundObject.Value = objects.Value[i];
                        return(TaskStatus.Success);
                    }
                }
            }
            // no objects are within distance. Return failure
            return(TaskStatus.Failure);
        }
Exemple #14
0
        public override TaskStatus OnUpdate()
        {
            if (!string.IsNullOrEmpty(targetTag.Value))
            {
                returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, GameObject.FindGameObjectWithTag(targetTag.Value), targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
            }
            else
            {
                base.OnUpdate();
            }

            if (returnedObject.Value != null)
            {
                // only change output value if target has been found
                OutputObject.Value = returnedObject.Value;
                // Return success if an object was found
                return(TaskStatus.Success);
            }

            // An object is not within sight so return failure
            return(TaskStatus.Failure);
        }
Exemple #15
0
        public static GameObject WithinSight(
            Transform transform,
            Vector3 positionOffset,
            float fieldOfViewAngle,
            float viewDistance,
            GameObject targetObject,
            Vector3 targetOffset,
            bool usePhysics2D,
            float angleOffset2D,
            out float angle,
            int ignoreLayerMask,
            bool useTargetBone,
            HumanBodyBones targetBone)
        {
            if (Object.op_Equality((Object)targetObject, (Object)null))
            {
                angle = 0.0f;
                return((GameObject)null);
            }
            Animator componentForType;

            if (useTargetBone && Object.op_Inequality((Object)(componentForType = MovementUtility.GetComponentForType <Animator>(targetObject)), (Object)null))
            {
                Transform boneTransform = componentForType.GetBoneTransform(targetBone);
                if (Object.op_Inequality((Object)boneTransform, (Object)null))
                {
                    targetObject = ((Component)boneTransform).get_gameObject();
                }
            }
            Vector3 vector3 = Vector3.op_Subtraction(targetObject.get_transform().get_position(), transform.TransformPoint(positionOffset));

            if (usePhysics2D)
            {
                Vector3     eulerAngles = transform.get_eulerAngles();
                ref Vector3 local       = ref eulerAngles;
                local.z   = (__Null)(local.z - (double)angleOffset2D);
                angle     = Vector3.Angle(vector3, Quaternion.op_Multiply(Quaternion.Euler(eulerAngles), Vector3.get_up()));
                vector3.z = (__Null)0.0;
            }
Exemple #16
0
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            if (usePhysics2D)
            {
                // If the target object is null then determine if there are any objects within sight based on the layer mask
                if (targetObject.Value == null)
                {
                    objectInSight.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask);
                }
                else     // If the target is not null then determine if that object is within sight
                {
                    objectInSight.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
                }
            }
            else
            {
#endif
            // If the target object is null then determine if there are any objects within sight based on the layer mask
            if (targetObject.Value == null)
            {
                objectInSight.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask);
            }
            else         // If the target is not null then determine if that object is within sight
            {
                objectInSight.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value);
            }
#if !(UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
        }
#endif
            if (objectInSight.Value != null)
            {
                gameObjectInSight.Value = objectInSight.Value.gameObject;
                // Return success if an object was found
                return(TaskStatus.Success);
            }
            // An object is not within sight so return failure
            return(TaskStatus.Failure);
        }
 // Returns success if an object was found otherwise failure
 public override TaskStatus OnUpdate()
 {
     // If the target object is null then determine if there are any objects within hearing range based on the layer mask
     if (targetObject.Value == null)
     {
         if (usePhysics2D)
         {
             returnedObject.Value = MovementUtility.WithinHearingRange2D(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
         }
         else
         {
             returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
         }
     }
     else
     {
         GameObject target;
         if (!string.IsNullOrEmpty(targetTag.Value))
         {
             target = GameObject.FindGameObjectWithTag(targetTag.Value);
         }
         else
         {
             target = targetObject.Value;
         }
         if (Vector3.Distance(target.transform.position, transform.position) < hearingRadius.Value)
         {
             returnedObject.Value = MovementUtility.WithinHearingRange(transform, offset.Value, audibilityThreshold.Value, targetObject.Value);
         }
     }
     if (returnedObject.Value != null)
     {
         // returnedObject success if an object was heard
         return(TaskStatus.Success);
     }
     // An object is not within heard so return failure
     return(TaskStatus.Failure);
 }
Exemple #18
0
        // Keep searching until an object is seen or heard (if senseAudio is enabled)
        public override TaskStatus OnUpdate()
        {
            navMeshAgent.destination = Target();
            // Detect if any objects are within sight
            objectFound.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask);
            // If an object was seen then return success
            if (objectFound.Value != null)
            {
                return(TaskStatus.Success);
            }
            // Detect if any object are within audio range (if enabled)
            if (senseAudio.Value)
            {
                objectFound.Value = MovementUtility.WithinHearingRange(transform, offset.Value, linearAudibilityThreshold.Value, hearingRadius.Value, objectLayerMask);
                // If an object was heard then return success
                if (objectFound.Value != null)
                {
                    return(TaskStatus.Success);
                }
            }

            // No object has been seen or heard so keep searching
            return(TaskStatus.Running);
        }
Exemple #19
0
        /// <summary>
        ///  检测对应layer且对应势力的对象
        /// </summary>
        /// <param name="transform"></param>
        /// <param name="positionOffset"></param>
        /// <param name="fieldOfViewAngle"></param>
        /// <param name="viewDistance"></param>
        /// <param name="objectLayerMask"></param>
        /// <param name="势力"></param>
        /// <returns></returns>
        public static Transform WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask, Individual.Power power)
        {
            Transform objectFound  = null;
            var       hitColliders = Physics.OverlapSphere(transform.position, viewDistance, objectLayerMask);

            if (hitColliders != null)
            {
                for (int i = 0; i < hitColliders.Length; ++i)
                {
                    Transform obj;
                    //检测势力是否一致
                    if (hitColliders[i].gameObject.GetComponent <Individual>().power != power)
                    {
                        continue;
                    }
                    // Call the WithinSight function to determine if this specific object is within sight
                    if ((obj = MovementUtility.WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, hitColliders[i].transform)) != null)
                    {
                        objectFound = obj;
                    }
                }
            }
            return(objectFound);
        }
Exemple #20
0
 public virtual TaskStatus OnUpdate()
 {
     if (this.HasArrived())
     {
         if ((double)this.maxPauseDuration.get_Value() > 0.0)
         {
             if ((double)this.destinationReachTime == -1.0)
             {
                 this.destinationReachTime = Time.get_time();
                 this.pauseTime            = Random.Range(this.minPauseDuration.get_Value(), this.maxPauseDuration.get_Value());
             }
             if ((double)this.destinationReachTime + (double)this.pauseTime <= (double)Time.get_time() && this.TrySetTarget())
             {
                 this.destinationReachTime = -1f;
             }
         }
         else
         {
             this.TrySetTarget();
         }
     }
     this.returnedObject.set_Value(MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.objectLayerMask, this.targetOffset.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
     if (Object.op_Inequality((Object)this.returnedObject.get_Value(), (Object)null))
     {
         return((TaskStatus)2);
     }
     if (this.senseAudio.get_Value())
     {
         this.returnedObject.set_Value(MovementUtility.WithinHearingRange((Transform)((Task)this).transform, this.offset.get_Value(), this.audibilityThreshold.get_Value(), this.hearingRadius.get_Value(), this.objectLayerMask));
         if (Object.op_Inequality((Object)this.returnedObject.get_Value(), (Object)null))
         {
             return((TaskStatus)2);
         }
     }
     return((TaskStatus)3);
 }
Exemple #21
0
 public virtual TaskStatus OnUpdate()
 {
     if (this.usePhysics2D)
     {
         if (this.targetObjects.get_Value() != null && this.targetObjects.get_Value().Count > 0)
         {
             GameObject gameObject1 = (GameObject)null;
             float      num         = float.PositiveInfinity;
             for (int index = 0; index < this.targetObjects.get_Value().Count; ++index)
             {
                 float      angle;
                 GameObject gameObject2;
                 if (Object.op_Inequality((Object)(gameObject2 = MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.targetObjects.get_Value()[index], this.targetOffset.get_Value(), true, this.angleOffset2D.get_Value(), out angle, LayerMask.op_Implicit(this.ignoreLayerMask), this.useTargetBone.get_Value(), this.targetBone)), (Object)null) && (double)angle < (double)num)
                 {
                     num         = angle;
                     gameObject1 = gameObject2;
                 }
             }
             this.returnedObject.set_Value(gameObject1);
         }
         else if (Object.op_Equality((Object)this.targetObject.get_Value(), (Object)null))
         {
             this.returnedObject.set_Value(MovementUtility.WithinSight2D((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.objectLayerMask, this.targetOffset.get_Value(), this.angleOffset2D.get_Value(), this.ignoreLayerMask));
         }
         else if (!string.IsNullOrEmpty(this.targetTag.get_Value()))
         {
             this.returnedObject.set_Value(MovementUtility.WithinSight2D((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), GameObject.FindGameObjectWithTag(this.targetTag.get_Value()), this.targetOffset.get_Value(), this.angleOffset2D.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
         }
         else
         {
             this.returnedObject.set_Value(MovementUtility.WithinSight2D((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.targetObject.get_Value(), this.targetOffset.get_Value(), this.angleOffset2D.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
         }
     }
     else if (this.targetObjects.get_Value() != null && this.targetObjects.get_Value().Count > 0)
     {
         GameObject gameObject1 = (GameObject)null;
         float      num         = float.PositiveInfinity;
         for (int index = 0; index < this.targetObjects.get_Value().Count; ++index)
         {
             float      angle;
             GameObject gameObject2;
             if (Object.op_Inequality((Object)(gameObject2 = MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.targetObjects.get_Value()[index], this.targetOffset.get_Value(), false, this.angleOffset2D.get_Value(), out angle, LayerMask.op_Implicit(this.ignoreLayerMask), this.useTargetBone.get_Value(), this.targetBone)), (Object)null) && (double)angle < (double)num)
             {
                 num         = angle;
                 gameObject1 = gameObject2;
             }
         }
         this.returnedObject.set_Value(gameObject1);
     }
     else if (Object.op_Equality((Object)this.targetObject.get_Value(), (Object)null))
     {
         this.returnedObject.set_Value(MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.objectLayerMask, this.targetOffset.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
     }
     else if (!string.IsNullOrEmpty(this.targetTag.get_Value()))
     {
         this.returnedObject.set_Value(MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), GameObject.FindGameObjectWithTag(this.targetTag.get_Value()), this.targetOffset.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
     }
     else
     {
         this.returnedObject.set_Value(MovementUtility.WithinSight((Transform)((Task)this).transform, this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.viewDistance.get_Value(), this.targetObject.get_Value(), this.targetOffset.get_Value(), this.ignoreLayerMask, this.useTargetBone.get_Value(), this.targetBone));
     }
     return(Object.op_Inequality((Object)this.returnedObject.get_Value(), (Object)null) ? (TaskStatus)2 : (TaskStatus)1);
 }
Exemple #22
0
 public virtual void OnDrawGizmos()
 {
     MovementUtility.DrawLineOfSight(((Component)((Task)this).get_Owner()).get_transform(), this.offset.get_Value(), this.fieldOfViewAngle.get_Value(), this.angleOffset2D.get_Value(), this.viewDistance.get_Value(), this.usePhysics2D);
 }
Exemple #23
0
 public virtual void OnBehaviorComplete()
 {
     MovementUtility.ClearCache();
 }
Exemple #24
0
        // returns success if any object is within distance of the current object. Otherwise it will return failure
        public override TaskStatus OnUpdate()
        {
            if (transform == null || objects == null)
            {
                return(TaskStatus.Failure);
            }

            if (overlapCast)
            {
                objects.Clear();
                if (usePhysics2D)
                {
                    if (overlap2DColliders == null)
                    {
                        overlap2DColliders = new Collider2D[maxCollisionCount];
                    }
                    var count = Physics2D.OverlapCircleNonAlloc(transform.position, magnitude.Value, overlap2DColliders, objectLayerMask.value);
                    for (int i = 0; i < count; ++i)
                    {
                        objects.Add(overlap2DColliders[i].gameObject);
                    }
                }
                else
                {
                    if (overlapColliders == null)
                    {
                        overlapColliders = new Collider[maxCollisionCount];
                    }
                    var count = Physics.OverlapSphereNonAlloc(transform.position, magnitude.Value, overlapColliders, objectLayerMask.value);
                    for (int i = 0; i < count; ++i)
                    {
                        objects.Add(overlapColliders[i].gameObject);
                    }
                }
            }

            Vector3 direction;

            // check each object. All it takes is one object to be able to return success
            for (int i = 0; i < objects.Count; ++i)
            {
                if (objects[i] == null || objects[i] == gameObject)
                {
                    continue;
                }
                direction = objects[i].transform.position - (transform.position + offset.Value);
                // check to see if the square magnitude is less than what is specified
                if (Vector3.SqrMagnitude(direction) < sqrMagnitude)
                {
                    // the magnitude is less. If lineOfSight is true do one more check
                    if (lineOfSight.Value)
                    {
                        var hitTransform = MovementUtility.LineOfSight(transform, offset.Value, objects[i], targetOffset.Value, usePhysics2D, ignoreLayerMask.value, drawDebugRay.Value);
                        if (hitTransform != null && MovementUtility.IsAncestor(hitTransform, objects[i].transform))
                        {
                            // the object has a magnitude less than the specified magnitude and is within sight. Set the object and return success
                            returnedObject.Value = objects[i];
                            return(TaskStatus.Success);
                        }
                    }
                    else
                    {
                        // the object has a magnitude less than the specified magnitude. Set the object and return success
                        returnedObject.Value = objects[i];
                        return(TaskStatus.Success);
                    }
                }
            }
            // no objects are within distance. Return failure
            return(TaskStatus.Failure);
        }
Exemple #25
0
 // Returns success if an object was found otherwise failure
 public override TaskStatus OnUpdate()
 {
     if (usePhysics2D)
     {
         if (targetObjects.Value != null && targetObjects.Value.Count > 0)   // If there are objects in the group list then search for the object within that list
         {
             GameObject objectFound = null;
             float      minAngle    = Mathf.Infinity;
             for (int i = 0; i < targetObjects.Value.Count; ++i)
             {
                 float      angle;
                 GameObject obj;
                 if ((obj = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObjects.Value[i], targetOffset.Value, true, angleOffset2D.Value, out angle, ignoreLayerMask, useTargetBone.Value, targetBone)) != null)
                 {
                     // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                     if (angle < minAngle)
                     {
                         minAngle    = angle;
                         objectFound = obj;
                     }
                 }
             }
             returnedObject.Value = objectFound;
         }
         else if (!string.IsNullOrEmpty(targetTag.Value))     // If the target tag is not null then determine if there are any objects within sight based on the tag
         {
             returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, possibleTarget, targetOffset.Value, angleOffset2D.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
         }
         else if (targetObject.Value == null)                     // If the target object is null then determine if there are any objects within sight based on the layer mask
         {
             returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, angleOffset2D.Value, ignoreLayerMask);
         }
         else                     // If the target is not null then determine if that object is within sight
         {
             returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, angleOffset2D.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
         }
     }
     else
     {
         if (targetObjects.Value != null && targetObjects.Value.Count > 0)   // If there are objects in the group list then search for the object within that list
         {
             GameObject objectFound = null;
             float      minAngle    = Mathf.Infinity;
             for (int i = 0; i < targetObjects.Value.Count; ++i)
             {
                 float      angle;
                 GameObject obj;
                 if ((obj = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObjects.Value[i], targetOffset.Value, false, angleOffset2D.Value, out angle, ignoreLayerMask, useTargetBone.Value, targetBone)) != null)
                 {
                     // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                     if (angle < minAngle)
                     {
                         minAngle    = angle;
                         objectFound = obj;
                     }
                 }
             }
             returnedObject.Value = objectFound;
         }
         else if (!string.IsNullOrEmpty(targetTag.Value))     // If the target tag is not null then determine if there are any objects within sight based on the tag
         {
             returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, possibleTarget, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
         }
         else if (targetObject.Value == null)                     // If the target object is null then determine if there are any objects within sight based on the layer mask
         {
             returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
         }
         else                     // If the target is not null then determine if that object is within sight
         {
             returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
         }
     }
     if (returnedObject.Value != null)
     {
         // Return success if an object was found
         return(TaskStatus.Success);
     }
     // An object is not within sight so return failure
     return(TaskStatus.Failure);
 }
Exemple #26
0
 public override void OnBehaviorComplete()
 {
     MovementUtility.ClearCache();
 }
        // Returns success if an object was found otherwise failure
        public override TaskStatus OnUpdate()
        {
            // The collider layers on the agent can be set to ignore raycast to prevent them from interferring with the raycast checks.
            if (disableAgentColliderLayer.Value)
            {
                if (agentColliderGameObjects == null)
                {
                    if (usePhysics2D)
                    {
                        var colliders = gameObject.GetComponentsInChildren <Collider2D>();
                        agentColliderGameObjects = new GameObject[colliders.Length];
                        for (int i = 0; i < agentColliderGameObjects.Length; ++i)
                        {
                            agentColliderGameObjects[i] = colliders[i].gameObject;
                        }
                    }
                    else
                    {
                        var colliders = gameObject.GetComponentsInChildren <Collider>();
                        agentColliderGameObjects = new GameObject[colliders.Length];
                        for (int i = 0; i < agentColliderGameObjects.Length; ++i)
                        {
                            agentColliderGameObjects[i] = colliders[i].gameObject;
                        }
                    }
                    originalColliderLayer = new int[agentColliderGameObjects.Length];
                }

                // Change the layer. Remember the previous layer so it can be reset after the check has completed.
                for (int i = 0; i < agentColliderGameObjects.Length; ++i)
                {
                    originalColliderLayer[i]          = agentColliderGameObjects[i].layer;
                    agentColliderGameObjects[i].layer = ignoreRaycastLayer;
                }
            }

            if (usePhysics2D)
            {
                if (targetObjects.Value != null && targetObjects.Value.Count > 0)   // If there are objects in the group list then search for the object within that list
                {
                    GameObject objectFound = null;
                    float      minAngle    = Mathf.Infinity;
                    for (int i = 0; i < targetObjects.Value.Count; ++i)
                    {
                        float      angle;
                        GameObject obj;
                        if ((obj = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObjects.Value[i], targetOffset.Value, true, angleOffset2D.Value, out angle, ignoreLayerMask, useTargetBone.Value, targetBone)) != null)
                        {
                            // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                            if (angle < minAngle)
                            {
                                minAngle    = angle;
                                objectFound = obj;
                            }
                        }
                    }
                    returnedObject.Value = objectFound;
                }
                else if (targetObject.Value != null)     // If the target is not null then determine if that object is within sight
                {
                    returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, angleOffset2D.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
                }
                else if (!string.IsNullOrEmpty(targetTag.Value))     // If the target tag is not null then determine if there are any objects within sight based on the tag
                {
                    returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, GameObject.FindGameObjectWithTag(targetTag.Value), targetOffset.Value, angleOffset2D.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
                }
                else     // If the target object is null and there is no tag then determine if there are any objects within sight based on the layer mask
                {
                    if (overlap2DColliders == null)
                    {
                        overlap2DColliders = new Collider2D[maxCollisionCount];
                    }
                    returnedObject.Value = MovementUtility.WithinSight2D(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, overlap2DColliders, objectLayerMask, targetOffset.Value, angleOffset2D.Value, ignoreLayerMask);
                }
            }
            else
            {
                if (targetObjects.Value != null && targetObjects.Value.Count > 0)   // If there are objects in the group list then search for the object within that list
                {
                    GameObject objectFound = null;
                    float      minAngle    = Mathf.Infinity;
                    for (int i = 0; i < targetObjects.Value.Count; ++i)
                    {
                        float      angle;
                        GameObject obj;
                        if ((obj = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObjects.Value[i], targetOffset.Value, false, angleOffset2D.Value, out angle, ignoreLayerMask, useTargetBone.Value, targetBone)) != null)
                        {
                            // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                            if (angle < minAngle)
                            {
                                minAngle    = angle;
                                objectFound = obj;
                            }
                        }
                    }
                    returnedObject.Value = objectFound;
                }
                else if (targetObject.Value != null)     // If the target is not null then determine if that object is within sight
                {
                    returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
                }
                else if (!string.IsNullOrEmpty(targetTag.Value))     // If the target tag is not null then determine if there are any objects within sight based on the tag
                {
                    returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, GameObject.FindGameObjectWithTag(targetTag.Value), targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
                }
                else     // If the target object is null and there is no tag then determine if there are any objects within sight based on the layer mask
                {
                    if (overlapColliders == null)
                    {
                        overlapColliders = new Collider[maxCollisionCount];
                    }
                    returnedObject.Value = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, overlapColliders, objectLayerMask, targetOffset.Value, ignoreLayerMask, useTargetBone.Value, targetBone);
                }
            }

            if (disableAgentColliderLayer.Value)
            {
                for (int i = 0; i < agentColliderGameObjects.Length; ++i)
                {
                    agentColliderGameObjects[i].layer = originalColliderLayer[i];
                }
            }

            if (returnedObject.Value != null)
            {
                // Return success if an object was found
                return(TaskStatus.Success);
            }
            // An object is not within sight so return failure
            return(TaskStatus.Failure);
        }
 // Draw the line of sight representation within the scene window
 public override void OnDrawGizmos()
 {
     MovementUtility.DrawLineOfSight(Owner.transform, offset.Value, fieldOfViewAngle.Value, angleOffset2D.Value, viewDistance.Value, usePhysics2D);
 }