public static int TagField(string label, int value) { // Make sure the tagNamesAndEditTagsButton is relatively up to date if (tagNamesAndEditTagsButton == null || EditorApplication.timeSinceStartup - timeLastUpdatedTagNames > 1) { timeLastUpdatedTagNames = EditorApplication.timeSinceStartup; var tagNames = AstarPath.FindTagNames(); tagNamesAndEditTagsButton = new string[tagNames.Length + 1]; tagNames.CopyTo(tagNamesAndEditTagsButton, 0); tagNamesAndEditTagsButton[tagNamesAndEditTagsButton.Length - 1] = "Edit Tags..."; } // Tags are between 0 and 31 value = Mathf.Clamp(value, 0, 31); var newValue = EditorGUILayout.IntPopup(label, value, tagNamesAndEditTagsButton, new [] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, -1 }); // Last element corresponds to the 'Edit Tags...' entry. Open the tag editor if (newValue == -1) { AstarPathEditor.EditTags(); } else { value = newValue; } return(value); }
public static void SetTagField(GUIContent label, ref Pathfinding.TagMask value) { GUILayout.BeginHorizontal(); //Debug.Log (value.ToString ()); #pragma warning disable CS0618 // El tipo o el miembro están obsoletos EditorGUIUtility.LookLikeControls(); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos EditorGUILayout.PrefixLabel(label, EditorStyles.layerMaskField); //GUILayout.FlexibleSpace (); //Rect r = GUILayoutUtility.GetLastRect (); string text = ""; if (value.tagsChange == 0) { text = "Nothing"; } else if (value.tagsChange == ~0) { text = "Everything"; } else { text = System.Convert.ToString(value.tagsChange, 2); } string[] tagNames = AstarPath.FindTagNames(); if (GUILayout.Button(text, EditorStyles.layerMaskField, GUILayout.ExpandWidth(true))) { //Debug.Log ("pre"); GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Everything"), value.tagsChange == ~0, value.SetValues, new Pathfinding.TagMask(~0, value.tagsSet)); menu.AddItem(new GUIContent("Nothing"), value.tagsChange == 0, value.SetValues, new Pathfinding.TagMask(0, value.tagsSet)); for (int i = 0; i < tagNames.Length; i++) { bool on = (value.tagsChange >> i & 0x1) != 0; Pathfinding.TagMask result = new Pathfinding.TagMask(on ? value.tagsChange & ~(1 << i) : value.tagsChange | 1 << i, value.tagsSet); menu.AddItem(new GUIContent(tagNames[i]), on, value.SetValues, result); //value.SetValues (result); } menu.AddItem(new GUIContent("Edit Tags..."), false, AstarPathEditor.EditTags); menu.ShowAsContext(); Event.current.Use(); //Debug.Log ("Post"); } #if UNITY_LE_4_3 EditorGUIUtility.LookLikeInspector(); #endif GUILayout.EndHorizontal(); }
public static int SingleTagField(string label, int value) { string[] tagNames = AstarPath.FindTagNames(); value = value < 0 ? 0 : value; value = value >= tagNames.Length ? tagNames.Length - 1 : value; value = EditorGUILayout.IntPopup(label, value, tagNames, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); return(value); }
public static void TagMaskField(GUIContent label, int value, System.Action <int> callback) { GUILayout.BeginHorizontal(); //EditorGUIUtility.LookLikeControls(); EditorGUIUtility.fieldWidth = 0f; EditorGUIUtility.labelWidth = 0f; EditorGUILayout.PrefixLabel(label, EditorStyles.layerMaskField); string text; if (value == 0) { text = "Nothing"; } else if (value == ~0) { text = "Everything"; } else { text = System.Convert.ToString(value, 2); } string[] tagNames = AstarPath.FindTagNames(); if (GUILayout.Button(text, EditorStyles.layerMaskField, GUILayout.ExpandWidth(true))) { GenericMenu.MenuFunction2 wrappedCallback = obj => callback((int)obj); var menu = new GenericMenu(); menu.AddItem(new GUIContent("Everything"), value == ~0, wrappedCallback, ~0); menu.AddItem(new GUIContent("Nothing"), value == 0, wrappedCallback, 0); for (int i = 0; i < tagNames.Length; i++) { bool on = (value >> i & 1) != 0; int result = on ? value & ~(1 << i) : value | 1 << i; menu.AddItem(new GUIContent(tagNames[i]), on, wrappedCallback, result); } // Shortcut to open the tag editor menu.AddItem(new GUIContent("Edit Tags..."), false, AstarPathEditor.EditTags); menu.ShowAsContext(); Event.current.Use(); } GUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); var script = target as Seeker; Undo.RecordObject(script, "modify settings on Seeker"); // Show a dropdown selector for the tags that this seeker can traverse // A callback is necessary because Unity's GenericMenu uses callbacks EditorGUILayoutx.TagMaskField(new GUIContent("Valid Tags"), script.traversableTags, result => script.traversableTags = result); #if !ASTAR_NoTagPenalty EditorGUI.indentLevel = 0; tagPenaltiesOpen = EditorGUILayout.Foldout(tagPenaltiesOpen, new GUIContent("Tag Penalties", "Penalties for each tag")); if (tagPenaltiesOpen) { EditorGUI.indentLevel = 2; string[] tagNames = AstarPath.FindTagNames(); for (int i = 0; i < script.tagPenalties.Length; i++) { int tmp = EditorGUILayout.IntField((i < tagNames.Length ? tagNames[i] : "Tag " + i), (int)script.tagPenalties[i]); if (tmp < 0) { tmp = 0; } // If the new value is different than the old one // Update the value and mark the script as dirty if (script.tagPenalties[i] != tmp) { script.tagPenalties[i] = tmp; EditorUtility.SetDirty(target); } } if (GUILayout.Button("Edit Tag Names...")) { AstarPathEditor.EditTags(); } } EditorGUI.indentLevel = 1; #endif if (GUI.changed) { EditorUtility.SetDirty(target); } }
public static int SingleTagField(string label, int value) { //GUILayout.BeginHorizontal (); //Debug.Log (value.ToString ()); //EditorGUIUtility.LookLikeControls(); ///EditorGUILayout.PrefixLabel (label,EditorStyles.layerMaskField); //GUILayout.FlexibleSpace (); //Rect r = GUILayoutUtility.GetLastRect (); string[] tagNames = AstarPath.FindTagNames(); value = value < 0 ? 0 : value; value = value >= tagNames.Length ? tagNames.Length - 1 : value; //string text = tagNames[value]; /*if (GUILayout.Button (text,EditorStyles.layerMaskField,GUILayout.ExpandWidth (true))) { * * //Debug.Log ("pre"); * GenericMenu menu = new GenericMenu (); * * for (int i=0;i<tagNames.Length;i++) { * bool on = value == i; * int result = i; * menu.AddItem (new GUIContent (tagNames[i]),on,delegate (System.Object ob) { value = (int)ob; }, result); * //value.SetValues (result); * } * * menu.AddItem (new GUIContent ("Edit Tags..."),false,AstarPathEditor.EditTags); * menu.ShowAsContext (); * * Event.current.Use (); * //Debug.Log ("Post"); * }*/ value = EditorGUILayout.IntPopup(label, value, tagNames, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); //EditorGUIUtility.LookLikeInspector(); //GUILayout.EndHorizontal (); return(value); }
public static void TagMaskField(GUIContent label, int value, System.Action <int> callback) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(label, EditorStyles.layerMaskField); string[] tagNames = AstarPath.FindTagNames(); string text; if (value == 0) { text = "Nothing"; } else if (value == ~0) { text = "Everything"; } else { text = ""; for (int i = 0; i < 32; i++) { if (((value >> i) & 0x1) != 0) { // Add spacing between words if (text.Length > 0) { text += ", "; } text += tagNames[i]; // Too long, just give up if (text.Length > 40) { text = "Mixed..."; break; } } } } if (GUILayout.Button(text, EditorStyles.layerMaskField, GUILayout.ExpandWidth(true))) { GenericMenu.MenuFunction2 wrappedCallback = obj => callback((int)obj); var menu = new GenericMenu(); menu.AddItem(new GUIContent("Everything"), value == ~0, wrappedCallback, ~0); menu.AddItem(new GUIContent("Nothing"), value == 0, wrappedCallback, 0); for (int i = 0; i < tagNames.Length; i++) { bool on = (value >> i & 1) != 0; int result = on ? value & ~(1 << i) : value | 1 << i; menu.AddItem(new GUIContent(tagNames[i]), on, wrappedCallback, result); } // Shortcut to open the tag editor menu.AddItem(new GUIContent("Edit Tag Names..."), false, AstarPathEditor.EditTags); menu.ShowAsContext(); Event.current.Use(); } GUILayout.EndHorizontal(); }
protected override void Inspector() { base.Inspector(); scripts.Clear(); foreach (var script in targets) { scripts.Add(script as Seeker); } Undo.RecordObjects(targets, "Modify settings on Seeker"); var startEndModifierProp = FindProperty("startEndModifier"); startEndModifierProp.isExpanded = EditorGUILayout.Foldout(startEndModifierProp.isExpanded, startEndModifierProp.displayName); if (startEndModifierProp.isExpanded) { EditorGUI.indentLevel++; Popup("startEndModifier.exactStartPoint", exactnessLabels, "Start Point Snapping"); Popup("startEndModifier.exactEndPoint", exactnessLabels, "End Point Snapping"); PropertyField("startEndModifier.addPoints", "Add Points"); if (FindProperty("startEndModifier.exactStartPoint").enumValueIndex == (int)StartEndModifier.Exactness.Original || FindProperty("startEndModifier.exactEndPoint").enumValueIndex == (int)StartEndModifier.Exactness.Original) { if (PropertyField("startEndModifier.useRaycasting", "Physics Raycasting")) { EditorGUI.indentLevel++; PropertyField("startEndModifier.mask", "Layer Mask"); EditorGUI.indentLevel--; EditorGUILayout.HelpBox("Using raycasting to snap the start/end points has largely been superseded by the 'ClosestOnNode' snapping option. It is both faster and usually closer to what you want to achieve.", MessageType.Info); } if (PropertyField("startEndModifier.useGraphRaycasting", "Graph Raycasting")) { EditorGUILayout.HelpBox("Using raycasting to snap the start/end points has largely been superseded by the 'ClosestOnNode' snapping option. It is both faster and usually closer to what you want to achieve.", MessageType.Info); } } EditorGUI.indentLevel--; } // Make sure the AstarPath object is initialized and the graphs are loaded, this is required to be able to show graph names in the mask popup AstarPath.FindAstarPath(); for (int i = 0; i < graphLabels.Length; i++) { if (AstarPath.active == null || AstarPath.active.data.graphs == null || i >= AstarPath.active.data.graphs.Length || AstarPath.active.data.graphs[i] == null) { graphLabels[i] = "Graph " + i + (i == 31 ? "+" : ""); } else { graphLabels[i] = AstarPath.active.data.graphs[i].name + " (graph " + i + ")"; } } Mask("graphMask", graphLabels, "Traversable Graphs"); tagPenaltiesOpen = EditorGUILayout.Foldout(tagPenaltiesOpen, new GUIContent("Tags", "Settings for each tag")); if (tagPenaltiesOpen) { string[] tagNames = AstarPath.FindTagNames(); EditorGUI.indentLevel++; if (tagNames.Length != 32) { tagNames = new string[32]; for (int i = 0; i < tagNames.Length; i++) { tagNames[i] = "" + i; } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Tag", EditorStyles.boldLabel, GUILayout.MaxWidth(120)); for (int i = 0; i < tagNames.Length; i++) { EditorGUILayout.LabelField(tagNames[i], GUILayout.MaxWidth(120)); } // Make sure the arrays are all of the correct size for (int i = 0; i < scripts.Count; i++) { if (scripts[i].tagPenalties == null || scripts[i].tagPenalties.Length != tagNames.Length) { scripts[i].tagPenalties = new int[tagNames.Length]; } } if (GUILayout.Button("Edit names", EditorStyles.miniButton)) { AstarPathEditor.EditTags(); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Penalty", EditorStyles.boldLabel, GUILayout.MaxWidth(100)); var prop = FindProperty("tagPenalties").FindPropertyRelative("Array"); prop.Next(true); for (int i = 0; i < tagNames.Length; i++) { prop.Next(false); EditorGUILayout.PropertyField(prop, GUIContent.none, false, GUILayout.MinWidth(100)); // Penalties should not be negative if (prop.intValue < 0) { prop.intValue = 0; } } if (GUILayout.Button("Reset all", EditorStyles.miniButton)) { for (int i = 0; i < tagNames.Length; i++) { for (int j = 0; j < scripts.Count; j++) { scripts[j].tagPenalties[i] = 0; } } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Traversable", EditorStyles.boldLabel, GUILayout.MaxWidth(100)); for (int i = 0; i < tagNames.Length; i++) { var anyFalse = false; var anyTrue = false; for (int j = 0; j < scripts.Count; j++) { var prevTraversable = ((scripts[j].traversableTags >> i) & 0x1) != 0; anyTrue |= prevTraversable; anyFalse |= !prevTraversable; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = anyTrue & anyFalse; var newTraversable = EditorGUILayout.Toggle(anyTrue); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { for (int j = 0; j < scripts.Count; j++) { scripts[j].traversableTags = (scripts[j].traversableTags & ~(1 << i)) | ((newTraversable ? 1 : 0) << i); } } } if (GUILayout.Button("Set all/none", EditorStyles.miniButton)) { for (int j = scripts.Count - 1; j >= 0; j--) { scripts[j].traversableTags = (scripts[0].traversableTags & 0x1) == 0 ? -1 : 0; } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } }