/// <summary> /// Registers a new alert and returns its ID. /// </summary> public static void Broadcast(Vector3 position, float range, bool isHostile, Actor actor, bool isDirect) { var alert = new GeneratedAlert(position, range, isHostile, actor, isDirect); var count = Physics.OverlapSphereNonAlloc(position, range, _colliders, 0x1, QueryTriggerInteraction.Ignore); for (int i = 0; i < count; i++) { var listener = AIListeners.Get(_colliders[i].gameObject); if (listener != null && listener.isActiveAndEnabled && Vector3.Distance(listener.transform.position, position) < range * listener.Hearing) { listener.SendMessage("OnAlert", alert, SendMessageOptions.DontRequireReceiver); } } }
/// <summary> /// Broadcasts an alert to all AIListener components in the area surrounding it. /// </summary> public static void Broadcast(Vector3 position, float range, bool isHostile, Actor actor, bool isDirect) { if (range <= float.Epsilon) { return; } var alert = new GeneratedAlert(position, range, isHostile, actor, isDirect); var count = Physics.OverlapSphereNonAlloc(position, range, Util.Colliders, Layers.Character, QueryTriggerInteraction.Ignore); for (int i = 0; i < count; i++) { var listener = AIListeners.Get(Util.Colliders[i].gameObject); if (listener != null && listener.isActiveAndEnabled && Vector3.Distance(listener.transform.position, position) < range * listener.Hearing) { listener.Hear(ref alert); } } }
private void OnDestroy() { AIListeners.Unregister(this); }
private void OnDisable() { AIListeners.Unregister(this); }
private void OnEnable() { AIListeners.Register(this); }