public static Color GetUISafeTextColorGreen()
		{
			return HEU_EditorUI.IsEditorDarkSkin() ? Color.green : new Color(0.1f, 0.4f, 0.1f);
		}
		public static Color GetUISafeTextColorRed()
		{
			return HEU_EditorUI.IsEditorDarkSkin() ? Color.magenta : Color.red;
		}
Esempio n. 3
0
		/// <summary>
		/// Draw the Generate section.
		/// </summary>
		private static bool DrawGenerateSection(HEU_HoudiniAssetRoot assetRoot, SerializedObject assetRootSerializedObject, HEU_HoudiniAsset asset, SerializedObject assetObject)
		{
			bool bSkipDrawing = false;

			float separatorDistance = 5f;

			float screenWidth = EditorGUIUtility.currentViewWidth;

			float buttonHeight = 30f;
			float widthPadding = 55f;
			float doubleButtonWidth = Mathf.Round(screenWidth - widthPadding + separatorDistance);
			float singleButtonWidth = Mathf.Round((screenWidth - widthPadding) * 0.5f);

			GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
			buttonStyle.fontStyle = FontStyle.Bold;
			buttonStyle.fontSize = 11;
			buttonStyle.alignment = TextAnchor.MiddleLeft;
			buttonStyle.fixedHeight = buttonHeight;
			buttonStyle.padding.left = 6;
			buttonStyle.padding.right = 6;
			buttonStyle.margin.left = 0;
			buttonStyle.margin.right = 0;

			GUIStyle centredButtonStyle = new GUIStyle(buttonStyle);
			centredButtonStyle.alignment = TextAnchor.MiddleCenter;

			GUIStyle buttonSetStyle = new GUIStyle(GUI.skin.box);
			RectOffset br = buttonSetStyle.margin;
			br.left = 4;
			br.right = 4;
			buttonSetStyle.margin = br;

			GUIStyle boxStyle = new GUIStyle(GUI.skin.GetStyle("ColorPickerBackground"));
			br = boxStyle.margin;
			br.left = 4;
			br.right = 4;
			boxStyle.margin = br;
			boxStyle.padding = br;

			GUIStyle promptButtonStyle = new GUIStyle(GUI.skin.button);
			promptButtonStyle.fontSize = 11;
			promptButtonStyle.alignment = TextAnchor.MiddleCenter;
			promptButtonStyle.fixedHeight = 30;
			promptButtonStyle.margin.left = 34;
			promptButtonStyle.margin.right = 34;

			_recookhdaContent.text = "  Recook Asset";

			HEU_HoudiniAsset.AssetBuildAction pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.NONE;
			SerializedProperty pendingBuildProperty = HEU_EditorUtility.GetSerializedProperty(assetObject, "_requestBuildAction");
			if (pendingBuildProperty != null)
			{
				pendingBuildAction = (HEU_HoudiniAsset.AssetBuildAction)pendingBuildProperty.enumValueIndex;
			}

			// Track changes for the build and bake targets
			EditorGUI.BeginChangeCheck();

			HEU_HoudiniAsset.AssetCookStatus cookStatus = GetCookStatusFromSerializedAsset(assetObject);

			if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.SELECT_SUBASSET)
			{
				// Prompt user to select subasset

				GUIStyle promptStyle = new GUIStyle(GUI.skin.label);
				promptStyle.fontStyle = FontStyle.Bold;
				promptStyle.normal.textColor = HEU_EditorUI.IsEditorDarkSkin() ? Color.green : Color.blue;
				EditorGUILayout.LabelField("SELECT AN ASSET TO INSTANTIATE:", promptStyle);

				EditorGUILayout.Separator();

				int selectedIndex = -1;
				string[] subassetNames = asset.SubassetNames;

				for (int i = 0; i < subassetNames.Length; ++i)
				{
					if (GUILayout.Button(subassetNames[i], promptButtonStyle))
					{
						selectedIndex = i;
						break;
					}

					EditorGUILayout.Separator();
				}

				if (selectedIndex >= 0)
				{
					SerializedProperty selectedIndexProperty = HEU_EditorUtility.GetSerializedProperty(assetObject, "_selectedSubassetIndex");
					if (selectedIndexProperty != null)
					{
						selectedIndexProperty.intValue = selectedIndex;
					}
				}

				bSkipDrawing = true;
			}
			else
			{
				HEU_EditorUI.BeginSection();
				{
					if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.COOKING || cookStatus == HEU_HoudiniAsset.AssetCookStatus.POSTCOOK)
					{
						_recookhdaContent.text = "  Cooking Asset";
					}
					else if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.LOADING || cookStatus == HEU_HoudiniAsset.AssetCookStatus.POSTLOAD)
					{
						_reloadhdaContent.text = "  Loading Asset";
					}

					SerializedProperty showGenerateProperty = assetObject.FindProperty("_showGenerateSection");

					showGenerateProperty.boolValue = HEU_EditorUI.DrawFoldOut(showGenerateProperty.boolValue, "GENERATE");
					if (showGenerateProperty.boolValue)
					{
						//bool bHasPendingAction = (pendingBuildAction != HEU_HoudiniAsset.AssetBuildAction.NONE) || (cookStatus != HEU_HoudiniAsset.AssetCookStatus.NONE);

						HEU_EditorUI.DrawSeparator();

						//EditorGUI.BeginDisabledGroup(bHasPendingAction);

						using (var hs = new EditorGUILayout.HorizontalScope(boxStyle))
						{
							if (GUILayout.Button(_reloadhdaContent, buttonStyle, GUILayout.Width(singleButtonWidth)))
							{
								pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.RELOAD;
								bSkipDrawing = true;
							}

							GUILayout.Space(separatorDistance);

							if (!bSkipDrawing && GUILayout.Button(_recookhdaContent, buttonStyle, GUILayout.Width(singleButtonWidth)))
							{
								pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.COOK;
								bSkipDrawing = true;
							}
						}

						using (var hs = new EditorGUILayout.HorizontalScope(boxStyle))
						{
							float tripleButtonWidth = Mathf.Round((screenWidth - widthPadding) * 0.33f);

							if (GUILayout.Button(_removeheContent, buttonStyle, GUILayout.Width(tripleButtonWidth)))
							{
								pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.STRIP_HEDATA;
								bSkipDrawing = true;
							}

							GUILayout.Space(separatorDistance);

							if (GUILayout.Button(_duplicateContent, buttonStyle, GUILayout.Width(tripleButtonWidth)))
							{
								pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.DUPLICATE;
								bSkipDrawing = true;
							}

							GUILayout.Space(separatorDistance);

							if (GUILayout.Button(_resetParamContent, buttonStyle, GUILayout.Width(tripleButtonWidth)))
							{
								pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.RESET_PARAMS;
								bSkipDrawing = true;
							}
						}

						//EditorGUI.EndDisabledGroup();

						HEU_EditorUI.DrawSeparator();
					}
				}

				HEU_EditorUI.EndSection();

				HEU_EditorUI.DrawSeparator();

				HEU_EditorUI.BeginSection();
				{
					SerializedProperty showBakeProperty = assetObject.FindProperty("_showBakeSection");

					showBakeProperty.boolValue = HEU_EditorUI.DrawFoldOut(showBakeProperty.boolValue, "BAKE");
					if (showBakeProperty.boolValue)
					{
						if (!bSkipDrawing)
						{
							// Bake -> New Instance, New Prefab, Existing instance or prefab

							using (var vs = new EditorGUILayout.HorizontalScope(boxStyle))
							{
								if (GUILayout.Button(_bakegameobjectContent, buttonStyle, GUILayout.Width(singleButtonWidth)))
								{
									asset.BakeToNewStandalone();
								}

								GUILayout.Space(separatorDistance);

								if (GUILayout.Button(_bakeprefabContent, buttonStyle, GUILayout.Width(singleButtonWidth)))
								{
									asset.BakeToNewPrefab();
								}
							}

							HEU_EditorUI.DrawSeparator();

							using (var hs2 = new EditorGUILayout.VerticalScope(boxStyle))
							{
								if (GUILayout.Button(_bakeandreplaceContent, centredButtonStyle, GUILayout.Width(doubleButtonWidth)))
								{
									if (assetRoot._bakeTargets == null || assetRoot._bakeTargets.Count == 0)
									{
										// No bake target means user probably forgot to set one. So complain!
										HEU_EditorUtility.DisplayDialog("No Bake Targets", "Bake Update requires atleast one valid GameObject.\n\nDrag a GameObject or Prefab onto the Drag and drop GameObjects / Prefabs field!", "OK");
									}
									else
									{
										int numTargets = assetRoot._bakeTargets.Count;
										for (int i = 0; i < numTargets; ++i)
										{
											GameObject bakeGO = assetRoot._bakeTargets[i];
											if (bakeGO != null)
											{
												if (HEU_EditorUtility.IsPrefabOriginal(bakeGO))
												{
													// Prefab original means its true prefab, and not an instance of it
													asset.BakeToExistingPrefab(bakeGO);
												}
												else
												{
													// This is for all standalone (including prefab instances)
													asset.BakeToExistingStandalone(bakeGO);
												}
											}
											else
											{
												Debug.LogWarning("Unable to bake to null target at index " + i);
											}
										}
									}
								}

								using (var hs = new EditorGUILayout.VerticalScope(buttonSetStyle))
								{
									SerializedProperty bakeTargetsProp = assetRootSerializedObject.FindProperty("_bakeTargets");
									if (bakeTargetsProp != null)
									{
										EditorGUILayout.PropertyField(bakeTargetsProp, _dragAndDropField, true, GUILayout.Width(doubleButtonWidth - 9f));
									}
								}
							}
						}
					}
				}
				HEU_EditorUI.EndSection();

				HEU_EditorUI.DrawSeparator();

				if (pendingBuildAction != HEU_HoudiniAsset.AssetBuildAction.NONE)
				{
					// Sanity check to make sure the asset is part of the AssetUpater
					HEU_AssetUpdater.AddAssetForUpdate(asset);

					// Apply pending build action based on user UI interaction above
					pendingBuildProperty.enumValueIndex = (int)pendingBuildAction;

					if (pendingBuildAction == HEU_HoudiniAsset.AssetBuildAction.COOK)
					{
						// Recook should only update parameters that haven't changed. Otherwise if not checking and updating parameters,
						// then buttons will trigger callbacks on Recook which is not desired.
						SerializedProperty checkParameterChange = HEU_EditorUtility.GetSerializedProperty(assetObject, "_checkParameterChangeForCook");
						if (checkParameterChange != null)
						{
							checkParameterChange.boolValue = true;
						}
					}
				}
			}
			
			if (EditorGUI.EndChangeCheck())
			{
				assetRootSerializedObject.ApplyModifiedProperties();
				assetObject.ApplyModifiedProperties();
			}

			return bSkipDrawing;
		}
		public static Color GetUISafeTextColorYellow()
		{
			return HEU_EditorUI.IsEditorDarkSkin() ? Color.yellow : Color.blue;
		}
	/// <summary>
	/// Draw the Generate section.
	/// </summary>
	private static bool DrawGenerateSection(HEU_HoudiniAssetRoot assetRoot, 
	    SerializedObject assetRootSerializedObject, 
	    HEU_HoudiniAsset asset, SerializedObject assetObject,
	    ref HEU_HoudiniAsset.AssetBuildAction pendingBuildAction)
	{
	    bool bSkipAutoCook = false;

	    CreateMainButtonStyle();

	    _recookhdaContent.text = "  Recook";

	    HEU_HoudiniAsset.AssetCookStatus cookStatus = GetCookStatusFromSerializedAsset(assetObject);

	    if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.SELECT_SUBASSET)
	    {
		// Prompt user to select subasset

		GUIStyle promptStyle = new GUIStyle(GUI.skin.label);
		promptStyle.fontStyle = FontStyle.Bold;
		promptStyle.normal.textColor = HEU_EditorUI.IsEditorDarkSkin() ? Color.green : Color.blue;
		EditorGUILayout.LabelField("SELECT AN ASSET TO INSTANTIATE:", promptStyle);

		EditorGUILayout.Separator();

		int selectedIndex = -1;
		string[] subassetNames = asset.SubassetNames;

		for (int i = 0; i < subassetNames.Length; ++i)
		{
		    if (GUILayout.Button(subassetNames[i], _mainPromptStyle))
		    {
			selectedIndex = i;
			break;
		    }

		    EditorGUILayout.Separator();
		}

		if (selectedIndex >= 0)
		{
		    SerializedProperty selectedIndexProperty = HEU_EditorUtility.GetSerializedProperty(assetObject, "_selectedSubassetIndex");
		    if (selectedIndexProperty != null)
		    {
			selectedIndexProperty.intValue = selectedIndex;
		    }
		}

		bSkipAutoCook = true;
	    }
	    else
	    {
		HEU_EditorUI.BeginSection();
		{
		    if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.COOKING || cookStatus == HEU_HoudiniAsset.AssetCookStatus.POSTCOOK)
		    {
			_recookhdaContent.text = "  Cooking Asset";
		    }
		    else if (cookStatus == HEU_HoudiniAsset.AssetCookStatus.LOADING || cookStatus == HEU_HoudiniAsset.AssetCookStatus.POSTLOAD)
		    {
			_reloadhdaContent.text = "  Loading Asset";
		    }

		    SerializedProperty showGenerateProperty = assetObject.FindProperty("_showGenerateSection");

		    showGenerateProperty.boolValue = HEU_EditorUI.DrawFoldOut(showGenerateProperty.boolValue, "GENERATE");
		    if (showGenerateProperty.boolValue)
		    {
			HEU_EditorUI.DrawSeparator();

			using (var hs = new EditorGUILayout.HorizontalScope(_mainBoxStyle))
			{
			    if (GUILayout.Button(_reloadhdaContent, _mainButtonStyle))
			    {
				pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.RELOAD;
				bSkipAutoCook = true;
			    }

			    GUILayout.Space(_mainButtonSeparatorDistance);

			    if (!bSkipAutoCook && GUILayout.Button(_recookhdaContent, _mainButtonStyle))
			    {
				pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.COOK;
				bSkipAutoCook = true;
			    }
			}

			using (var hs = new EditorGUILayout.HorizontalScope(_mainBoxStyle))
			{
			    if (GUILayout.Button(_duplicateContent, _mainButtonStyle))
			    {
				pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.DUPLICATE;
				bSkipAutoCook = true;
			    }

			    GUILayout.Space(_mainButtonSeparatorDistance);

			    if (GUILayout.Button(_resetParamContent, _mainButtonStyle))
			    {
				pendingBuildAction = HEU_HoudiniAsset.AssetBuildAction.RESET_PARAMS;
				bSkipAutoCook = true;
			    }
			}
		    }
		}

		HEU_EditorUI.EndSection();
	    }

	    HEU_EditorUI.DrawSeparator();

	    return bSkipAutoCook;
	}