Example #1
0
        // Utility function to spawn a single button and add it to the tool panel.
        GameObject SpawnButton(GameObject buttonPrefab, int buttonId)
        {
            GameObject button = GameObject.Instantiate(
                buttonPrefab, menuComponent.ToolPanel.transform, false);

            Menus.GUIEditorButton component = button.GetComponent <Menus.GUIEditorButton>();
            if (component != null)
            {
                component.buttonId    = buttonId;
                toolButtons[buttonId] = button;
            }
            else
            {
                Debug.LogError("Button prefab had no LevelSelectButtionGUI component.");
            }
            return(button);
        }
Example #2
0
 // Update the button highlights and make sure that only the selection has one.
 void UpdateButtonHighlights()
 {
     foreach (KeyValuePair <int, GameObject> pair in toolButtons)
     {
         Menus.GUIEditorButton button = pair.Value.GetComponent <Menus.GUIEditorButton>();
         // Attach the highlight to the appropriate button:
         if (button.buttonId == mapToolSelection)
         {
             menuComponent.Highlight.gameObject.SetActive(true);
             menuComponent.Highlight.transform.SetParent(button.transform, false);
             menuComponent.Highlight.transform.position =
                 button.transform.position - button.transform.TransformVector(new Vector3(0, 0, 1));
             return;
         }
     }
     // No highlighted button found.  Hide the highlight.
     menuComponent.Highlight.transform.SetParent(menuComponent.transform, false);
     menuComponent.Highlight.gameObject.SetActive(false);
 }
Example #3
0
        // Handle button clicks etc, and act on them.
        public override void HandleUIEvent(GameObject source, object eventData)
        {
            if (source == menuComponent.MainButton.gameObject)
            {
                manager.SwapState(new MainMenu());
            }
            else if (source == menuComponent.ClearButton.gameObject)
            {
                CommonData.gameWorld.DisposeWorld();
            }
            else if (source == menuComponent.LoadButton.gameObject)
            {
                manager.PushState(new LoadMap());
            }
            else if (source == menuComponent.SaveButton.gameObject)
            {
                manager.PushState(new SaveMap());
            }
            else if (source == menuComponent.PlayButton.gameObject)
            {
                manager.PushState(new Gameplay(Gameplay.GameplayMode.Editor));
            }
            else if (source == menuComponent.RotateButton.gameObject)
            {
                currentOrientation = (currentOrientation + 1) % 4;
                UpdateOrientationIndicator();
#if UNITY_EDITOR
            }
            else if (source == menuComponent.ExportButton.gameObject)
            {
                manager.PushState(new ExportMap(CommonData.gameWorld.worldMap));
            }
            else if (source == menuComponent.BonusButton.gameObject)
            {
                manager.PushState(new SaveBonusMap());
#endif
            }
            else
            {
                Menus.GUIEditorButton editorButton = source.GetComponent <Menus.GUIEditorButton>();
                if (editorButton != null)
                {
                    int previousSelection = mapToolSelection;
                    if (editorButton.buttonId == DownArrowId)
                    {
                        SpawnToolButtons(++currentPage);
                    }
                    else if (editorButton.buttonId == UpArrowId)
                    {
                        SpawnToolButtons(--currentPage);
                    }
                    else
                    {
                        mapToolSelection = editorButton.buttonId;
                        UpdateButtonHighlights();
                    }

                    // If selecting or unselecting Camera, we need to update the controller.
                    if (previousSelection != mapToolSelection &&
                        (previousSelection == (int)SpecialTools.Camera ||
                         mapToolSelection == (int)SpecialTools.Camera))
                    {
                        UpdateCameraController();
                    }
                }
            }
        }