Beispiel #1
0
 public OilBuilder(CommonAssets commonData)
 {
     _firstPool   = new GOPool();
     _transitPool = new GOPool();
     _endPosY     = commonData.OilEnd.transform.position.y;
     _endPool     = new GOPool(commonData.OilEnd);
 }
        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.
        }
Beispiel #3
0
 protected override void OnCreatedView()
 {
     base.OnCreatedView();
     GOPool = new GOPool(Prefab, DataBar);
     LoggerMgr.Callback_OnAddedLog  += OnAddedLog;
     LoggerMgr.Callback_OnRemoveLog += OnRemoveLog;
 }
Beispiel #4
0
    public void Spawn()
    {
        GOPool    p = GOPool.Create(2).Fill();
        Transform t;

        p.Spawn(out t);
        Assert.AreEqual(p.numActives, 1);
    }
Beispiel #5
0
 public CopterBuilder()
 {
     _copterPool            = new GOPool();
     _missilePool           = new GOPool();
     _copterQueue           = new Queue <GameObject>();
     Copter.MissilePool     = _missilePool;
     HomingMissile.SelfPool = _missilePool;
 }
Beispiel #6
0
        private GOPool BuildPoolOfSingleType(GameObject type, int size)
        {
            GameObject[] singleType = new GameObject[1];
            singleType[0] = type;
            GOPool goPool = BuildPool(singleType, size);

            return(goPool);
        }
Beispiel #7
0
        private GOPool BuildPool(GameObject[] prefabs, int poolsize)
        {
            gameObject = Object.Instantiate(new GameObject());
            GOPool goPool = gameObject.AddComponent <GOPool>();

            goPool.types    = prefabs;
            goPool.poolSize = poolsize;
            return(goPool);
        }
Beispiel #8
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));
 }
Beispiel #9
0
    public void PoolSize()
    {
        Transform parent = new GameObject("Parent").transform;

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

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

        Transform t;

        p.Spawn(out t);
        Assert.AreEqual(t.name, "Cube_0");
    }
Beispiel #11
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);
    }
Beispiel #12
0
    public void FillResourcesPath()
    {
        CubeBehaviour cb;

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

        Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour));
    }
Beispiel #13
0
        public IEnumerator SingleTypeMultipleObjects()
        {
            GOPool goPool = BuildPoolOfSingleType(new GameObject(), 1);

            yield return(null);

            GameObject fromPool = goPool.PopDeactivatedObjectOrReturnNull();

            Assert.IsNotNull(fromPool);
            yield return(null);
        }
Beispiel #14
0
    public void DefaultFill()
    {
        CubeBehaviour cb;

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

        Assert.AreEqual(cb.GetType(), typeof(CubeBehaviour));
    }
Beispiel #15
0
    public void Spawn()
    {
        GOPool <CubeBehaviour> p = GOPool <CubeBehaviour>
                                   .Create(2)
                                   .Fill();

        CubeBehaviour cb;

        p.Spawn(out cb);
        Assert.AreEqual(p.numActives, 1);
    }
Beispiel #16
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);
    }
Beispiel #17
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);
    }
Beispiel #18
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());
    }
Beispiel #19
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));
    }
Beispiel #20
0
 protected override void OnCreatedView()
 {
     base.OnCreatedView();
     Title.CancleInit();
     DescPool = new GOPool(Desc.gameObject, CanvasGroup.transform);
     Bg.Init(new BaseImageData {
         OnClick = OnClickBg
     });
     KeyTip.Init(new BaseTextData {
         Name = GetKeyTip, IsTrans = false
     });
     Desc.Show(false);
 }
Beispiel #21
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));
    }
 public VehicleBuilder(CommonAssets commonAssets)
 {
     _commonAssets   = commonAssets;
     _s1Pool         = new GOPool();
     _s2Pool         = new GOPool();
     _s3Pool         = new GOPool();
     _pPool          = new GOPool();
     _mPool          = new GOPool();
     _tPool          = new GOPool();
     _projectilePool = new GOPool();
     ProjectileGun.ProjectilePool = _projectilePool;
     Projectile.SelfPool          = _projectilePool;
 }
Beispiel #23
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));
    }
Beispiel #24
0
 public void Initialize(GOPool pool)
 {
     Pool    = pool;
     Type    = prefab.GetComponent <IBasePoolObject>();
     objects = new List <GameObject>();
     for (var i = 0; i < cacheSize; i++)
     {
         objects.Add(Pool.InstantiateGameObject(prefab, new Vector3(), Quaternion.identity));
         objects[i].SetActive(false);
         objects[i].name             = objects[i].name + i;
         objects[i].transform.parent = Pool.transform;
     }
 }
Beispiel #25
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);
    }
Beispiel #26
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);
    }
Beispiel #27
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);
    }
Beispiel #28
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");
    }
Beispiel #29
0
    protected virtual void Awake()
    {
        Pool = this;
        int amount = 0;

        for (var i = 0; i < caches.Count; i++)
        {
            caches[i].Initialize(this);
            amount += caches[i].cacheSize;
        }
        activeCachedObjects = new Hashtable();
        //   Debug.LogError(gameObject.name);
        this.Inject();
    }
Beispiel #30
0
        public IEnumerator SingleTypeMultipleSingleObjects()
        {
            const int poolSize = 10;
            GOPool    goPool   = BuildPoolOfSingleType(new GameObject(), 10);

            yield return(null);

            for (int i = 0; i < poolSize; i++)
            {
                GameObject fromPool = goPool.PopDeactivatedObjectOrReturnNull();
                Assert.IsNotNull(fromPool, "Expected not null @ " + i);
                fromPool.SetActive(true);
            }

            yield return(null);
        }