Exemplo n.º 1
0
        private void CreatePopup(int count, MCMenu parent)
        {
            // Get the Menu object, we need this because we have a button that closes the menu.
            MCMenu popupMenu = MenuController.GetMenuGlobal("SIMPLEPOPUP");

            // Create the data for the menu.
            MCSimplePopupData simplePopupData = new MCSimplePopupData("title " + count, "This is another popup.",
                                                                      new MCButtonData[]
            {
                new MCButtonData("New popup", button => { CreatePopup(count + 1, popupMenu); }, null, true, "Creates a new popup"),
                new MCButtonData("Tooltip", null, null, true, "Simply shows the tooltip working"),
                new MCButtonData("Close parent", button => { MenuController.HideMenuGlobal(popupMenu.Parent); }, null, true, "Closes the parent menu (which will close all children)"),
                new MCButtonData("Close this", button => popupMenu.Hide(), null, true, "Closes this popup")
            });

            if (parent)
            {
                parent.AddPopup(popupMenu, simplePopupData);
            }
            else
            {
                // Add the popup to the screen, when there is nothing on the screen it will be added as a menu instead of a popup.
                MenuController.AddPopupGlobal(popupMenu, true, simplePopupData);

                // In case you have a specific menucontroller that you want to use:
                // yourMenuController.AddPopup(popupMenu, true, simplePopupData);
            }
        }
