Exemplo n.º 1
0
        public void Init(LevelObject levelObject, Menu.OnLevelAction loadAction)
        {
            levelName.text   = levelObject.levelName;
            levelAuthor.text = levelObject.levelAuthor;
            Assert.IsNotNull(levelObject.overview, $"level named {levelObject.levelName} has no overview?");
            var sprite = Sprite.Create(levelObject.overview,
                                       new Rect(0f, 0f, levelObject.overview.width, levelObject.overview.height), Vector2.one * .5f);

            image.sprite = sprite;
            button.onClick.AddListener(() => loadAction.Invoke(levelObject));
        }
Exemplo n.º 2
0
        public void Init(LevelObject[] levelObjects, Menu.OnLevelAction loadAction)
        {
            foreach (Transform t in transform)
            {
                Destroy(t.gameObject);
            }

            List <LevelObject> list = levelObjects.ToList();

            list.Sort(Comparison);
            foreach (var o in list)
            {
                var panel = Instantiate(prefab, transform);
                panel.Init(o, loadAction);

                // Navigation
                if (o == list.First())
                {
                    firstPanel = panel.GetComponent <Button>();
                    MarkFirstLevel();

                    lastPanelButton = panel.GetComponent <Button>();
                }
                else if (o == list[1])
                {
                    Navigation navigation = new Navigation {
                        mode          = Navigation.Mode.Explicit,
                        selectOnUp    = BackButton.GetComponent <Button>(),
                        selectOnDown  = horizontalScrollbar.GetComponent <Scrollbar>(),
                        selectOnRight = panel.GetComponent <Button>()
                    };
                    lastPanelButton.navigation = navigation;

                    beforeLastPanelButton = lastPanelButton;
                    lastPanelButton       = panel.GetComponent <Button>();
                }
                else
                {
                    Navigation navigation = new Navigation {
                        mode          = Navigation.Mode.Explicit,
                        selectOnUp    = BackButton.GetComponent <Button>(),
                        selectOnDown  = horizontalScrollbar.GetComponent <Scrollbar>(),
                        selectOnLeft  = beforeLastPanelButton,
                        selectOnRight = panel.GetComponent <Button>()
                    };
                    lastPanelButton.navigation = navigation;

                    beforeLastPanelButton = lastPanelButton;
                    lastPanelButton       = panel.GetComponent <Button>();
                }

                if (o == list.Last())
                {
                    Navigation navigation = new Navigation {
                        mode         = Navigation.Mode.Explicit,
                        selectOnUp   = BackButton.GetComponent <Button>(),
                        selectOnDown = horizontalScrollbar.GetComponent <Scrollbar>(),
                        selectOnLeft = beforeLastPanelButton
                    };
                    panel.GetComponent <Button>().navigation = navigation;
                }
            }
        }