/// <summary> /// Draws a GUI for a game object chance table. Allowing for addition/removal of rows and /// modification of values and weights /// </summary> /// <param name="table">The table to draw</param> public static void DrawGameObjectChanceTableGUI(string objectName, GameObjectChanceTable table, List <bool> showWeights, bool allowSceneObjects = false) { string title = string.Format("{0} Weights ({1})", objectName, table.Weights.Count); EditorGUILayout.LabelField(title, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; int toDeleteIndex = -1; GUILayout.BeginVertical("box"); for (int i = 0; i < table.Weights.Count; i++) { var w = table.Weights[i]; GUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); w.Value = (GameObject)EditorGUILayout.ObjectField("", w.Value, typeof(GameObject), allowSceneObjects); if (GUILayout.Button("x", EditorStyles.miniButton, EditorConstants.SmallButtonWidth)) { toDeleteIndex = i; } EditorGUILayout.EndHorizontal(); showWeights[i] = EditorGUILayout.Foldout(showWeights[i], "Weights"); if (showWeights[i]) { w.MainPathWeight = EditorGUILayout.FloatField("Main Path", w.MainPathWeight); w.BranchPathWeight = EditorGUILayout.FloatField("Branch Path", w.BranchPathWeight); if (w.UseDepthScale) { w.DepthWeightScale = EditorGUILayout.CurveField("Depth Scale", w.DepthWeightScale, Color.white, new Rect(0, 0, 1, 1)); } } GUILayout.EndVertical(); } if (toDeleteIndex >= 0) { table.Weights.RemoveAt(toDeleteIndex); showWeights.RemoveAt(toDeleteIndex); } if (GUILayout.Button("Add New " + objectName)) { table.Weights.Add(new GameObjectChance() { UseDepthScale = true }); showWeights.Add(false); } EditorGUILayout.EndVertical(); }
/// <summary> /// Draws a GUI for a game object chance table. Allowing for addition/removal of rows and /// modification of values and weights /// </summary> /// <param name="table">The table to draw</param> public static void DrawGameObjectChanceTableGUI(string objectName, GameObjectChanceTable table, List <bool> showWeights, bool allowSceneObjects, bool allowAssetObjects) { string title = string.Format("{0} Weights ({1})", objectName, table.Weights.Count); EditorGUILayout.LabelField(title, EditorStyles.boldLabel); EditorGUI.indentLevel = 1; int toDeleteIndex = -1; GUILayout.BeginVertical("box"); for (int i = 0; i < table.Weights.Count; i++) { var w = table.Weights[i]; GUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); var obj = (GameObject)EditorGUILayout.ObjectField("", w.Value, typeof(GameObject), allowSceneObjects); if (obj != null) { bool isAsset = EditorUtility.IsPersistent(obj); if (allowAssetObjects && isAsset || allowSceneObjects && !isAsset) { w.Value = obj; } } else { w.Value = null; } if (GUILayout.Button("x", EditorStyles.miniButton, InspectorConstants.SmallButtonWidth)) { toDeleteIndex = i; } EditorGUILayout.EndHorizontal(); #if UNITY_5_5_OR_NEWER showWeights[i] = EditorGUILayout.Foldout(showWeights[i], "Weights", true); #else showWeights[i] = EditorGUILayout.Foldout(showWeights[i], "Weights"); #endif if (showWeights[i]) { w.MainPathWeight = EditorGUILayout.FloatField("Main Path", w.MainPathWeight); w.BranchPathWeight = EditorGUILayout.FloatField("Branch Path", w.BranchPathWeight); w.DepthWeightScale = EditorGUILayout.CurveField("Depth Scale", w.DepthWeightScale, Color.white, new Rect(0, 0, 1, 1)); } GUILayout.EndVertical(); } if (toDeleteIndex >= 0) { table.Weights.RemoveAt(toDeleteIndex); showWeights.RemoveAt(toDeleteIndex); } if (GUILayout.Button("Add New " + objectName)) { table.Weights.Add(new GameObjectChance()); showWeights.Add(false); } EditorGUILayout.EndVertical(); }