Ejemplo n.º 1
0
        /// <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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
                }
            }
        }
Ejemplo n.º 3
0
 private void OnDestroy()
 {
     AIListeners.Unregister(this);
 }
Ejemplo n.º 4
0
 private void OnDisable()
 {
     AIListeners.Unregister(this);
 }
Ejemplo n.º 5
0
 private void OnEnable()
 {
     AIListeners.Register(this);
 }