public static void Remove(T listener)
            {
                if (_receivers == null || _receivers.Count == 0)
                {
                    return;
                }

                switch (_state)
                {
                case ExecutingState.None:
                    _receivers.Remove(listener);
                    break;

                case ExecutingState.Executing:
                    if (_toRemove == null)
                    {
                        _toRemove = TempCollection.GetSet <T>();
                    }
                    _toRemove.Add(listener);
                    break;

                case ExecutingState.CleaningUp:
                    _receivers.Remove(listener);
                    break;
                }
            }
            public static void Add(T listener)
            {
                if (_receivers == null)
                {
                    _receivers = new HashSet <T>();
                }

                switch (_state)
                {
                case ExecutingState.None:
                    _receivers.Add(listener);
                    break;

                case ExecutingState.Executing:
                    if (_toAdd == null)
                    {
                        _toAdd = TempCollection.GetSet <T>();
                    }
                    _toAdd.Add(listener);
                    break;

                case ExecutingState.CleaningUp:
                    _receivers.Add(listener);
                    break;
                }
            }
Example #3
0
        void IUpdateable.Update()
        {
            if (_currentToken == null)
            {
                GameLoopEntry.UpdatePump.Remove(this);
                return;
            }

            TempHashSet <AudibleSensor> activeSet = null;

            if (_activeSensors.Count > 0)
            {
                activeSet = TempCollection.GetSet(_activeSensors);
            }

            var   pos = this.transform.position;
            float d, r;

            var e = AudibleSensor.Pool.GetEnumerator();

            while (e.MoveNext())
            {
                var sensor = e.Current;
                if (_activeSensors.Contains(sensor) || sensor.Ignores(this))
                {
                    continue;
                }

                d = (sensor.transform.position - pos).sqrMagnitude;
                r = (sensor.Range + _range);
                if (d < r * r)
                {
                    _activeSensors.Add(sensor);
                    sensor.SignalEnterSiren(this);
                }
            }

            if (activeSet != null)
            {
                var e2 = activeSet.GetEnumerator();
                while (e2.MoveNext())
                {
                    var sensor = e.Current;

                    d = (sensor.transform.position - pos).sqrMagnitude;
                    r = (sensor.Range + _range);
                    if (d < r * r)
                    {
                        sensor.SignalSirenStay(this);
                    }
                    else
                    {
                        _activeSensors.Remove(sensor);
                        sensor.SignalExitSiren(this);
                    }
                }

                activeSet.Dispose();
            }
        }
Example #4
0
            public static void Execute <TArg>(TArg arg, System.Action <T, TArg> functor)
            {
                if (_executing)
                {
                    throw new System.InvalidOperationException("Can not globally broadcast a message currently executing.");
                }
                if (_receivers == null || _receivers.Count == 0)
                {
                    return;
                }

                _executing = true;
                try
                {
                    var e = _receivers.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current is UnityEngine.Object && (e.Current as UnityEngine.Object) == null)
                        {
                            //skip & remove destroyed objects
                            Remove(e.Current);
                        }
                        try
                        {
                            functor(e.Current, arg);
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogException(ex);
                        }
                    }
                }
                finally
                {
                    _executing = false;

                    if (_toRemove != null)
                    {
                        var e = _toRemove.GetEnumerator();
                        while (e.MoveNext())
                        {
                            _receivers.Remove(e.Current);
                        }
                        _toRemove.Dispose();
                        _toRemove = null;
                    }

                    if (_toAdd != null)
                    {
                        var e = _toAdd.GetEnumerator();
                        while (e.MoveNext())
                        {
                            _receivers.Add(e.Current);
                        }
                        _toAdd.Dispose();
                        _toAdd = null;
                    }
                }
            }
Example #5
0
            public static void Remove(T listener)
            {
                if (_receivers == null || _receivers.Count == 0)
                {
                    return;
                }

                if (_executing)
                {
                    if (_toRemove == null)
                    {
                        _toRemove = TempCollection.GetSet <T>();
                    }
                    _toRemove.Add(listener);
                }
                else
                {
                    _receivers.Remove(listener);
                }
            }
Example #6
0
            public static void Add(T listener)
            {
                if (_receivers == null)
                {
                    _receivers = new HashSet <T>();
                }

                if (_executing)
                {
                    if (_toAdd == null)
                    {
                        _toAdd = TempCollection.GetSet <T>();
                    }
                    _toAdd.Add(listener);
                }
                else
                {
                    _receivers.Add(listener);
                }
            }