コード例 #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;
        }
    }