Beispiel #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);
 }
Beispiel #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);
        }
 // 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);
 }