void Awake() { stonePool = GOPool.Create(25) .Grow(true) .Parent(GO.Create("StonePool")) .Fill(prefabStone.gameObject); splashPool = GOPool.Create(50) .Grow(true) .Parent(GO.Create("SplashPool")) .Fill(prefabSplash.gameObject) .SetOnSpawn(splash => { splash.GetComponent <SkippingSplash>() .onAnimDone.AddListener(OnSplashAnimDone); }); anims = ObjectPool <StoneSkipAnim> .Create(20) .Grow(false) .Fill(i => { return(new StoneSkipAnim { skipCoords = new Vector3[numSkipsPerThrow], splashes = new SkippingSplash[numSkipsPerThrow] }); }) .SetOnDespawn(OnDespawnAnim); playTimes = new float[numSkipsPerThrow]; // Calculate duration time per frame CalcPlayTimes(numSkipsPerThrow, ref playTimes); // get child objects from throwingStones. Pool them and refill // with as many as there are child objects. }
public void Spawn() { GOPool p = GOPool.Create(2).Fill(); Transform t; p.Spawn(out t); Assert.AreEqual(p.numActives, 1); }
public static GOPool Pool(this GO go, int num) { return(GOPool.Create(num) .Fill(i => go.Duplicate().Modify() // set active .SetName(go.GameObject.name + "_" + i) .SetParent(go.Transform.parent) .Transform)); }
public void PoolSize() { Transform parent = new GameObject("Parent").transform; GOPool.Create(5) .Parent(parent) .Fill(); Assert.AreEqual(parent.childCount, 5); }
public void FillResourcesPath() { GOPool p = GOPool.Create(2) .Fill("Cube"); Transform t; p.Spawn(out t); Assert.AreEqual(t.name, "Cube_0"); }
public void Spawn() { GOPool <CubeBehaviour> p = GOPool <CubeBehaviour> .Create(2) .Fill(); CubeBehaviour cb; p.Spawn(out cb); Assert.AreEqual(p.numActives, 1); }
public void LimitGrow() { GOPool <CubeBehaviour> p = GOPool <CubeBehaviour> .Create(1).Fill(); CubeBehaviour cb1; CubeBehaviour cb2; int s = p.Spawn(out cb1) ? 1 : 0; s += p.Spawn(out cb2) ? 1 : 0; Assert.AreEqual(s, 1); }
public void Despawn() { CubeBehaviour cb; GOPool <CubeBehaviour> p = GOPool <CubeBehaviour> .Create(2) .Fill(); p.Spawn(out cb); p.Despawn(cb); Assert.AreEqual(p.numActives, 0); }
public void DefaultFill() { CubeBehaviour cb; GOPool <CubeBehaviour> .Create(2) .Fill() .Spawn(out cb); Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour)); }
public void FillResourcesPath() { CubeBehaviour cb; GOPool <CubeBehaviour> .Create(2) .Fill("Cube") .Spawn(out cb); Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour)); }
public void LimitGrow() { GOPool p = GOPool.Create(1).Fill(); Transform t1; Transform t2; int s = p.Spawn(out t1) ? 1 : 0; s += p.Spawn(out t2) ? 1 : 0; Assert.AreEqual(s, 1); }
public void FillResourcesLoad() { GameObject go = Resources.Load <GameObject>("Cube"); CubeBehaviour cb; GOPool <CubeBehaviour> .Create(2) .Fill(go) .Spawn(out cb); Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour)); }
public void FillResourcesLoad() { GameObject go = Resources.Load <GameObject>("Cube"); GOPool p = GOPool.Create(2) .Fill(go); Transform t; p.Spawn(out t); Assert.AreEqual(go.GetComponent <CubeBehaviour>().GetType(), t.GetComponent <CubeBehaviour>().GetType()); }
void Start() { GOPool p = GOPool.Create(2) .SetOnSpawn(t => { t.transform.position = Vector3.right; t.gameObject.SetActive(false); }) .Fill("Cube"); Transform i; p.Spawn(out i); }
public void FillReference() { GameObject prefab = Resources.Load <GameObject>("Cube"); GameObject go = GameObject.Instantiate(prefab); CubeBehaviour cb; GOPool <CubeBehaviour> .Create(2) .Fill(go) .Spawn(out cb); Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour)); }
public void SetParent() { Transform parent = new GameObject("Parent").transform; GOPool p = GOPool.Create(2) .Parent(parent) .Fill(); Transform t; p.Spawn(out t); Assert.AreEqual(t.parent, parent); }
public void FillLambda() { CubeBehaviour cb; GOPool <CubeBehaviour> .Create(2) .Fill(i => { return(new GameObject().AddComponent <CubeBehaviour>()); }) .Spawn(out cb); Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour)); }
public void FillLambda() { GOPool p = GOPool.Create(2) .Fill(i => { GameObject go = new GameObject("GO"); go.name += "_" + i; return(go.transform); }); Transform t; p.Spawn(out t); Assert.AreEqual(t.name, "GO_0"); }
public void SetParent() { Transform parent = new GameObject("Parent").transform; GOPool <CubeBehaviour> p = GOPool <CubeBehaviour> .Create(2) .Parent(parent) .Fill(); CubeBehaviour cb; p.Spawn(out cb); Assert.AreEqual(cb.transform.parent, parent); }
public void SetOnSpawn() { GOPool p = GOPool.Create(2) .SetOnSpawn(t => { t.transform.position = Vector3.right; // GOPool activates the object after the lambda has // run. This should be reverted after Spawn() has run. t.gameObject.SetActive(false); }) .Fill("Cube"); Transform i; p.Spawn(out i); Assert.AreEqual(i.position, Vector3.right); Assert.AreEqual(i.gameObject.activeSelf, true); }
public void SetOnDespawn() { GOPool <CubeBehaviour> p = GOPool <CubeBehaviour> .Create(2) .SetOnDespawn(t => { t.transform.position = -Vector3.right; // GOPool deactivates the object after the lambda has // run. This should be reverted after Spawn() has run. t.gameObject.SetActive(true); }) .Fill("Cube"); CubeBehaviour i; p.Spawn(out i); p.Despawn(i); Assert.AreEqual(i.transform.position, -Vector3.right); Assert.AreEqual(i.gameObject.activeSelf, false); }