예제 #1
0
        /// <summary>
        /// Setups maps buttons while waiting until map manager is initialized
        /// </summary>
        /// <returns>Task</returns>
        private async Task SetupButtons()
        {
            await ScenarioManager.Instance.WaitForExtension <ScenarioMapManager>();

            var mapManager = ScenarioManager.Instance.GetExtension <ScenarioMapManager>();

            mapManager.MapChanged += OnMapLoaded;
            var availableMaps  = mapManager.AvailableMaps;
            var currentMapName = mapManager.CurrentMapName;

            for (var i = 0; i < availableMaps.Count; i++)
            {
                var availableMap    = availableMaps[i];
                var mapSelectButton = Instantiate(buttonSample, buttonSample.transform.parent);
                mapSelectButton.Setup(availableMap.name);
                mapSelectButton.gameObject.SetActive(true);
                if (currentMapName == availableMap.name)
                {
                    mapSelectButton.MarkAsCurrent();
                    currentMapButton = mapSelectButton;
                }

                buttons.Add(mapSelectButton);
            }

            //Dynamic height
            var rectTransform = (RectTransform)transform;
            var buttonHeight  = ((RectTransform)buttonSample.transform).sizeDelta.y;
            var firstButtonY  = ((RectTransform)buttons[0].transform).anchoredPosition.y;

            rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, (buttonHeight + 4) * availableMaps.Count - firstButtonY);

            buttonSample.gameObject.SetActive(false);
        }
예제 #2
0
        /// <summary>
        /// Method called when new map is loaded
        /// </summary>
        /// <param name="mapMetaData">The loaded map meta data</param>
        /// <exception cref="ArgumentException">There is no button corresponding to the loaded map</exception>
        private void OnMapLoaded(ScenarioMapManager.MapMetaData mapMetaData)
        {
            if (currentMapButton != null)
            {
                currentMapButton.UnmarkCurrent();
            }
            var mapCorrespondingButton = buttons.Find((button) => button.MapName == mapMetaData.name);

            if (mapCorrespondingButton == null)
            {
                throw new ArgumentException("Could not find button corresponding to loaded map.");
            }
            mapCorrespondingButton.MarkAsCurrent();
            currentMapButton = mapCorrespondingButton;
        }