public void group_dispatches_OnEntityRemoved_and_OnEntityAdded_when_replacing_components() { var g = pool.GetGroup(matcherAB); var didR = 0; var didA = 0; var compP = eAB1.Get(typeof(TestComponentA)); var compA = new TestComponentA(); g.OnEntityRemoved += (grp, entity, type, comp) => { Assert.AreSame(g, grp); Assert.AreSame(entity, eAB1); Assert.AreEqual(typeof(TestComponentA), type); Assert.AreSame(comp, compP); didR += 1; }; g.OnEntityAdded += (grp, entity, type, comp) => { Assert.AreSame(g, grp); Assert.AreSame(entity, eAB1); Assert.AreEqual(typeof(TestComponentA), type); Assert.AreSame(comp, compA); didA += 1; }; eAB1.ReplaceInstance(compA); Assert.AreEqual(1, didA); Assert.AreEqual(1, didR); }
public void Setup() { refA = new TestComponentA(); refB = new TestComponentB(); refC = new TestComponentC(); pool = new Pool <ITestPool>(refA, refB, refC); entity = pool.CreateEntity(); }
public void group_dispatch_OnEntityUpdated_with_previous_and_current_components() { var update = 0; var prev = eAB1.Get <TestComponentA>(); var next = new TestComponentA(); var g = pool.GetGroup(matcherAB); g.OnEntityUpdated += (grp, e, type, p, n) => { Assert.AreSame(g, grp); Assert.AreSame(e, eAB1); Assert.AreEqual(typeof(TestComponentA), type); Assert.AreSame(p, prev); Assert.AreSame(n, next); update += 1; }; eAB1.ReplaceInstance(next); Assert.AreEqual(1, update); }
public void dispatches_OnComponentReplaced_when_replacing_a_component() { entity.Add <TestComponentA>(); var newA = new TestComponentA(); entity.OnComponentReplaced += (e, type, prev, next) => { did += 1; Assert.AreSame(e, entity); Assert.AreEqual(typeof(TestComponentA), type); Assert.AreSame(refA, prev); Assert.AreNotSame(refA, next); Assert.AreNotSame(refA, next); }; entity.OnComponentAdded += delegate { Assert.Fail(); }; entity.OnComponentRemoved += delegate { Assert.Fail(); }; entity.ReplaceInstance(newA); Assert.AreEqual(did, 1); }
protected void AssertHasComponentA(Entity <ITestPool> e, TestComponentA comp = null) { if (comp == null) { comp = refA; } var ea = e.Get <TestComponentA>(); Assert.AreSame(ea, comp); var components = e.GetComponents(); Assert.AreEqual(1, components.Length); Assert.Contains(comp, components); var types = e.GetComponentsTypes(); Assert.AreEqual(1, types.Length); Assert.Contains(typeof(TestComponentA), types); Assert.IsTrue(e.Has <TestComponentA>()); Assert.IsTrue(e.Has(typeof(TestComponentA))); Assert.IsTrue(e.HasAny(typeof(TestComponentA))); }