Menu class to manipulate the menu item.

Пример #1
0
 public static void __changeDebug()
 {
     LerpedCore.SetBool(section, !active);
     EditorMenu.SetChecked(menuName, active);
     EditorPrefs.SetBool(menuName, active);
     if (active)
     {
         Debug.Log("Debug is enabled!");
     }
     else
     {
         Debug.Log("Debug is disabled!");
     }
 }
Пример #2
0
		private void SideMenu (Menu _menu)
		{
			GenericMenu menu = new GenericMenu ();
			sideMenu = menus.IndexOf (_menu);

			menu.AddItem (new GUIContent ("Insert after"), false, MenuCallback, "Insert after");
			if (menus.Count > 0)
			{
				menu.AddItem (new GUIContent ("Delete"), false, MenuCallback, "Delete");
			}

			menu.AddSeparator ("");
			menu.AddItem (new GUIContent ("Copy"), false, MenuCallback, "Copy");
			if (MenuManager.copiedMenu != null)
			{
				menu.AddItem (new GUIContent ("Paste after"), false, MenuCallback, "Paste after");
			}

			if (sideMenu > 0 || sideMenu < menus.Count-1)
			{
				menu.AddSeparator ("");
				if (sideMenu > 0)
				{
					menu.AddItem (new GUIContent ("Move up"), false, MenuCallback, "Move up");
				}
				if (sideMenu < menus.Count-1)
				{
					menu.AddItem (new GUIContent ("Move down"), false, MenuCallback, "Move down");
				}
			}
			
			menu.ShowAsContext ();
		}
Пример #3
0
		private void AddElement (string className, Menu _menu)
		{
			Undo.RecordObject (_menu, "Add element");

			List<int> idArray = new List<int>();
			
			foreach (MenuElement _element in _menu.elements)
			{
				if (_element != null)
				{
					idArray.Add (_element.ID);
				}
			}
			idArray.Sort ();
			
			className = "Menu" + className;
			MenuElement newElement = (MenuElement) CreateInstance (className);
			newElement.Declare ();
			newElement.title = className.Substring (4);
			
			// Update id based on array
			foreach (int _id in idArray.ToArray())
			{
				if (newElement.ID == _id)
				{
					newElement.ID ++;
				}
			}
			
			_menu.elements.Add (newElement);
			_menu.Recalculate ();
			DeactivateAllElements (_menu);
			newElement.isEditing = true;
			selectedMenuElement = newElement;

			newElement.hideFlags = HideFlags.HideInHierarchy;
			AssetDatabase.AddObjectToAsset (newElement, this);
			AssetDatabase.ImportAsset (AssetDatabase.GetAssetPath (newElement));
			AssetDatabase.SaveAssets ();

			CleanUpAsset ();
		}
Пример #4
0
		private void DeactivateAllElements (Menu menu)
		{
			foreach (MenuElement menuElement in menu.elements)
			{
				menuElement.isEditing = false;
			}
		}
Пример #5
0
		private void DeleteAllElements (Menu menu)
		{
			foreach (MenuElement menuElement in menu.elements)
			{
				UnityEngine.Object.DestroyImmediate (menuElement, true);
				AssetDatabase.SaveAssets();
			}
			CleanUpAsset ();
		}
Пример #6
0
		private void DeactivateAllMenus ()
		{
			foreach (Menu menu in menus)
			{
				menu.isEditing = false;
			}
			selectedMenu = null;
			selectedMenuElement = null;
		}
Пример #7
0
		private void ActivateMenu (Menu menu)
		{
			menu.isEditing = true;
			selectedMenu = menu;
		}
Пример #8
0
		public override void DrawOutline (bool isSelected, Menu _menu)
		{
			if (dragType == DragElementType.EntireMenu)
			{
				DrawStraightLine.DrawBox (_menu.GetRectAbsolute (GetDragRectRelative ()), Color.white, 1f, false, 1);
			}
			else
			{
				if (elementName != "")
				{
					MenuElement element = MenuManager.GetElementWithName (_menu.title, elementName);
					if (element != null)
					{
						Rect dragBox = _menu.GetRectAbsolute (GetDragRectRelative ());
						dragBox.x += element.GetSlotRectRelative (0).x;
						dragBox.y += element.GetSlotRectRelative (0).y;
						DrawStraightLine.DrawBox (dragBox, Color.white, 1f, false, 1);
					}
				}
			}
			
			base.DrawOutline (isSelected, _menu);
		}
