Esempio n. 1
0
    public void 사용예시()
    {
        SimplePoolTarget.Reset_InstanceCount();
        int totalInstanceCount             = 10;
        SimplePool <SimplePoolTarget> pool = new SimplePool <SimplePoolTarget>(new SimplePoolTarget(), totalInstanceCount);
        int loopCount = Random.Range(3, 10);

        for (int i = 0; i < loopCount; i++)
        {
            int spawnCount = Random.Range(2, totalInstanceCount);
            HashSet <SimplePoolTarget> set = new HashSet <SimplePoolTarget>();
            for (int j = 0; j < spawnCount; j++)
            {
                set.Add(pool.Spawn());
            }

            foreach (var item in set)
            {
                pool.DeSpawn(item);
            }
        }

        Assert.AreEqual(pool.AllInstance.Count, totalInstanceCount);
        Assert.AreEqual(pool.Use.Count, 0);
        Assert.AreEqual(pool.NotUse.Count, totalInstanceCount);
    }
Esempio n. 2
0
    static int DeSpawn(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        SimplePool obj  = LuaScriptMgr.GetUnityObject <SimplePool>(L, 1);
        GameObject arg0 = LuaScriptMgr.GetUnityObject <GameObject>(L, 2);

        obj.DeSpawn(arg0);
        return(0);
    }
Esempio n. 3
0
    public void PlaceBomb(PlayerControl player)
    {
        //The player does not have enough bomb
        if (player.currentBomb <= 0)
        {
            return;
        }

        int mapIndex = GetMapIndex(player.currentPos.x, player.currentPos.y);

        if (!CheckObstacle(mapIndex))
        {
            //Get the bomb
            GameObject newBomb  = bombPool.Spawn(bombPool.transform, map[mapIndex].position, Quaternion.identity);
            Bomb       bombStat = newBomb.GetComponent <Bomb>();
            bombStat.isActive   = true;
            bombStat.cooldown   = Const.BOMB_COOLDOWN;
            bombStat.lenght     = player.power;
            bombStat.currentPos = player.currentPos;
            player.PlaceBomb(-1);

            lock (_lock)
                map[mapIndex].obstacle = bombStat;

            bombStat.onBombCD         = null;
            bombStat.onBombCD         = StartCoroutine(bombStat.TriggerCountdown());
            bombStat.OnCooldownEnded += () =>
            {
                bombStat.isActive = false;
                player.PlaceBomb(1);
                if (bombStat.onBombCD != null)
                {
                    StopCoroutine(bombStat.onBombCD);
                }
                bombStat.onBombCD = null;
                ExploseBombEffect(bombStat);

                lock (_lock)
                    map[mapIndex].obstacle = null;

                bombPool.DeSpawn(newBomb);
            };
        }
    }
Esempio n. 4
0
    //Create a fire object
    void InitFireObject(int mapIndex)
    {
        GameObject newFire  = firePool.Spawn(firePool.transform, map[mapIndex].position, Quaternion.identity);
        Fire       fireStat = newFire.GetComponent <Fire>();

        fireStat.cooldown = Const.FIRE_COOLDOWN;

        lock (_lock)
            map[mapIndex].obstacle = fireStat;

        StartCoroutine(fireStat.OnFire());
        fireStat.OnCooldownEnded += () =>
        {
            fireStat.isActive = false;
            lock (_lock)
                map[mapIndex].obstacle = null;
            firePool.DeSpawn(newFire);
        };
    }