Esempio n. 1
0
        private void Start()
        {
            Dictionary <string, bool> savedScenarios = MissionSaveLoad.LoadScenarios(); //get the saved scenarios

            //start by creating the assigned scenarios
            for (int i = 0; i < scenarios.Length; i++)
            {
                ScenarioMenuUI nextScenarioUI = Instantiate(scenarioUIPrefab.gameObject, scenarioUIParent.transform).GetComponent <ScenarioMenuUI>(); //create a new scenario UI menu element
                scenarioUIList.Add(nextScenarioUI);

                nextScenarioUI.Init(this, i); //initialise it

                bool unlocked = true;
                if (i > 0)                                                                                             //only if this is not the first scenario in the list
                {
                    savedScenarios.TryGetValue(scenarios[i - 1].source.GetCode(), out unlocked);                       //check if it's unlocked or not
                }
                nextScenarioUI.Refresh(scenarios[i].source.GetName(), scenarios[i].source.GetDescription(), unlocked); //refresh the content of the scenario UI menu
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshes the UI elements of the available scenarios.
        /// </summary>
        /// <param name="redraw">When true, previous UI elements will be destroyed and redrawn. When false, only the state of the scenario in the UI elements will be updated.</param>
        public void RefreshUI(bool redraw)
        {
            if (redraw)                          //redraw the UI elemets for each scenario?
            {
                while (scenarioUIList.Count > 0) //go through the already drawn scenario UI elements
                {
                    Destroy(scenarioUIList[0]);  //destroy the UI element
                    scenarioUIList.RemoveAt(0);; //remove the element's entry
                }
            }

            Dictionary <string, bool> savedScenarios = MissionSaveLoad.LoadScenarios(); //get the saved scenarios

            //start by creating the assigned scenarios
            for (int i = 0; i < scenarios.Length; i++)
            {
                ScenarioMenuUI nextScenarioUI = scenarioUIList.Count > i
                    ? scenarioUIList[i]
                    : null;

                if (nextScenarioUI == null)                                                                                                //the scenario UI element is not found, create one
                {
                    nextScenarioUI = Instantiate(scenarioUIPrefab.gameObject, scenarioUIParent.transform).GetComponent <ScenarioMenuUI>(); //create a new scenario UI menu element
                    scenarioUIList.Add(nextScenarioUI);
                }

                nextScenarioUI.Init(this, i); //initialise it

                bool unlocked = true;
                if (i > 0)                                                                                             //only if this is not the first scenario in the list
                {
                    savedScenarios.TryGetValue(scenarios[i - 1].source.GetCode(), out unlocked);                       //check if it's unlocked or not
                }
                nextScenarioUI.Refresh(scenarios[i].source.GetName(), scenarios[i].source.GetDescription(), unlocked); //refresh the content of the scenario UI menu
            }
        }