Пример #9
0
		public void SelectElementFromPreview (Menu _menu, MenuElement _element)
		{
			if (_menu.elements.Contains (_element))
			{
				if (selectedMenuElement != _element)
				{
					DeactivateAllElements (_menu);
					ActivateElement (_element);
				}
			}
		}
Пример #10
0
 private static void UpdateState()
 {
     EditorApplication.update -= UpdateState;
     EditorMenu.SetChecked(menuName, active);
 }
Пример #11
0
		public virtual void DrawOutline (bool isSelected, Menu _menu)
		{
			Color boxColor = Color.yellow;
			if (isSelected)
			{
				boxColor = Color.red;
			}
			for (int i=0; i<GetNumSlots (); i++)
			{
				if (i > 0)
				{
					boxColor = Color.blue;
				}
				DrawStraightLine.DrawBox (_menu.GetRectAbsolute (GetSlotRectRelative (i)), boxColor, 1f, false, 1);
			}

		}
Пример #12
0
		public void ClickOutput (Menu _menu, MouseState _mouseState)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeInventory>())
			{
				RuntimeInventory runtimeInventory = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeInventory>();

				if (items.Count > 0)
				{
					if (_mouseState == MouseState.SingleClick)
					{
						if (runtimeInventory.selectedItem == null)
						{
							// Pick up created item
							if (activeRecipe.onCreateRecipe == OnCreateRecipe.SelectItem)
							{
								runtimeInventory.PerformCrafting (activeRecipe, true);
							}
							else if (activeRecipe.onCreateRecipe == OnCreateRecipe.RunActionList)
							{
								runtimeInventory.PerformCrafting (activeRecipe, false);
								if (activeRecipe.invActionList != null && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent <RuntimeActionList>())
								{
									AdvGame.RunActionListAsset (activeRecipe.invActionList);
								}
							}
							else
							{
								runtimeInventory.PerformCrafting (activeRecipe, false);
							}
						}
					}
					PlayerMenus.ResetInventoryBoxes ();
				}
			}
		}
 static void OnRecordCommand(CommandExecuteContext ctx)
 {
     s_SlaveProfilerWindow.SetRecordingEnabled(!s_SlaveProfilerWindow.IsRecording());
     Menu.SetChecked("Edit/Record", s_SlaveProfilerWindow.IsRecording());
 }
Пример #14
0
		private void SideMenu (Menu _menu, MenuElement _element)
		{
			GenericMenu menu = new GenericMenu ();
			sideElement = _menu.elements.IndexOf (_element);
			sideMenu = menus.IndexOf (_menu);
			
			if (_menu.elements.Count > 0)
			{
				menu.AddItem (new GUIContent ("Delete"), false, ElementCallback, "Delete");
			}

			menu.AddSeparator ("");
			menu.AddItem (new GUIContent ("Copy"), false, ElementCallback, "Copy");
			if (MenuManager.copiedElement != null)
			{
				menu.AddItem (new GUIContent ("Paste after"), false, ElementCallback, "Paste after");
			}
			if (sideElement > 0 || sideElement < _menu.elements.Count-1)
			{
				menu.AddSeparator ("");
			}

			if (sideElement > 0)
			{
				menu.AddItem (new GUIContent ("Move up"), false, ElementCallback, "Move up");
			}
			if (sideElement < _menu.elements.Count-1)
			{
				menu.AddItem (new GUIContent ("Move down"), false, ElementCallback, "Move down");
			}
			
			menu.ShowAsContext ();
		}
Пример #15
0
		private void CreateElementsGUI (Menu _menu)
		{	
			if (_menu.elements != null && _menu.elements.Count > 0)
			{
				foreach (MenuElement _element in _menu.elements)
				{
					if (_element != null)
					{
						string elementName = _element.title;
						
						if (elementName == "")
						{
							elementName = "(Untitled)";
						}
						
						EditorGUILayout.BeginHorizontal ();
						
							if (GUILayout.Toggle (_element.isEditing, _element.ID + ": " + elementName, "Button"))
							{
								if (selectedMenuElement != _element)
								{
									DeactivateAllElements (_menu);
									ActivateElement (_element);
								}
							}

							if (GUILayout.Button (icon, GUILayout.Width (20f), GUILayout.Height (15f)))
							{
								SideMenu (_menu, _element);
							}
					
						EditorGUILayout.EndHorizontal ();
					}
				}
			}

			EditorGUILayout.BeginHorizontal ();
				EditorGUILayout.LabelField ("Element type:", GUILayout.Width (80f));
				typeNumber = EditorGUILayout.Popup (typeNumber, elementTypes);
				
				if (GUILayout.Button ("Add new"))
				{
					AddElement (elementTypes[typeNumber], _menu);
				}

				if (copiedElement != null)
				{
					if (GUILayout.Button ("Paste"))
					{
						PasteElement (menus.IndexOf (_menu), _menu.elements.Count -1);
					}
				}
			EditorGUILayout.EndHorizontal ();
		}
