private void Awake()
        {
            // Sanity checks
            Assert.IsNotNull(this.UIToolboxPanelPrefab);

            // Initialise internal state
            this.name   = "UIToolboxContainer";
            this.Panels = new List <UIToolboxPanel>();

            // Load toolbox configuration from JSON
            TextAsset toolboxConfigAsset = Resources.Load <TextAsset>(TOOLBOX_CONFIG_RESOURCE);

            Assert.IsNotNull(toolboxConfigAsset);
            UIToolboxConfig toolboxConfig = JsonUtility.FromJson <UIToolboxConfig>(toolboxConfigAsset.text);

            // Instantiate and build sub panels
            foreach (var subpanelConfig in toolboxConfig.panels)
            {
                UIToolboxPanel panel = Instantiate(this.UIToolboxPanelPrefab, this.transform);
                Assert.IsNotNull(panel);
                panel.Build(subpanelConfig);
                this.Panels.Add(panel);
            }

            // Instantiate and build main panel
            Assert.IsNull(this.MainPanel);
            UIToolboxPanel mainPanel = Instantiate(this.UIToolboxPanelPrefab, this.transform);

            Assert.IsNotNull(mainPanel);
            mainPanel.Build(toolboxConfig);
            this.Panels.Add(mainPanel);

            // Finalise toolbox
            this.CurrentPanel = this.MainPanel;
        }
示例#2
0
        /// <summary>
        /// Build this panel as a main panel, populated with sub panel entries
        /// </summary>
        /// <param name="mainPanelConfig"></param>
        public void Build(UIToolboxConfig mainPanelConfig)
        {
            // Sanity check
            Assert.IsFalse(this.Built);
            Assert.IsNotNull(mainPanelConfig);
            Assert.IsNotNull(this.UIToolboxSubpanelEntryPrefab);

            // Set name
            this.SimpleName = "Main";

            foreach (var panelEntryConfig in mainPanelConfig.panels)
            {
                // Load sprites
                Sprite activeSprite   = Resources.Load <Sprite>(panelEntryConfig.sprite_selected);
                Sprite inactiveSprite = Resources.Load <Sprite>(panelEntryConfig.sprite_unselected);
                Assert.IsNotNull(activeSprite);
                Assert.IsNotNull(inactiveSprite);

                // Instantiate panel entry
                UIToolboxSubpanelEntry newPanelEntry = Instantiate(this.UIToolboxSubpanelEntryPrefab, this.transform);
                Assert.IsNotNull(newPanelEntry);
                this.Entries.Add(newPanelEntry);

                // Set up panel entry
                newPanelEntry.SimpleName = panelEntryConfig.panel_name;
                newPanelEntry.SetSprites(activeSprite, inactiveSprite);
                newPanelEntry.InfoPanelTitle = panelEntryConfig.panel_name;
                newPanelEntry.InfoPanelText  = panelEntryConfig.entry_description;
            }

            // Remove the back button
            GameObject.Destroy(this.GetComponentInChildren <UIToolboxPanelBackButton>().gameObject);

            // Finalise panel
            this.Built = true;
        }