Example #1
0
	public static void ExecuteTool(int toolSlot)
	{
	    if (_currentSelectedShelf < 0 && _currentSelectedShelf >= _shelves.Count)
	    {
		Debug.LogWarning("Invalid shelf selected. Unable to apply tool.");
		return;
	    }

	    if (toolSlot < 0 || toolSlot >= _shelves[_currentSelectedShelf]._tools.Count)
	    {
		Debug.LogWarning("Invalid tool selected. Unable to apply tool.");
		return;
	    }

	    HEU_ShelfToolData toolData = _shelves[_currentSelectedShelf]._tools[toolSlot];

	    GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

	    string assetPath = toolData._assetPath;

	    if (toolData._toolType == HEU_ShelfToolData.ToolType.GENERATOR)
	    {
		Matrix4x4 targetMatrix = HEU_EditorUtility.GetSelectedObjectsMeanTransform();
		Vector3 position = HEU_HAPIUtility.GetPosition(ref targetMatrix);
		Quaternion rotation = HEU_HAPIUtility.GetQuaternion(ref targetMatrix);
		Vector3 scale = HEU_HAPIUtility.GetScale(ref targetMatrix);
		scale = Vector3.one;

		ExecuteToolGenerator(toolData._name, assetPath, position, rotation, scale);
	    }
	    else if (selectedObjects.Length == 0)
	    {
		ExecuteToolNoInput(toolData._name, assetPath);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.OPERATOR_SINGLE)
	    {
		ExecuteToolOperatorSingle(toolData._name, assetPath, selectedObjects);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.OPERATOR_MULTI)
	    {
		ExecuteToolOperatorMultiple(toolData._name, assetPath, selectedObjects);
	    }
	    else if (toolData._toolType == HEU_ShelfToolData.ToolType.BATCH)
	    {
		ExecuteToolBatch(toolData._name, assetPath, selectedObjects);
	    }
	}
Example #2
0
		public static void ExecuteTool(int toolSlot)
		{
			if(toolSlot < 0 || toolSlot >= _tools.Count)
			{
				Debug.LogWarning("Invalid tool selection!");
				return;
			}

			HEU_ShelfToolData toolData = _tools[toolSlot];
			if(toolData.toolType == HEU_ShelfToolData.ToolType.GENARATOR)
			{
				Matrix4x4 targetMatrix = HEU_EditorUtility.GetSelectedObjectsMeanTransform();
				Vector3 position = HEU_HAPIUtility.GetPosition(ref targetMatrix);
				Quaternion rotation = HEU_HAPIUtility.GetQuaternion(ref targetMatrix);
				Vector3 scale = HEU_HAPIUtility.GetScale(ref targetMatrix);
				scale = Vector3.one;

				ExecuteToolGenerator(toolData.name, toolData.assetPath, position, rotation, scale);
			}
			else if(toolData.toolType == HEU_ShelfToolData.ToolType.OPERATOR_SINGLE)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolOperatorSingle(toolData.name, toolData.assetPath, selectedObjects);
			}
			else if (toolData.toolType == HEU_ShelfToolData.ToolType.OPERATOR_MULTI)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolOperatorMultiple(toolData.name, toolData.assetPath, selectedObjects);
			}
			else if (toolData.toolType == HEU_ShelfToolData.ToolType.BATCH)
			{
				GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();

				ExecuteToolBatch(toolData.name, toolData.assetPath, selectedObjects);
			}
		}
		public void OnGUI()
		{
			if (!_initializedUI)
			{
				// Creating of UI elements must happen in OnGUI
				InitializeUIElements();
			}

			bool bChanged = false;

			Color originalBGColor = GUI.backgroundColor;

			bool bRequiresLoad = !HEU_ShelfTools.AreShelvesLoaded();
			if(!bRequiresLoad)
			{
				// Sanity check that textures are still valid. When scene changes, these get invalidated.
				if (_guiContents != null && _guiContents.Length > 0)
				{
					bRequiresLoad = (_guiContents[0].image == null);
				}
			}
			
			if(bRequiresLoad)
			{
				LoadShelves();
			}

			int numTools = 0;

			using (new EditorGUILayout.VerticalScope())
			{
				using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
				{
					if (HEU_ShelfTools.AreShelvesLoaded())
					{
						int currentShelfIndex = HEU_ShelfTools.GetCurrentShelfIndex();

						HEU_Shelf shelf = null;

						using (new EditorGUILayout.HorizontalScope())
						{
							GUILayout.FlexibleSpace();

							if (GUILayout.Button(_addButton, _buttonStyle, GUILayout.MaxWidth(_buttonWidth), GUILayout.MaxHeight(_buttonHeight)))
							{
								string newShelfPath = UnityEditor.EditorUtility.OpenFolderPanel("Add Shelf Folder", "", "");
								if (!string.IsNullOrEmpty(newShelfPath) && HEU_Platform.DoesDirectoryExist(newShelfPath))
								{
									AddNewShelfWindow(newShelfPath);
									bChanged = true;
								}
							}
						}

						using (new EditorGUILayout.HorizontalScope())
						{
							GUILayout.Label("Active Shelf");

							int newShelfIndex = EditorGUILayout.Popup(currentShelfIndex, _shelfNames, _popupStyle);
							if (currentShelfIndex != newShelfIndex)
							{
								// Change shelf
								currentShelfIndex = newShelfIndex;
								HEU_ShelfTools.SetCurrentShelf(currentShelfIndex);
								SelectShelf(currentShelfIndex);
							}

							shelf = HEU_ShelfTools.GetShelf(currentShelfIndex);
							numTools = shelf._tools.Count;

							using (new EditorGUI.DisabledGroupScope(shelf._defaultShelf))
							{
								if (GUILayout.Button(_removeButton, _buttonStyle, GUILayout.MaxWidth(_buttonWidth)))
								{
									HEU_ShelfTools.RemoveShelf(currentShelfIndex);

									HEU_ShelfTools.SaveShelf();
									HEU_ShelfTools.SetReloadShelves();
									bChanged = true;
								}
							}
						}


						HEU_EditorUI.DrawSeparator();

						if (!bChanged)
						{
							using (EditorGUILayout.ScrollViewScope scroll = new EditorGUILayout.ScrollViewScope(_toolButtonScrollPos))
							{
								if (numTools > 0)
								{
									int numXElements = numTools < _toolGridXElements ? numTools : _toolGridXElements;

									_selectedToolIndex = GUILayout.SelectionGrid(_selectedToolIndex, _guiContents, numXElements, _toolGridStyle);
								}
								else
								{
									EditorGUILayout.LabelField("No tools found!");
								}

								_toolButtonScrollPos = scroll.scrollPosition;
							}
						}
					}
				}
				
				bool bValidSelection = (_selectedToolIndex >= 0 && _selectedToolIndex < numTools);
				using (new EditorGUI.DisabledGroupScope(!bValidSelection))
				{
					if(!bValidSelection)
					{
						_applyButton.text = "Select a Tool!";
					}
					else
					{
						GameObject[] selectedObjects = HEU_EditorUtility.GetSelectedObjects();
						if(selectedObjects.Length == 0)
						{
							_applyButton.text = "Create Tool (no input selected)!";
						}
						else
						{
							_applyButton.text = "Create Tool (selected objects as inputs)!";
						}
					}

					if (GUILayout.Button(_applyButton, _buttonStyle, GUILayout.MaxHeight(_buttonHeight)))
					{
						ProcessUserSelection(_selectedToolIndex);
					}
				}
			}
		}