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.
        }
Esempio n. 2
0
    public void Spawn()
    {
        GOPool    p = GOPool.Create(2).Fill();
        Transform t;

        p.Spawn(out t);
        Assert.AreEqual(p.numActives, 1);
    }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
    public void PoolSize()
    {
        Transform parent = new GameObject("Parent").transform;

        GOPool.Create(5)
        .Parent(parent)
        .Fill();

        Assert.AreEqual(parent.childCount, 5);
    }
Esempio n. 5
0
    public void FillResourcesPath()
    {
        GOPool p = GOPool.Create(2)
                   .Fill("Cube");

        Transform t;

        p.Spawn(out t);
        Assert.AreEqual(t.name, "Cube_0");
    }
Esempio n. 6
0
    public void Spawn()
    {
        GOPool <CubeBehaviour> p = GOPool <CubeBehaviour>
                                   .Create(2)
                                   .Fill();

        CubeBehaviour cb;

        p.Spawn(out cb);
        Assert.AreEqual(p.numActives, 1);
    }
Esempio n. 7
0
    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);
    }
Esempio n. 8
0
    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);
    }
Esempio n. 9
0
    public void DefaultFill()
    {
        CubeBehaviour cb;

        GOPool <CubeBehaviour>
        .Create(2)
        .Fill()
        .Spawn(out cb);

        Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour));
    }
Esempio n. 10
0
    public void FillResourcesPath()
    {
        CubeBehaviour cb;

        GOPool <CubeBehaviour>
        .Create(2)
        .Fill("Cube")
        .Spawn(out cb);

        Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour));
    }
Esempio n. 11
0
    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);
    }
Esempio n. 12
0
    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));
    }
Esempio n. 13
0
    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());
    }
Esempio n. 14
0
    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);
    }
Esempio n. 15
0
    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));
    }
Esempio n. 16
0
    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);
    }
Esempio n. 17
0
    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));
    }
Esempio n. 18
0
    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");
    }
Esempio n. 19
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);
    }
Esempio n. 20
0
    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);
    }
Esempio n. 21
0
    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);
    }