public void SubscribeAndAddTwoThenDisposeAllAndComplete() { Queue <TaskCompletionSource <bool> > pending = new Queue <TaskCompletionSource <bool> >(); BatchedEvents <string> events = new BatchedEvents <string>(() => pending.Dequeue().Task); List <string> batches = new List <string>(); TaskCompletionSource <bool> pending1 = new TaskCompletionSource <bool>(); TaskCompletionSource <bool> pending2 = new TaskCompletionSource <bool>(); pending.Enqueue(pending1); pending.Enqueue(pending2); IDisposable sub1 = events.Subscribe("item1", i => batches.Add("A:" + i)); events.Subscribe("item2", i => batches.Add("B:" + i)); events.Add("item1", new TimePoint(1)); events.Add("item2", new TimePoint(1)); batches.Should().BeEmpty(); events.Dispose(); pending1.SetResult(true); batches.Should().BeEmpty(); pending2.SetResult(true); batches.Should().BeEmpty(); }
public void AddTwoDifferentBatches() { Queue <TaskCompletionSource <bool> > pending = new Queue <TaskCompletionSource <bool> >(); BatchedEvents <string> events = new BatchedEvents <string>(() => pending.Dequeue().Task); List <string> batches = new List <string>(); TaskCompletionSource <bool> pending1 = new TaskCompletionSource <bool>(); TaskCompletionSource <bool> pending2 = new TaskCompletionSource <bool>(); pending.Enqueue(pending1); pending.Enqueue(pending2); events.Subscribe("item1", i => batches.Add("A:" + i)); events.Subscribe("item2", i => batches.Add("B:" + i)); events.Add("item1", new TimePoint(1)); events.Add("item2", new TimePoint(1)); batches.Should().BeEmpty(); pending1.SetResult(true); batches.Should().ContainSingle().Which.Should().Be("A:item1"); batches.Clear(); pending2.SetResult(true); batches.Should().ContainSingle().Which.Should().Be("B:item2"); }
public void AddBeforeSubscribe() { BatchedEvents <string> events = new BatchedEvents <string>(() => Task.CompletedTask); Action act = () => events.Add("item1", new TimePoint(1)); act.Should().NotThrow(); }
void OnDisable() { BatchedEvents.Remove(this); if (RTSManager.instance != null) { RTSManager.instance.units.RemoveUnit(this); } }
public void DisposeAfterCreate() { BatchedEvents <string> events = new BatchedEvents <string>(() => Task.CompletedTask); Action act = () => events.Dispose(); act.Should().NotThrow(); }
public void SubscribeAndDispose() { BatchedEvents <string> events = new BatchedEvents <string>(() => Task.CompletedTask); IDisposable sub = events.Subscribe("item1", i => { }); Action act = () => sub.Dispose(); act.Should().NotThrow(); }
public void SubscribeThenAddAndDispose() { TaskCompletionSource <bool> pending = new TaskCompletionSource <bool>(); BatchedEvents <string> events = new BatchedEvents <string>(() => pending.Task); IDisposable sub = events.Subscribe("item1", i => { }); events.Add("item1", new TimePoint(1)); Action act = () => sub.Dispose(); act.Should().NotThrow(); }
/// <summary>Called when the component is enabled</summary> protected virtual void OnEnable() { FindComponents(); // Make sure we receive callbacks when paths are calculated seeker.pathCallback += OnPathComplete; Init(); // When using rigidbodies all movement is done inside FixedUpdate instead of Update bool fixedUpdate = rigid != null || rigid2D != null; BatchedEvents.Add(this, fixedUpdate ? BatchedEvents.Event.FixedUpdate : BatchedEvents.Event.Update, OnUpdate); }
protected virtual void OnDisable() { BatchedEvents.Remove(this); ClearPath(); // Make sure we no longer receive callbacks when paths complete seeker.pathCallback -= OnPathComplete; velocity2D = Vector3.zero; accumulatedMovementDelta = Vector3.zero; verticalVelocity = 0f; lastDeltaTime = 0; }
public void AddOneAndComplete() { TaskCompletionSource <bool> pending = new TaskCompletionSource <bool>(); BatchedEvents <string> events = new BatchedEvents <string>(() => pending.Task); List <string> batches = new List <string>(); events.Subscribe("item1", i => batches.Add(i)); events.Add("item1", new TimePoint(1)); batches.Should().BeEmpty(); pending.SetResult(true); batches.Should().ContainSingle().Which.Should().Be("item1"); }
void OnEnable() { if (OnUpdateDelegate == null) { OnUpdateDelegate = OnUpdate; } RTSManager.instance.units.AddUnit(this); selected = false; health = maxHealth; movementMode = MovementMode.AttackMove; reachedDestination = true; if (ai != null) { lastDestination = ai.destination; } BatchedEvents.Add(this, BatchedEvents.Event.Update, OnUpdateDelegate); }