public void DeadListenersRemovedRightAway() { var slot = new EventSlot(); bool called = false; bool dead = false; int count = 0; IEventListener listener = new DelegateEventListener(() => { if (count == 0) { dead = true; } else { called = true; } ++count; }, () => dead); slot.Register(listener); slot.Trigger(); dead = false; slot.Trigger(); Assert.That(!called); }
public void ExceptionsDuringTriggerDontEraseSlot() { var slot = new EventSlot(); bool called = false; IEventListener listener2 = new DelegateEventListener(() => called = true); bool dead = false; IEventListener listener = new DelegateEventListener(() => { dead = true; throw new Exception(); }, () => dead); slot.Register(listener); slot.Register(listener2); try { slot.Trigger(); } catch (Exception) {} slot.Trigger(); Assert.That(called); }
public void Release(object obj) { if (Free || obj == null) { return; } SemaphoreObject s; if (_semaphores.TryGetValue(obj, out s)) { s.Value--; if (s.Value == 0) { _semaphores.Remove(obj); } } if (Free) { _releaseEvent.Trigger(); _changeStateEvent.Trigger(true); } _onInteraction.Trigger(); }
public void Remove(K key, T value) { List <T> list; if (!_dictionary.TryGetValue(key, out list)) { return; } var deleted = list.Remove(value); if (!deleted) { return; } var count = list.Count; GetEventDrivenCountEditor(key).Setter(count); if (list.Count == 0) { _dictionary.Remove(key); GetEventDrivenContainsEditor(key).SetFalse(); } _onElementRemoved.Trigger(value); _onChange.Trigger(); // if( value != null )_ onNotNullElementRemoved.Trigger( value ); }
public bool Block(object obj, bool increaseBlock = true) { if (obj == null) { return(false); } bool trigger = Free; SemaphoreObject s; bool newKey = !_semaphores.TryGetValue(obj, out s); if (newKey || increaseBlock) { if (newKey) { s = new SemaphoreObject(); _semaphores.Add(obj, s); } s.Value++; } if (trigger) { _blockEvent.Trigger(); _changeStateEvent.Trigger(false); } _onInteraction.Trigger(); return(newKey); }
public void Start() { _r.Start(_cachedColor.r); _g.Start(_cachedColor.g); _b.Start(_cachedColor.b); _a.Start(_cachedColor.a); _colorUpdate.Trigger(_cachedColor); }
public void AddEntry(Key key, Value t) { if (_dict.ContainsKey(key)) { _dict.Remove(key); } _dict.Add(key, t); t.IsValid.RegisterOnFalse(() => RemoveEntry(key)); _onEntriesChanged.Trigger(); }
public T this[int id] { get { return(_list[id]); } set { TriggerRemoveEvents(_list[id]); _list[id] = value; _onElementAdded.Trigger(value); } }
public void Force(float value) { var val = Mathf.Clamp(value, _min, _max); if (Mathf.Approximately(_current, val)) { return; } _current = val; _onValueUpdate.Trigger(_current); CheckDesired(); }
public void Once() { var slot = new EventSlot(); int count = 0; IEventListener listener = DelegateEventListeners.Once(() => { ++count; }); slot.Register(listener); slot.Trigger(); slot.Trigger(); Assert.AreEqual(1, count); }
public void ChangeSource(IBoolStateObserver newSource) { if (newSource == _currentSource) { return; } var oldValue = Value; _events.Void(); _currentSource = newSource; var newValue = Value; if (oldValue != newValue) { _onChange.Trigger(newValue); if (newValue) { _onTrueState.Trigger(); } else { _onFalseState.Trigger(); } } if (_currentSource != null) { _currentSource.OnChange.Register(_events.Validated <bool>(_onChange)); _currentSource.OnTrueState.Register(_events.Validated(_onTrueState)); _currentSource.OnFalseState.Register(_events.Validated(_onFalseState)); } }
public void DeadListenerRemoved() { var slot = new EventSlot(); bool called = false; bool dead = true; IEventListener listener = new DelegateEventListener(() => called = true, () => dead); slot.Register(listener); slot.Trigger(); dead = false; slot.Trigger(); Assert.That(!called); }
public void Add(K key, T value) { List <T> list; if (!_dictionary.TryGetValue(key, out list)) { list = new List <T>(); _dictionary.Add(key, list); GetEventDrivenContainsEditor(key).SetTrue(); } list.Add(value); GetEventDrivenCountEditor(key).Setter(list.Count); _onElementAdded.Trigger(value); _onChange.Trigger(); }
public void Update() { if (!_valid) { return; } var angle = CalculateAngle(); var distance = CalculateDistance(); if (_lastAngle != angle) { _angleChange = angle - _lastAngle; if (_angleChange > Mathf.PI) { _angleChange = _angleChange - 2 * Mathf.PI; } if (_angleChange < -Mathf.PI) { _angleChange = _angleChange + 2 * Mathf.PI; } _lastAngle = angle; // _onPinchAngleChanged.Trigger( angle ); } if (_lastDistance != distance) { _distanceChange = distance - _lastDistance; _lastDistance = distance; // _onPinchDistanceChanged.Trigger( _distanceChange ); } _onPinch.Trigger(this); }
internal void AddPoint(Vector2 point) { if (point != LastPoint) { _points.Add(new TimedPosition(point)); _onDrag.Trigger(this); } }
public void TryDestroy() { if (_valid) { _valid = false; _onPinchComplete.Trigger(this); } }
void TriggerRemoveEvents(T t) { _onElementRemoved.Trigger(t); if (t != null) { _onNotNullElementRemoved.Trigger(t); } _onChange.Trigger(); }
public void Setter(T value) { if (_value.Equals(value)) { return; } _value = value; _onChange.Trigger(value); }
public void Setter(Vector3 value) { if (Mathf.Approximately(_value.x, value.x) && Mathf.Approximately(_value.y, value.y) && Mathf.Approximately(_value.z, value.z)) { return; } _value = value; _onChange.Trigger(value); }
public void Setter(Quaternion value) { if (_value == value) { return; } _value = value; _onChange.Trigger(value); }
public void Setter(float value) { if (Mathf.Approximately(_value, value)) { return; } _value = value; _onChange.Trigger(value); }
public void Setter(byte value) { if (_value == value) { return; } _value = value; _onChange.Trigger(value); }
public void Setter(double value) { if (_value - value < double.Epsilon) { return; } _value = value; _onChange.Trigger(value); }
public void CompleteWarning(float seconds) { if (_isWarned) { return; } _isWarned = true; _warning.Trigger(seconds); }
public void ForceComplete() { if (_isComplete) { return; } _isComplete = true; _completion.Trigger(); }
public void Setter(Guid value) { if (_value.Value == value) { return; } _value.SetGuid(value); _isEmpty.Setter(value == Guid.Empty); _onChange.Trigger(value); }
public void Void() { if (!_isValid) { return; } _isValid = false; _onFalseState.Trigger(); _onChange.Trigger(false); }
private void OnValueChange(bool value) { if (value) { _onTrueState.Trigger(); } else { _onFalseState.Trigger(); } }
public void Lock(string lockName, object activator) { List <object> acts; if (!_activators.TryGetValue(lockName, out acts)) { acts = new List <object>(); _activators[lockName] = acts; } if (!acts.Contains(activator)) { if (acts.Count == 0) { _changeStateEvent.Trigger(lockName, true); } acts.Add(activator); } }
public void EventCallOrder() { var slot = new EventSlot(); List <int> ints = new List <int>(); slot.Register(() => ints.Add(0)); slot.Register(() => ints.Add(1)); slot.Trigger(); Assert.That(ints[0].Equals(0) && ints[1].Equals(1)); }