Exemplo n.º 2
0
        public static List <MCMenu> GetSimilarIDs(MCMenu comparison)
        {
            string        id  = comparison.Id;
            List <MCMenu> ids = new List <MCMenu>();

            GameObject[] allGameObjects = Resources.FindObjectsOfTypeAll <GameObject>();
            for (int i = 0; i < allGameObjects.Length; i++)
            {
                MCMenu menu = allGameObjects[i].GetComponentInChildren <MCMenu>();
                if (menu)
                {
                    if (string.Equals(menu.Id, id) && comparison != menu)
                    {
                        ids.Add(menu);
                    }
                }
            }

            // If we are the only instance, remove us.
            if (ids.Count == 1)
            {
                ids.Clear();
            }

            return(ids);
        }
        /// <summary>
        /// Returns a poolObject from the global MenuManager if available, otherwise it will instantiate a new menu.
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        private MCMenu GetPoolObject(string menu)
        {
            Queue <MCMenu> menus;

            if (_menuPool.TryGetValue(menu, out menus))
            {
                if (menus.Count > 0)
                {
                    MCMenu dequeue = menus.Dequeue();
                    dequeue.PrepareForPool();
                    return(dequeue);
                }
            }

            // We could not find a poolObject, instantiate a new object.
            MCMenu menuObject;

            if (!_menus.TryGetValue(menu, out menuObject))
            {
                Debug.LogError("Trying to show a menu that is not added to this MenuController: " + menu);
                return(null);
            }
            MCMenu mcMenu = Instantiate(menuObject, transform);

            mcMenu.SetState(false);
            return(mcMenu);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Goes through all prefabs and gets all IDs.
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, List <MCMenu> > GetAllIDs()
        {
            Dictionary <string, List <MCMenu> > ids = new Dictionary <string, List <MCMenu> >();

            GameObject[] allGameObjects = Resources.FindObjectsOfTypeAll <GameObject>();
            for (int i = 0; i < allGameObjects.Length; i++)
            {
                MCMenu menu = allGameObjects[i].GetComponentInChildren <MCMenu>();
                if (menu)
                {
                    if (ids.TryGetValue(menu.Id, out List <MCMenu> menus))
                    {
                        menus.Add(menu);
                    }
                    else
                    {
                        ids.Add(menu.Id, new List <MCMenu> {
                            menu
                        });
                    }
                }
            }

            return(ids);
        }
Exemplo n.º 5
0
        private void AddSharedMenuToController(MCMenu mcMenu)
        {
            if (!mcMenu)
            {
                this.ShowNotification(new GUIContent("This does not contain a MCMenu component."));
                return;
            }
            PrefabType prefabType = PrefabUtility.GetPrefabType(mcMenu);

            if (prefabType == PrefabType.None)
            {
                this.ShowNotification(new GUIContent("Please use prefabs for shared menus."));
                return;
            }

            Object prefab = mcMenu;

            if (prefabType == PrefabType.PrefabInstance)
            {
                prefab = PrefabUtility.GetCorrespondingObjectFromSource(mcMenu);
            }

            _menuControllerSharedPropsObject.Update();
            SerializedProperty sharedProps = _menuControllerSharedPropsObject.FindProperty("_menus");

            sharedProps.arraySize += 1;
            sharedProps.GetArrayElementAtIndex(sharedProps.arraySize - 1).objectReferenceValue = prefab;
            _menuControllerSharedPropsObject.ApplyModifiedProperties();
        }
        /// <summary>
        /// Will Initalize the outside click for the last activated menu that is still active.
        /// </summary>
        private void InitializeOutsideClick()
        {
            MCMenu lastActive = GetLastActive();

            if (lastActive)
            {
                InitializeOutsideClick(lastActive);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add a popup to this menu and assign this menu as the parent for the popup.
        /// </summary>
        /// <param name="mcMenu">The new popup object.</param>
        /// <param name="data">Data that is passed to the popup that is created.</param>
        public MCMenu AddPopup(MCMenu mcMenu, object data = null)
        {
            PopupMenus.Add(mcMenu);
            mcMenu.Parent = this;
            mcMenu.Show(data);

            _menuController.OnMenuAdded(mcMenu);
            return(mcMenu);
        }
        /// <summary>
        /// Add a popup with an id to an existing menu.
        /// </summary>
        /// <param name="id">The id of the new popup.</param>
        /// <param name="parent">The parent object that already exists.</param>
        /// <param name="data">Data that should be passed on to the popup that is created.</param>
        /// <returns></returns>
        public MCMenu AddPopup(string id, MCMenu parent, object data = null)
        {
#if UNITY_EDITOR
            if (string.IsNullOrWhiteSpace(id))
            {
                Debug.LogError("You are trying to add a popup, but the id is empty. This is probably a mistake.");
            }
#endif
            return(parent.AddPopup(GetPoolObject(id), data));
        }
        /// <summary>
        /// Add a poolObject to the pool for a certain menu.
        /// Only does data managing, the object should already be ready for pooling (E.G. inactive).
        /// </summary>
        /// <param name="menu"></param>
        private void AddPoolObject(MCMenu menu)
        {
            Queue <MCMenu> menus;

            if (!_menuPool.TryGetValue(menu.Id, out menus))
            {
                menus = new Queue <MCMenu>();
                _menuPool.Add(menu.Id, menus);
            }

            menus.Enqueue(menu);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called when the user wants to create a new menu.
        /// </summary>
        /// <param name="menuCreatorPreset"></param>
        private void CreateMenu(MenuCreatorPreset menuCreatorPreset)
        {
            GameObject newMenu = Instantiate(menuCreatorPreset.PresetObject, _editorMenuCreatorSettings.MenuController.transform);

            Undo.RegisterCreatedObjectUndo(newMenu, "Created menu");

            MCMenu mcMenu = newMenu.GetComponentInChildren <MCMenu>();

            if (mcMenu)
            {
                AddMenuToController(mcMenu);
            }
        }
Exemplo n.º 11
0
        private void InitializeDraggables(IDraggableMenu draggableMenu)
        {
            MCMenu mcMenu = (MCMenu)target;

            Draggable[] draggables = mcMenu.GetComponentsInChildren <Draggable>();

            for (int i = 0; i < draggables.Length; i++)
            {
                SerializedObject so = new SerializedObject(draggables[i]);
                so.Update();
                so.FindProperty("Owner").objectReferenceValue = mcMenu;
                so.ApplyModifiedProperties();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Try to get a menu of type from the active menus.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="mcMenu">Set to null if no menu of this type is found. Otherwise is the menu that that is active with type 'id'.</param>
        /// <remarks>Uses linear search.</remarks>
        /// <returns>False if no menu of this type is found. </returns>
        public bool TryGetMenuActive(string id, out MCMenu mcMenu)
        {
            for (int i = 0; i < _activeMenus.Count; i++)
            {
                if (_activeMenus[i].Id == id)
                {
                    mcMenu = _activeMenus[i];
                    return(true);
                }
            }

            mcMenu = null;
            return(false);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Prepare the OutsideClick object and put it in the right position in the heiarchy.
        /// </summary>
        /// <param name="mcMenu"></param>
        private void InitializeOutsideClick(MCMenu mcMenu)
        {
            int siblingIndex = mcMenu.transform.GetSiblingIndex();

            if (_clickOutsideMenu.transform.GetSiblingIndex() < siblingIndex)
            {
                siblingIndex--;
            }
            _clickOutsideMenu.transform.SetSiblingIndex(siblingIndex);
            _clickOutsideMenu.OnClick = mcMenu.OnClickOutside;

            _clickOutsideMenu.raycastTarget = mcMenu.BlockOutsideRaycasting;

            _clickOutsideMenu.gameObject.SetActive(true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Will add a menu popup for the current visible menu (first one that was visible).
 /// </summary>
 /// <param name="mcMenu"></param>
 /// <param name="createWhenNoMenu">If true this popup will be made an active window in the case of no active windows at the time of calling this.
 /// If false, no popup will be shown if there is no active window.</param>
 /// <param name="data"></param>
 public MCMenu AddPopup(MCMenu mcMenu, bool createWhenNoMenu, object data = null)
 {
     if (_activeMenus.Count > 0)
     {
         InitializeOutsideClick(mcMenu);
         _activeMenus[0].AddPopup(mcMenu, data);
     }
     else
     {
         if (createWhenNoMenu)
         {
             ShowMenu(mcMenu, data);
         }
     }
     return(mcMenu);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Adds a new menu to the array of menus in the menucontroller.
 /// </summary>
 /// <param name="mcMenu"></param>
 private void AddMenuToController(MCMenu mcMenu)
 {
     if (!mcMenu)
     {
         return;
     }
     if (_editorMenuCreatorSettings.MenuController)
     {
         if (_menuController == null)
         {
             _menuController = new SerializedObject(_editorMenuCreatorSettings.MenuController);
         }
         _menuController.Update();
         SerializedProperty menuArray = _menuController.FindProperty("_mcMenus");
         menuArray.arraySize += 1;
         menuArray.GetArrayElementAtIndex(menuArray.arraySize - 1).objectReferenceValue = mcMenu;
         _menuController.ApplyModifiedProperties();
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Called when a menu is ready to be actually hidden internally (from the data structure).
        /// </summary>
        /// <param name="mcMenu"></param>
        private void OnHideMenu(MCMenu mcMenu)
        {
            if (_activeMenus.Contains(mcMenu))
            {
                _clickOutsideMenu.gameObject.SetActive(false);

                _activeMenus.Remove(mcMenu);
                // Only check the menu when we actually removed something.
                if (!CheckMenuQueue())
                {
                    // We did not activate a menu in the queue.
                    InitializeOutsideClick();
                }
            }
            else
            {
                if (mcMenu.Parent)
                {
                    InitializeOutsideClick(mcMenu.Parent);
                }
                else
                {
                    InitializeOutsideClick();
                }
            }

            if (mcMenu.ShouldBePooled)
            {
                // It should be pooled, add it.
                AddPoolObject(mcMenu);
            }
            else
            {
                // Since it should not be pooled, we destroy it.
                Destroy(mcMenu.gameObject);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Show a specific menu.
        /// If this menu needs fullscreen and the current active menus allow it to override them, it will close the current menus.
        /// </summary>
        /// <param name="mcMenu">The new menu. (this is a copy of the original)</param>
        /// <param name="mcMenuData"></param>
        public MCMenu ShowMenu(MCMenu mcMenu, object mcMenuData = null)
        {
            if (mcMenu.Fullscreen)
            {
                bool canShow = true;
                for (int i = 0; i < _activeMenus.Count; i++)
                {
                    if (_activeMenus[i].ShouldBlockNewMenu)
                    {
                        canShow = false;
                        break;
                    }
                }
                if (canShow)
                {
                    // Hide the current menu's and show this one.
                    HideAllBlockingMenus();
                }
                else
                {
                    if (mcMenu.ShouldBeQueued)
                    {
                        _menuQueue.Enqueue(new MenuQueueItem(mcMenu, mcMenuData));
                    }
                    return(mcMenu);
                }
            }

            InitializeOutsideClick(mcMenu);
            // Add ourselves as the owner of the menu.
            mcMenu.SetMenuController(this);
            // We can show this one.
            mcMenu.Show(mcMenuData);
            _activeMenus.Add(mcMenu);
            return(mcMenu);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Called when a popup is added directly to the McMenu and will make sure the OutsideClick is correctly configured.
 /// </summary>
 /// <param name="mcMenu"></param>
 public void OnMenuAdded(MCMenu mcMenu)
 {
     InitializeOutsideClick(mcMenu);
 }
Exemplo n.º 19
0
        private void DrawManageMenus()
        {
            bool hasMenuControllerSelected = _editorMenuCreatorSettings.MenuController;

            if (!hasMenuControllerSelected)
            {
                EditorGUILayout.HelpBox("Select a MenuController to change specific menus.", MessageType.Info);
            }

            if (hasMenuControllerSelected)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Specific menus", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                _editorMenuCreatorSettings.DetailView = EditorGUILayout.Toggle("Detailed", _editorMenuCreatorSettings.DetailView);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();

                _menuController.Update();
                SerializedProperty arrayProperty = _menuController.FindProperty("_mcMenus");
                for (int i = 0; i < arrayProperty.arraySize; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(arrayProperty.GetArrayElementAtIndex(i));
                    if (GUILayout.Button("Remove"))
                    {
                        RemoveMenuFromController(i);
                    }
                    EditorGUILayout.EndHorizontal();

                    // Show extra details, like the menuId.
                    if (_editorMenuCreatorSettings.DetailView)
                    {
                        using (new EditorGUI.IndentLevelScope())
                        {
                            SerializedObject   serializedMenu   = new SerializedObject(arrayProperty.GetArrayElementAtIndex(i).objectReferenceValue);
                            SerializedProperty serializedMenuID = serializedMenu.FindProperty("_id");
                            if (serializedMenuID != null)
                            {
                                EditorGUILayout.PropertyField(serializedMenuID);
                            }

                            serializedMenu.ApplyModifiedProperties();
                        }
                    }
                }
                EditorGUILayout.Space();
                _menuController.ApplyModifiedProperties();

                DragDrop.DrawDragDrop("Drag menus to add them", objects =>
                {
                    foreach (Object dropObject in objects)
                    {
                        GameObject gameObject = dropObject as GameObject;
                        if (gameObject)
                        {
                            MCMenu mcMenu = gameObject.GetComponentInChildren <MCMenu>();
                            AddMenuToController(mcMenu);
                        }
                    }
                }, 40);

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
                EditorGUILayout.Space();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Shared menus", EditorStyles.boldLabel);
            EditorGUILayout.Space();
            if (GUILayout.Button("", GUI.skin.GetStyle("IN ObjectField")))
            {
                EditorGUIUtility.PingObject(_menuControllerSharedProps);
            }
            EditorGUILayout.EndHorizontal();

            EnsureSharedProps();

            _menuControllerSharedPropsObject.Update();
            SerializedProperty sharedMenusProperty = _menuControllerSharedPropsObject.FindProperty("_menus");

            for (int i = 0; i < sharedMenusProperty.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(sharedMenusProperty.GetArrayElementAtIndex(i));
                if (GUILayout.Button("Remove"))
                {
                    RemoveSharedMenuFromController(i);
                }
                EditorGUILayout.EndHorizontal();
            }
            _menuControllerSharedPropsObject.ApplyModifiedProperties();

            EditorGUILayout.Space();

            DragDrop.DrawDragDrop("Drag menus to add them", objects =>
            {
                foreach (Object dropObject in objects)
                {
                    GameObject gameObject = dropObject as GameObject;
                    if (gameObject)
                    {
                        MCMenu mcMenu = gameObject.GetComponentInChildren <MCMenu>();
                        AddSharedMenuToController(mcMenu);
                    }
                }
            }, 40);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Hide a specific menu.
 /// </summary>
 /// <param name="mcMenu"></param>
 public void HideMenu(MCMenu mcMenu)
 {
     mcMenu.Hide(() => OnHideMenu(mcMenu));
 }
Exemplo n.º 21
0
 public MenuQueueItem(MCMenu mcMenu, object data)
 {
     _mcMenu = mcMenu;
     _data   = data;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Called when a popup is added directly to the McMenu and will make sure the OutsideClick is correctly configured.
 /// </summary>
 /// <param name="mcMenu"></param>
 public static void OnMenuAddedGlobal(MCMenu mcMenu)
 {
     _instance.InitializeOutsideClick(mcMenu);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Add a poolObject to the pool (of the global MenuController) for a certain menu.
 /// Only does data managing, the object should already be ready for pooling (E.G. inactive).
 /// </summary>
 /// <param name="menu"></param>
 private static void AddPoolObjectGlobal(MCMenu menu)
 {
     _instance.AddPoolObject(menu);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Add a popup with an id to an existing menu to the global MenuController
 /// </summary>
 /// <param name="id">The id of the new popup.</param>
 /// <param name="parent">The parent object that already exists.</param>
 /// <param name="data">Data that should be passed on to the popup that is created.</param>
 /// <returns></returns>
 public static MCMenu AddPopupGlobal(string id, MCMenu parent, object data = null)
 {
     return(_instance.AddPopup(id, parent, data));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Will add a menu popup for the current visible menu (first one that was visible) for the global MenuController.
 /// </summary>
 /// <param name="mcMenu"></param>
 /// <param name="createWhenNoMenu">If true this popup will be made an active window in the case of no active windows at the time of calling this.
 /// If false, no popup will be shown if there is no active window.</param>
 /// <param name="data"></param>
 public static MCMenu AddPopupGlobal(MCMenu mcMenu, bool createWhenNoMenu, object data = null)
 {
     return(_instance.AddPopup(mcMenu, createWhenNoMenu, data));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Hide a specific menu for the global MenuController.
 /// </summary>
 /// <param name="mcMenu"></param>
 public static void HideMenuGlobal(MCMenu mcMenu)
 {
     _instance.HideMenu(mcMenu);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Show a specific menu in the global MenuController.
 /// If this menu needs fullscreen and the current active menus allow it to override them, it will close the current menus.
 /// </summary>
 /// <param name="mcMenu">The new menu. (this is a copy of the original)</param>
 /// <param name="mcMenuData"></param>
 public static MCMenu ShowMenuGlobal(MCMenu mcMenu, object mcMenuData = null)
 {
     return(_instance.ShowMenu(mcMenu, mcMenuData));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Remove a specific popup menu.
 /// </summary>
 /// <param name="mcMenu"></param>
 public void RemovePopup(MCMenu mcMenu)
 {
     PopupMenus.Remove(mcMenu);
     mcMenu.Parent = null;
     mcMenu.Hide();
 }
Exemplo n.º 29
0
        /// <summary>
        /// Draw the create preset panel.
        /// </summary>
        private void DrawCreatePreset()
        {
            bool hasPresets = CheckPresets();

            if (!hasPresets)
            {
                EditorGUILayout.HelpBox("You don't seem to have any presets, start by creating one!", MessageType.Info);
            }

            EditorGUILayout.BeginHorizontal();

            _newFileName = GUILayout.TextField(_newFileName, 20);

            if (GUILayout.Button("Create new"))
            {
                CreatePreset(_newFileName);
                UpdatePresetsList();
            }

            EditorGUILayout.EndHorizontal();

            if (!hasPresets)
            {
                return;
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.Label("Preset list", EditorStyles.centeredGreyMiniLabel);

            _scrollPositionPresetList = EditorGUILayout.BeginScrollView(_scrollPositionPresetList);
            for (int i = 0; i < _presets.Length; i++)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(_presets[i].Title))
                {
                    _currentSelectedPreset = _presets[i];
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            GUILayout.Label("Preset detail", EditorStyles.centeredGreyMiniLabel);

            if (_currentSelectedPreset != null)
            {
                _scrollPositionPresetDetail = EditorGUILayout.BeginScrollView(_scrollPositionPresetDetail);
                Editor editor = Editor.CreateEditor(_currentSelectedPreset);
                editor.DrawDefaultInspector();

                EditorGUILayout.Space();

                if (_currentSelectedPreset.PresetObject)
                {
                    MCMenu mcMenu = _currentSelectedPreset.PresetObject.GetComponentInChildren <MCMenu>();
                    if (mcMenu)
                    {
                        Editor mcEditor = Editor.CreateEditor(mcMenu);
                        mcEditor.DrawDefaultInspector();
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Try to get a menu of type from the active menus.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="mcMenu">Set to null if no menu of this type is found. Otherwise is the menu that that is active with type 'id'.</param>
 /// <remarks>Uses linear search.</remarks>
 /// <returns>False if no menu of this type is found. </returns>
 public static bool TryGetMenuActiveGlobal(string id, out MCMenu mcMenu)
 {
     return(_instance.TryGetMenuActive(id, out mcMenu));
 }