Пример #16
0
        private void MenuCallback(object obj)
        {
            if (sideMenu >= 0)
            {
                switch (obj.ToString ())
                {
                case "Copy":
                    MenuManager.copiedMenu = menus[sideMenu];
                    break;

                case "Paste after":
                    PasteMenu (sideMenu);
                    break;

                case "Insert after":
                    Undo.RecordObject (this, "Insert menu");
                    Menu newMenu = (Menu) CreateInstance <Menu>();
                    newMenu.Declare (GetIDArray ());
                    menus.Insert (sideMenu+1, newMenu);

                    DeactivateAllMenus ();
                    ActivateMenu (newMenu);

                    newMenu.hideFlags = HideFlags.HideInHierarchy;
                    AssetDatabase.AddObjectToAsset (newMenu, this);
                    AssetDatabase.ImportAsset (AssetDatabase.GetAssetPath (newMenu));
                    break;

                case "Delete":
                    Undo.RecordObject (this, "Delete menu");
                    if (menus[sideMenu] == selectedMenu)
                    {
                        DeactivateAllElements (menus[sideMenu]);
                        DeleteAllElements (menus[sideMenu]);
                        selectedMenuElement = null;
                    }
                    DeactivateAllMenus ();
                    Menu tempMenu = menus[sideMenu];
                    foreach (MenuElement element in tempMenu.elements)
                    {
                        UnityEngine.Object.DestroyImmediate (element, true);
                    }
                    menus.RemoveAt (sideMenu);
                    UnityEngine.Object.DestroyImmediate (tempMenu, true);
                    AssetDatabase.SaveAssets ();
                    CleanUpAsset ();
                    break;

                case "Move up":
                    Undo.RecordObject (this, "Move menu up");
                    menus = SwapMenus (menus, sideMenu, sideMenu-1);
                    menus[sideMenu].ResetVisibleElements ();
                    AssetDatabase.SaveAssets ();
                    break;

                case "Move down":
                    Undo.RecordObject (this, "Move menu down");
                    menus = SwapMenus (menus, sideMenu, sideMenu+1);
                    menus[sideMenu].ResetVisibleElements ();
                    AssetDatabase.SaveAssets ();
                    break;

                case "Move to top":
                    Undo.RecordObject (this, "Move menu to top");
                    menus = MoveMenuToTop (menus, sideMenu);
                    menus[sideMenu].ResetVisibleElements ();
                    AssetDatabase.SaveAssets ();
                    break;

                case "Move to bottom":
                    Undo.RecordObject (this, "Move menu to bottom");
                    menus = MoveMenuToBottom (menus, sideMenu);
                    menus[sideMenu].ResetVisibleElements ();
                    AssetDatabase.SaveAssets ();
                    break;
                }
            }

            sideMenu = -1;
            sideElement = -1;
            SaveAllMenus ();
        }
Пример #17
0
		public void StartDrag (Menu _menu)
		{
			menuToDrag = _menu;

			if (dragType == DragElementType.SingleElement)
			{
				if (elementName != "")
				{
					MenuElement element = PlayerMenus.GetElementWithName (_menu.title, elementName);
					if (element == null)
					{
						Debug.LogWarning ("Cannot drag " + elementName + " as it cannot be found on " + _menu.title);
					}
					else if (element.positionType == AC_PositionType2.Aligned)
					{
						Debug.LogWarning ("Cannot drag " + elementName + " as it's Position is set to Aligned");
					}
					else if (_menu.sizeType == AC_SizeType.Automatic)
					{
						Debug.LogWarning ("Cannot drag " + elementName + " as it's parent Menu's Size is set to Automatic");
					}
					else
					{
						elementToDrag = element;
						dragStartPosition = elementToDrag.GetDragStart ();
					}
				}
			}
			else
			{
				dragStartPosition = _menu.GetDragStart ();
			}
		}