Exemplo n.º 1
0
        private void ChangeCollection()
        {
            this.Clear();
            var collection = GameState.Collections[GameState.CurrentCollectionIndex];

            collectionText.GetComponent <Text>().text = collection;

            GameState.CurrentCollectionLevels = LevelFileLoader.GetLevels(collection).ToArray();

            var index = 0;

            foreach (var level in GameState.CurrentCollectionLevels)
            {
                var buttonGameObject = (GameObject)Instantiate(levelButtonPrefab);
                buttonGameObject.transform.SetParent(layoutContent.transform, false);
                buttonGameObject.transform.GetChild(0).GetComponent <Text>().text = level.Item1;
                instances.Add(buttonGameObject);
                var button = buttonGameObject.GetComponent <UnityEngine.UI.Button>();

                // add lsitener
                button.onClick.AddListener(() =>
                {
                    GameState.CurrentLevelIndex = index;
                    CommunicationService.ChangeLevel(level);
                });
            }

            // switch buttons
            previousButton.SetActive(GameState.CurrentCollectionIndex > 0);
            nextButton.SetActive(GameState.CurrentCollectionIndex < collection.Length - 1);
            index++;
        }
Exemplo n.º 2
0
        private void Start()
        {
            GameState.Collections = LevelFileLoader.ListCollections();
            ChangeCollection();

            var _nextButton = nextButton.GetComponent <UnityEngine.UI.Button>();

            _nextButton.onClick.AddListener(() =>
            {
                GameState.CurrentCollectionIndex++;
                ChangeCollection();
            });

            var _previousButton = previousButton.GetComponent <UnityEngine.UI.Button>();

            _previousButton.onClick.AddListener(() =>
            {
                GameState.CurrentCollectionIndex--;
                ChangeCollection();
            });

            var _resetButton = resetButton.GetComponent <UnityEngine.UI.Button>();

            _resetButton.onClick.AddListener(() =>
            {
                CommunicationService.ChangeLevel(GameState.CurrentCollectionLevels[GameState.CurrentLevelIndex]);
            });

            CommunicationService.LevelChange += (Tuple <string, char[][]> level) =>
            {
                menuCanvas.SetActive(false);
                resetButton.SetActive(true);
            };

            resetButton.SetActive(false);
        }