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