Esempio n. 1
0
    protected void Update()
    {
        if (spawnQueue.Count > 0 || objectToSpawn != null)
        {
            if (objectToSpawn == null)
            {
                currentSpawnQueueItem = spawnQueue.Dequeue();
                objectToSpawn         = currentSpawnQueueItem.thingToSpawn;
                UICoolDownImage       = currentSpawnQueueItem.UICooldownImage;
                hasPlayedAudio        = false;
                UICoolDownImage.color = new Color(1, 0, 0, (float)122 / 255);
                queueLength           = currentSpawnQueueItem.queueLength;
                currentSpawnQueueItem.Dequeue();
            }
            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);

                    currentSpawnQueueItem.TutorialInputManager2.buildings.Add(currentSpawnQueueItem.thingToSpawn.name);

                    tmp.Activate();
                    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. 2
0
    public void Cancel()
    {
        if (spawnComponent.currentSpawnQueueItem == this)
        {
            gameManager.UpdateMinerals(thingToSpawn.cost);
            CompleteQueueItem();
        }
        else
        {
            if (spawnComponent.spawnQueue.Contains(this))
            {
                //spawnComponent.spawnQueue.
                Queue <SpawnQueueItemTutorial> tmpqueue = new Queue <SpawnQueueItemTutorial>();

                bool hasCanceledOnce = false;
                while (spawnComponent.spawnQueue.Count > 0)
                {
                    SpawnQueueItemTutorial 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. 3
0
 public void ContinueQueue()
 {
     spawntimerCurr        = 0;
     objectToSpawn         = null;
     currentSpawnQueueItem = null;
 }
Esempio n. 4
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>();

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

            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);
        }
    }