Exemple #1
0
        /// <summary>
        /// TODO: now only called when hierarchy changes, not when a new prefab is dragged into the scene.
        /// </summary>
        private void UpdateAvailableMenuControllers()
        {
            EnsureSettingsObject();
            // TODO: support MenuControllers in prefabs?
            _availableMenuControllers = HierarchyHelper.GetObjectsOfType <MenuController>();

#if UNITY_2018_3_OR_NEWER
            // Add the open prefab to the list.
            PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
            if (currentPrefabStage != null)
            {
                AddPrefabStageMenuControllers(currentPrefabStage);
            }
#endif
            int labelSize = _availableMenuControllers.Length;
            _availableMenuControllersLabels = new string[labelSize];
            for (int i = 0; i < _availableMenuControllers.Length; i++)
            {
                _availableMenuControllersLabels[i] = _availableMenuControllers[i].name;
                if (_editorMenuCreatorSettings.MenuController == _availableMenuControllers[i])
                {
                    _selectedMenuController = i;
                }
            }
            if (_selectedMenuController >= _availableMenuControllers.Length)
            {
                _selectedMenuController = -1;
            }
        }
Exemple #2
0
        /// <summary>
        /// Shows popup for the user to choose a Canvas that will be used and adds a MenuController component to it.
        /// </summary>
        public static void CreateMenuController(UnityEngine.Events.UnityAction <MenuController> onFinish)
        {
            Canvas[] canvasses   = HierarchyHelper.GetSelectedOrGeneralObjectsOfType <Canvas>();
            Vector2  coordinates = EditorUtils.GetMousePosition();

            try {
                PopupWindow.Show(new Rect(GUIUtility.ScreenToGUIPoint(coordinates), new Vector2(250, 150)), new CanvasSelector(canvasses, (Canvas canvas) => {
                    if (canvas == null)
                    {
                        // The user wants us to create a canvas
                        EditorApplication.ExecuteMenuItem("GameObject/UI/Canvas");
                        Canvas[] newCanvasses = HierarchyHelper.GetObjectsOfType <Canvas>();
                        canvasses             = newCanvasses.Except(canvasses).ToArray();
                        if (canvasses == null || canvasses.Length <= 0)
                        {
                            Debug.LogError("Something went wrong with creating the new canvas. Please try again.");
                            return;
                        }
                        canvas = canvasses[0];
                    }
                    MenuController result = Undo.AddComponent <MenuController>(canvas.gameObject);
                    if (onFinish != null)
                    {
                        onFinish(result);
                    }
                }));
            } catch (UnityEngine.ExitGUIException) {
                // https://answers.unity.com/questions/385235/editorguilayoutcolorfield-inside-guilayoutwindow-c.html
            }
        }