Example #1
0
		private void SelectShelf(int index)
		{
			int numShelves = HEU_ShelfTools.GetNumShelves();
			if(index >= 0 && index < numShelves)
			{
				HEU_Shelf shelf = HEU_ShelfTools.GetShelf(index);
				if (shelf != null)
				{
					int numTools = shelf._tools.Count;
					_guiContents = new GUIContent[numTools];

					for (int i = 0; i < numTools; ++i)
					{
						_guiContents[i] = new GUIContent();
						_guiContents[i].text = shelf._tools[i]._name;

						if (HEU_Platform.DoesFileExist(shelf._tools[i]._iconPath))
						{
							_guiContents[i].image = HEU_GeneralUtility.LoadTextureFromFile(shelf._tools[i]._iconPath);
						}
						
						_guiContents[i].tooltip = shelf._tools[i]._toolTip;
					}
				}
			}
		}
		private void SelectShelf(int index)
		{
			int numShelves = HEU_ShelfTools.GetNumShelves();
			if(index >= 0 && index < numShelves)
			{
				HEU_Shelf shelf = HEU_ShelfTools.GetShelf(index);
				if (shelf != null)
				{
					int numTools = shelf._tools.Count;
					_guiContents = new GUIContent[numTools];

					for (int i = 0; i < numTools; ++i)
					{
						_guiContents[i] = new GUIContent();
						_guiContents[i].text = shelf._tools[i]._name;

						if (HEU_HAPIUtility.DoesMappedPathExist(shelf._tools[i]._iconPath))
						{
							string realPath = HEU_PluginStorage.Instance.ConvertEnvKeyedPathToReal(shelf._tools[i]._iconPath);
							_guiContents[i].image = HEU_GeneralUtility.LoadTextureFromFile(realPath);
						}
						
						_guiContents[i].tooltip = shelf._tools[i]._toolTip;
					}
				}
			}
		}
Example #3
0
	public void OnGUI()
	{
	    using (new GUILayout.VerticalScope())
	    {
		_shelfName = EditorGUILayout.TextField("New Shelf Name", _shelfName);
		using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(_shelfName) || _shelfName.Trim().Length == 0))
		{
		    if (GUILayout.Button("Create"))
		    {
			//HEU_Logger.Log("Shelf name: " + _shelfName);
			HEU_Shelf newShelf = HEU_ShelfTools.AddShelf(_shelfName, _shelfPath);
			if (newShelf != null)
			{
			    HEU_ShelfTools.SaveShelf();
			    HEU_ShelfTools.SetReloadShelves();
			    this.Close();
			}
			else
			{
			    HEU_Logger.LogError("Invalid Shelf! Please check if the name or path is valid.");
			}
		    }
		}

		if (GUILayout.Button("Cancel"))
		{
		    this.Close();
		}
	    }
	}
Example #4
0
		public static HEU_Shelf AddShelf(string shelfName, string shelfPath)
		{
			HEU_Shelf newShelf = new HEU_Shelf();
			newShelf._shelfName = shelfName;
			newShelf._shelfPath = shelfPath;

			_shelves.Add(newShelf);
			return newShelf;
		}
	public static HEU_Shelf AddShelf(string shelfName, string shelfPath)
	{
	    if (_shelves.Find((HEU_Shelf shelf) => shelf._shelfName == shelfName) != null)
	    {
		return null;
	    }

	    if (!HEU_AssetDatabase.IsValidFolderName(shelfName))
	    {
		return null;
	    }

	    HEU_Shelf newShelf = new HEU_Shelf();
	    newShelf._shelfName = shelfName;
	    newShelf._shelfPath = shelfPath;

	    _shelves.Add(newShelf);
	    return newShelf;
	}
		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);
					}
				}
			}
		}
Example #7
0
		public static void LoadShelves()
		{
			bool bSaveShelf = false;

			_shelves.Clear();

			// Always add the default shelf
			HEU_Shelf defaultShelf = AddShelf(HEU_Defines.HEU_HENGINE_SHIPPED_SHELF, HEU_Defines.HEU_HENGINE_TOOLS_SHIPPED_FOLDER);
			defaultShelf._defaultShelf = true;

			List<string> shelfEntries = HEU_PluginSettings.HEngineToolsShelves;
			if (shelfEntries == null || shelfEntries.Count == 0)
			{
				shelfEntries = new List<string>();
			}

			// Convert shelf path + name to actual shelf objects
			int numShelves = shelfEntries.Count;
			for(int i = 0; i < numShelves; i++)
			{
				string shelfName = "";
				string shelfPath = "";

				GetSplitShelfEntry(shelfEntries[i], out shelfName, out shelfPath);

				// Ignore default shelf because we added it already
				if(shelfPath.Equals(HEU_Defines.HEU_HENGINE_TOOLS_SHIPPED_FOLDER))
				{
					continue;
				}

				if(!string.IsNullOrEmpty(shelfName) && !string.IsNullOrEmpty(shelfPath))
				{
					HEU_Shelf newShelf = new HEU_Shelf();
					newShelf._shelfName = shelfName;
					newShelf._shelfPath = shelfPath;

					_shelves.Add(newShelf);
				}
				else
				{
					Debug.LogWarningFormat("Found invalid shelf with entry: {0}", shelfEntries[i]);
					shelfEntries.RemoveAt(i);
					i--;
					bSaveShelf = true;
				}
			}

			foreach(HEU_Shelf shelf in _shelves)
			{
				string realShelfPath = HEU_HAPIUtility.GetRealPathFromHFSPath(shelf._shelfPath);

				if (!HEU_Platform.DoesPathExist(realShelfPath))
				{
					Debug.LogWarningFormat("Shelf path does not exist: {0}", realShelfPath);
				}
				else
				{
					bool bShelfLoaded = LoadToolsFromDirectory(realShelfPath, out shelf._tools);
					if (!bShelfLoaded)
					{
						Debug.LogWarningFormat("Failed to load shelf {0} at path {1}", shelf._shelfName, realShelfPath);
					}
				}
			}

			_currentSelectedShelf = HEU_PluginSettings.HEngineShelfSelectedIndex;
			if (_currentSelectedShelf < 0 || _currentSelectedShelf >= _shelves.Count)
			{
				_currentSelectedShelf = 0;
				HEU_PluginSettings.HEngineShelfSelectedIndex = _currentSelectedShelf;
			}

			if (bSaveShelf)
			{
				SaveShelf();
			}

			_shelvesLoaded = true;
		}