コード例 #1
1
    public void Spawn(ESpaceObjects e, int count, Vector2 start, Vector2 end)
    {
        if (count < 1) return;

        Debug.Log(string.Format("Spawn {0} {1}", count, e.ToString()));

        var cahce = _cache[(int)e];
        for (int i = 0; i < count; i++)
        {
            var so = cahce.Pop();
            so.OnDestroy += _destroyDelegates[(int)e];
            so.OnReward += OnReward;

            so.transform.position = new Vector2(Random.Range(start.x, end.x), Random.Range(start.y, end.y));
            so.Spawn();

            if (e == ESpaceObjects.AlienBig || e == ESpaceObjects.AlienShield || e == ESpaceObjects.AlienSmall)
            {
                Alien alien = so as Alien;
                alien.Spawner = this;
            }

            LiveObjects.Add(so);
        }
    }
コード例 #2
0
    public void Spawn(ESpaceObjects e, int count, Vector2 start, Vector2 end)
    {
        if (count < 1)
        {
            return;
        }

        Debug.Log(string.Format("Spawn {0} {1}", count, e.ToString()));

        var cahce = _cache[(int)e];

        for (int i = 0; i < count; i++)
        {
            var so = cahce.Pop();
            so.OnDestroy += _destroyDelegates[(int)e];
            so.OnReward  += OnReward;

            so.transform.position = new Vector2(Random.Range(start.x, end.x), Random.Range(start.y, end.y));
            so.Spawn();

            if (e == ESpaceObjects.AlienBig || e == ESpaceObjects.AlienShield || e == ESpaceObjects.AlienSmall)
            {
                Alien alien = so as Alien;
                alien.Spawner = this;
            }

            LiveObjects.Add(so);
        }
    }
コード例 #3
0
    public void Spawn(ESpaceObjects e, int count, Vector2 start, Vector2 end, List <RelativeSpaceObject> list)
    {
        if (count < 1)
        {
            return;
        }

        Debug.Log(string.Format("Spawn {0} {1}", count, e.ToString()));

        var cahce = _cache[(int)e];

        for (int i = 0; i < count; i++)
        {
            var so = cahce.Pop();

            System.Action <RelativeSpaceObject> destroyDelegate = null;
            destroyDelegate = (x) =>
            {
                cahce.Push(x);
                list.Remove(x);
                Debug.Log(destroyDelegate);
                x.OnDestroy -= destroyDelegate;
                x.OnReward  -= OnReward;
            };

            so.OnDestroy += destroyDelegate;
            so.OnReward  += OnReward;


            so.transform.position = new Vector2(Random.Range(start.x, end.x), Random.Range(start.y, end.y));
            so.Spawn();

            if (e == ESpaceObjects.AlienBig || e == ESpaceObjects.AlienShield || e == ESpaceObjects.AlienSmall)
            {
                Alien alien = so as Alien;
                alien.Spawner = this;
            }

            list.Add(so);
        }
    }
コード例 #4
0
    public void Spawn(ESpaceObjects e, int count, Vector2 start, Vector2 end, List<RelativeSpaceObject> list)
    {
        if (count < 1) return;

        Debug.Log(string.Format("Spawn {0} {1}", count, e.ToString()));

        var cahce = _cache[(int)e];
        for (int i = 0; i < count; i++)
        {
            var so = cahce.Pop();

            System.Action<RelativeSpaceObject> destroyDelegate = null;
            destroyDelegate = (x) =>
            {
                cahce.Push(x);
                list.Remove(x);
                Debug.Log(destroyDelegate);
                x.OnDestroy -= destroyDelegate;
                x.OnReward -= OnReward;
            };

            so.OnDestroy += destroyDelegate;
            so.OnReward += OnReward;

            so.transform.position = new Vector2(Random.Range(start.x, end.x), Random.Range(start.y, end.y));
            so.Spawn();

            if (e == ESpaceObjects.AlienBig || e == ESpaceObjects.AlienShield || e == ESpaceObjects.AlienSmall)
            {
                Alien alien = so as Alien;
                alien.Spawner = this;
            }

            list.Add(so);
        }
    }