示例#1
0
    public void Trigger_Spawn()
    {
        if (spawnMode == SpawnMode.Auto)
        {
            return;
        }

        if (items.Count >= limit)
        {
            switch (limitedMode)
            {
            case LimitedMode.DeleteFirst:
                SetOnDelete?.Invoke(items[0]);
                items.RemoveAt(0);
                numberOfClone = items.Count;
                break;

            case LimitedMode.StopSpawn:
                while (items.Count >= limit)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i] == null)
                        {
                            items.RemoveAt(i);
                        }
                    }
                    return;
                }
                break;
            }
        }
        GameObject gene = Instantiate(what);

        if (positionMode == PositionMode.WhatObject)
        {
            gene.transform.SetParentWithoutChangeScale(null, what.transform.position);
        }
        else
        {
            gene.transform.SetParentWithoutChangeScale(null, transform.position);
        }
        gene.SetActive(true);
        try { SetOnInit?.Invoke(gene); } catch { }
        items.Add(gene);
        numberOfClone = items.Count;
    }
示例#2
0
    IEnumerator running()
    {
        while (true)
        {
            if (items.Count >= limit)
            {
                switch (limitedMode)
                {
                case LimitedMode.DeleteFirst:
                    SetOnDelete?.Invoke(items[0]);
                    items.RemoveAt(0);
                    numberOfClone = items.Count;
                    break;

                case LimitedMode.StopSpawn:
                    while (items.Count >= limit)
                    {
                        for (int i = 0; i < items.Count; i++)
                        {
                            if (items[i] == null)
                            {
                                items.RemoveAt(i);
                            }
                        }
                        yield return(0);
                    }
                    break;
                }
            }
            GameObject gene = Instantiate(what);
            if (positionMode == PositionMode.WhatObject)
            {
                gene.transform.SetParentWithoutChangeScale(null, what.transform.position);
            }
            else
            {
                gene.transform.SetParentWithoutChangeScale(null, transform.position);
            }
            gene.SetActive(true);
            try { SetOnInit?.Invoke(gene); } catch { }
            items.Add(gene);
            numberOfClone = items.Count;
            yield return(new WaitForSeconds(delayTimeSpawn + Random.Range(0, randomDelayDelta)));
        }
    }