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