Esempio n. 1
0
    private void SpawnEnemy(SpawnQueueItem item, SpawnPoint inSpawnPoint)
    {
        GameObject go = (GameObject)Instantiate(item.objectToSpawn, inSpawnPoint.placementCollider.center + RandomPointInCollider(inSpawnPoint.placementCollider), Quaternion.identity, enemySpawnParent.transform);

        spawnedThisRound.Add(go);
        item.amountLeftToSpawn -= 1;
        item.currentAlive      += 1;
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        //Actually do our spawning.
        if (toSpawn.Count > 0)
        {
            if (Time.time > nextSpawnTime)
            {
                SpawnQueueItem item = SelectRandomFromSpawnQueue();
                if (item != null)
                {
                    SpawnEnemy(item, ChooseSpawnPoint());
                    if (item.amountLeftToSpawn == 0)
                    {
                        toSpawn.Remove(item);
                    }
                    nextSpawnTime = Time.time + activeRoundSettings.averageSpawnInterval + UnityEngine.Random.Range(-activeRoundSettings.acceptedDeviation, activeRoundSettings.acceptedDeviation);
                }
            }

            //Select a random enemy from our spawn queue
        }
    }
Esempio n. 3
0
    public void Cancel()
    {
        if (spawnComponent.currentSpawnQueueItem == this)
        {
            gameManager.UpdateMinerals(thingToSpawn.cost);
            CompleteQueueItem();
        }
        else
        {
            if (spawnComponent.spawnQueue.Contains(this))
            {
                //spawnComponent.spawnQueue.
                Queue <SpawnQueueItem> tmpqueue = new Queue <SpawnQueueItem>();

                bool hasCanceledOnce = false;
                while (spawnComponent.spawnQueue.Count > 0)
                {
                    SpawnQueueItem spawnQueueItem = spawnComponent.spawnQueue.Dequeue();
                    if (spawnQueueItem == this && !hasCanceledOnce)
                    {
                        hasCanceledOnce = true;
                        spawnQueueItem.nrOfQueue--;
                        spawnQueueItem.queueLength.text = "Queue: " + nrOfQueue.ToString();
                        continue;
                    }
                    else
                    {
                        tmpqueue.Enqueue(spawnQueueItem);
                    }
                }

                while (tmpqueue.Count > 0)
                {
                    spawnComponent.spawnQueue.Enqueue(tmpqueue.Dequeue());
                }
            }
        }
    }
Esempio n. 4
0
 public void ContinueQueue()
 {
     spawntimerCurr        = 0;
     objectToSpawn         = null;
     currentSpawnQueueItem = null;
 }
Esempio n. 5
0
    protected void Update()
    {
        if (spawnQueue.Count > 0 || objectToSpawn != null)
        {
            if (objectToSpawn == null)
            {
                currentSpawnQueueItem = spawnQueue.Dequeue();
                objectToSpawn         = currentSpawnQueueItem.thingToSpawn;
                UICoolDownImage       = currentSpawnQueueItem.UICooldownImage;
                UICoolDownImage.color = new Color(1, 0, 0, (float)122 / 255);
                hasPlayedAudio        = false;
                queueLength           = currentSpawnQueueItem.queueLength;
                currentSpawnQueueItem.Dequeue();
                if (FactoryDoor != null)
                {
                    FactoryDoor.TurnOnLights();
                }
            }
            spawntimerCurr += Time.deltaTime;

            if (spawntimerCurr > spawntimerMax)
            {
                spawntimerCurr = spawntimerMax;
                if (!manuallyPlaced)
                {
                    spawntimerCurr = 0;
                    UICoolDownImage.rectTransform.sizeDelta = new Vector2(UICoolDownImage.rectTransform.sizeDelta.x, 0);

                    MyObject tmp = Instantiate(objectToSpawn, spawnPoint.position, Quaternion.identity);
                    tmp.Activate();
                    OnUnitSpawned?.Invoke(tmp);
                    objectToSpawn         = null;
                    currentSpawnQueueItem = null;
                    tmp.team = GetComponent <MyObject>().team;
                    tmp.GetComponent <UnityEngine.AI.NavMeshAgent>().destination = waypointLocation.position;

                    if (FactoryDoor != null)
                    {
                        FactoryDoor.OpenDoor();
                    }
                }
                else
                {
                    if (!hasPlayedAudio)
                    {
                        hasPlayedAudio        = true;
                        UICoolDownImage.color = new Color(0, 1, 0, (float)122 / 255);
                        constructionComplete.Play();
                        //UICoolDownImage.transform.parent.SetAsLastSibling();
                        iTween.PunchScale(UICoolDownImage.transform.parent.gameObject, new Vector3(2f, 2f, 2f), 1f);
                    }
                }
            }

            float spriteSizeFrac = (spawntimerCurr / spawntimerMax);
            UICoolDownImage.rectTransform.sizeDelta = new Vector2(UICoolDownImage.rectTransform.sizeDelta.x, spriteMaxSize * spriteSizeFrac);
        }
        else
        {
            spawntimerCurr = 0;
        }
    }
Esempio n. 6
0
    virtual protected void Start()
    {
        foreach (InfantryUnit iu in UnitPrefabSO)
        {
            GameObject tmpGO = Instantiate(iu.UIGameObjectPrefab, buildingContainer);

            Image imageTmp  = null;
            Text  queueText = null;
            Text  costTxt   = null;

            //Debug.Log(tmpGO.transform.GetChild(1).name);
            for (int i = 0; i < tmpGO.transform.GetChild(1).childCount; i++)
            {
                Transform t = tmpGO.transform.GetChild(1).GetChild(i);

                //if (t.name == "UICooldownImage") {
                //     = t.GetComponent<Image>();
                //}
                if (t.name == "QueueLength")
                {
                    queueText = t.GetComponent <Text>();
                }
                else if (t.name == "MainText")
                {
                    t.GetComponent <Text>().text = iu.MyObject.myName;
                }
                else if (t.name == "CostText")
                {
                    costTxt      = t.GetComponent <Text>();
                    costTxt.text = "Cost: " + iu.MyObject.cost.ToString();
                }
                else if (t.name == "PowerCost")
                {
                    t.GetComponent <Text>().text = "Power: " + (-iu.MyObject.powerReq).ToString();
                }
            }

            imageTmp = tmpGO.transform.GetChild(0).GetComponent <Image>();

            SpawnQueueItem spawnQueue = new SpawnQueueItem(imageTmp, queueText, iu.MyObject, this, costTxt);
            infantryUnitToSpawnQueueItem[iu] = spawnQueue;

            Button tmpButton = tmpGO.GetComponentInChildren <Button>();
            tmpButton.onClick.AddListener(delegate { infantryUnitToSpawnQueueItem[iu].EnqueuePrefab(); });
        }

        ClickableComponent clickableComponent = GetComponent <ClickableComponent>();

        if (clickableComponent != null)
        {
            clickableComponent.OnClick   += ToggleBuildingUI;
            clickableComponent.OnUnClick += DisableBuildingUI;
        }
        else
        {
            Debug.LogWarning("SpawnComponent warning: No clickableComponent found", this);
        }
        SelectableComponent selectableComponent = GetComponent <SelectableComponent>();

        if (selectableComponent != null)
        {
            selectableComponent.OnSelect   += ToggleBuildingUI;
            selectableComponent.OnDeselect += DisableBuildingUI;
        }
        else
        {
            Debug.LogWarning("SpawnComponent warning: No selectableComponent found", this);
        }
    }