示例#1
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);
        }
 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);
 }
 // 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);
 }
示例#4
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);
        }
示例#5
0
        // 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);
        }
 // 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);
 }
示例#7
0
文件: Search.cs 项目: deeerr/MetroVR
        // 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);
        }
示例#8
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);
 }