Example #1
0
        /// <summary>
        /// Resumes gameplay, and reactivates in-game menu items.
        /// </summary>
        public void Resume()
        {
            isPaused = false;

            if (gameSpeeds.Length > 0)
            {
                Time.timeScale = gameSpeeds[currentSpeed];
            }
            else
            {
                Time.timeScale = 1;
            }

            BuildController bc = GetComponent <BuildController>();
            EnemyDispenser  ed = GetComponent <EnemyDispenser>();
            GameSpeed       gs = GetComponent <GameSpeed>();
            GameMenu        gm = GetComponent <GameMenu>();

            // Enable all other components in this game controller object
            if (bc)
            {
                bc.enabled = true;
            }

            if (ed)
            {
                ed.enabled = true;
            }

            if (gs)
            {
                gs.enabled = true;
            }

            // Disable the in-game menu
            if (gm)
            {
                gm.enabled = false;
            }

            // If we have a game menu canvas for the new UI (4.6+), deactivate it
            if (useOldUI == false)
            {
                if (gameMenuCanvas)
                {
                    gameMenuCanvas.gameObject.SetActive(false);
                }

                if (speedMenuCanvas)
                {
                    speedMenuCanvas.gameObject.SetActive(true);
                }

                if (buildMenuCanvas)
                {
                    buildMenuCanvas.gameObject.SetActive(true);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Pauses gameplay, and deactivates in-game menu items.
        /// </summary>
        public void Pause()
        {
            isPaused = true;

            Time.timeScale = 0;

            BuildController bc = GetComponent <BuildController>();
            EnemyDispenser  ed = GetComponent <EnemyDispenser>();
            GameSpeed       gs = GetComponent <GameSpeed>();
            GameMenu        gm = GetComponent <GameMenu>();

            // Enable all other components in this game controller object
            if (bc)
            {
                bc.enabled = false;
            }

            if (ed)
            {
                ed.enabled = false;
            }

            if (gs)
            {
                gs.enabled = false;
            }

            // If we are using the old UI, activate the OnGUI game menu
            if (gm && useOldUI == true)
            {
                gm.enabled = true;
            }

            // If we have a game menu canvas for the new UI (4.6+), activate it
            if (useOldUI == false)
            {
                if (gameMenuCanvas)
                {
                    gameMenuCanvas.gameObject.SetActive(true);
                }

                if (speedMenuCanvas)
                {
                    speedMenuCanvas.gameObject.SetActive(false);
                }

                if (buildMenuCanvas)
                {
                    buildMenuCanvas.gameObject.SetActive(false);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Start is only called once in the lifetime of the behaviour.
        /// The difference between Awake and Start is that Start is only called if the script instance is enabled.
        /// This allows you to delay any initialization code, until it is really needed.
        /// Awake is always called before any Start functions.
        /// This allows you to order initialization of scripts
        /// </summary>
        public void Start()
        {
            GameSpeed       gs = GetComponent <GameSpeed>();
            BuildController bc = GetComponent <BuildController>();
            EnemyDispenser  ed = GetComponent <EnemyDispenser>();
            GameMenu        gm = GetComponent <GameMenu>();

            // Go through all the resource types the player has and deactivate their new UI (4.6+) icons
            for (int resourceIndex = 0; resourceIndex < bc.moneyTypes.Length; resourceIndex++)
            {
                // Disable the icon of the resource type
                if (bc.moneyTypes[resourceIndex].icon)
                {
                    bc.moneyTypes[resourceIndex].icon.gameObject.SetActive(false);
                }
            }

            // If we are using the old GUI, deactivate the new UI canvas
            if (useOldUI == true && unitSelectionCanvas)
            {
                unitSelectionCanvas.gameObject.SetActive(false);
            }

            // Deactivate the speed menu canvas, because we need to select units for the battle first
            if (gs.speedMenuCanvas)
            {
                gs.speedMenuCanvas.gameObject.SetActive(false);
            }

            // Deactivate the build menu canvas, because we need to select units for the battle first
            if (bc.buildMenuCanvas)
            {
                bc.buildMenuCanvas.gameObject.SetActive(false);
            }

            // Deactivate the enemy canvas, because we need to select units for the battle first
            if (ed.enemyCanvas)
            {
                ed.enemyCanvas.gameObject.SetActive(false);
            }

            // If we are using the old UI, limit the value of Max Units based on the number of slots in the build list ( new UI )
            if (useOldUI == false)
            {
                if (maxUnits > buildListButtons.Length)
                {
                    maxUnits = buildListButtons.Length;
                }

                // Remove any extra slots in the build list
                for (int index = maxUnits; index < buildListButtons.Length; index++)
                {
                    // Make the button of the building in the build list unclickable
                    //buildListButtons[index].GetComponent(Button).interactable = false;

                    // Disable the whole building slot
                    //buildListButtons[index].Find("Icon").gameObject.SetActive(false);

                    //Disable the whole building slot
                    buildListButtons[index].gameObject.SetActive(false);
                }
            }

            // Pause the game
            Time.timeScale = 0;

            // Calculate the size of a single tile within the grid of units
            tileSize = new Vector2(positionAndSize.width / grid.x, positionAndSize.height / grid.y);

            // Disable all other components in this game controller object
            if (bc)
            {
                bc.enabled = false;
            }

            if (ed)
            {
                ed.enabled = false;
            }

            if (gs)
            {
                gs.enabled = false;
            }

            if (gm)
            {
                gm.enabled = false;
            }

            // Set the build list in the BuildController script to be the same length as maxUnits
            bc.buildList = new Transform[maxUnits];

            // Register the build list transform array for easier access
            buildList = bc.buildList;

            // Set the units which are essential to this battle
            SetEssential();

            // Set the icons of the units in the grid
            SetGrid();
        }
Example #4
0
        /// <summary>
        /// Ends the unit selection phase, and starts the game.
        /// </summary>
        public void StartGame()
        {
            // If we have at least one selected unit, start the game
            if (selectedUnits > 0)
            {
                GameSpeed       gs = GetComponent <GameSpeed>();
                BuildController bc = GetComponent <BuildController>();
                EnemyDispenser  ed = GetComponent <EnemyDispenser>();

                // Unpause the game
                Time.timeScale = 1;

                if (GetComponent <AudioSource>())
                {
                    GetComponent <AudioSource>().Play();
                }

                // Enable all other components in this game controller object
                if (bc)
                {
                    bc.enabled = true;
                }

                if (ed)
                {
                    ed.enabled = true;
                }

                if (gs)
                {
                    gs.enabled = true;
                }

                // Assign the correct cooldown for each unit in the list
                bc.GetCooldowns();

                // Deactivate the unit selection canvas
                if (unitSelectionCanvas)
                {
                    unitSelectionCanvas.gameObject.SetActive(false);
                }

                // If we are using the new GUI (4.6+), activate the build menu canvas and set the build list for it
                if (useOldUI == false)
                {
                    // If we have a speed menu canvas assigned, activate it
                    if (gs.speedMenuCanvas)
                    {
                        gs.speedMenuCanvas.gameObject.SetActive(true);
                    }

                    // If we have a build menu canvas assigned, activate it
                    if (bc.buildMenuCanvas)
                    {
                        bc.buildMenuCanvas.gameObject.SetActive(true);
                    }

                    // If we have an enemy canvas assigned, activate it
                    if (ed.enemyCanvas)
                    {
                        ed.enemyCanvas.gameObject.SetActive(true);
                    }

                    // Set the build list icons in the build controller
                    bc.SetBuildList();

                    // If we have a game speed canvas assigned, activate it
                    if (gs)
                    {
                        if (gs.speedMenuCanvas)
                        {
                            gs.speedMenuCanvas.gameObject.SetActive(true);
                        }
                    }

                    // Go through all the resource types the player has and activate their new UI (4.6+) icons
                    for (int resourceIndex = 0; resourceIndex < bc.moneyTypes.Length; resourceIndex++)
                    {
                        // Activate the icon of the resource type
                        bc.moneyTypes[resourceIndex].icon.gameObject.SetActive(true);
                    }
                }

                // Disable this script
                this.enabled = false;
            }
        }