public override void OnInspectorGUI() { GraphUpdateScene script = target as GraphUpdateScene; #if !UNITY_LE_4_3 Undo.RecordObject(script, "modify settings on GraphUpdateObject"); #endif if (script.points == null) { script.points = new Vector3[0]; } if (script.points == null || script.points.Length == 0) { if (script.GetComponent <Collider>() != null) { EditorGUILayout.HelpBox("No points, using collider.bounds", MessageType.Info); } else if (script.GetComponent <Renderer>() != null) { EditorGUILayout.HelpBox("No points, using renderer.bounds", MessageType.Info); } else { EditorGUILayout.HelpBox("No points and no collider or renderer attached, will not affect anything\nPoints can be added using the transform tool and holding shift", MessageType.Warning); } } Vector3[] prePoints = script.points; #if UNITY_4 EditorGUILayout.PropertyField(serializedObject.FindProperty("points"), true); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); } #else DrawDefaultInspector(); #endif #if UNITY_LE_4_3 EditorGUI.indentLevel = 1; #else EditorGUI.indentLevel = 0; #endif script.updatePhysics = EditorGUILayout.Toggle(new GUIContent("Update Physics", "Perform similar calculations on the nodes as during scan.\n" + "Grid Graphs will update the position of the nodes and also check walkability using collision.\nSee online documentation for more info."), script.updatePhysics); if (script.updatePhysics) { EditorGUI.indentLevel++; script.resetPenaltyOnPhysics = EditorGUILayout.Toggle(new GUIContent("Reset Penalty On Physics", "Will reset the penalty to the default value during the update."), script.resetPenaltyOnPhysics); EditorGUI.indentLevel--; } script.updateErosion = EditorGUILayout.Toggle(new GUIContent("Update Erosion", "Recalculate erosion for grid graphs.\nSee online documentation for more info"), script.updateErosion); if (prePoints != script.points) { script.RecalcConvex(); HandleUtility.Repaint(); } bool preConvex = script.convex; script.convex = EditorGUILayout.Toggle(new GUIContent("Convex", "Sets if only the convex hull of the points should be used or the whole polygon"), script.convex); if (script.convex != preConvex) { script.RecalcConvex(); HandleUtility.Repaint(); } script.minBoundsHeight = EditorGUILayout.FloatField(new GUIContent("Min Bounds Height", "Defines a minimum height to be used for the bounds of the GUO.\nUseful if you define points in 2D (which would give height 0)"), script.minBoundsHeight); script.applyOnStart = EditorGUILayout.Toggle("Apply On Start", script.applyOnStart); script.applyOnScan = EditorGUILayout.Toggle("Apply On Scan", script.applyOnScan); script.modifyWalkability = EditorGUILayout.Toggle(new GUIContent("Modify walkability", "If true, walkability of all nodes will be modified"), script.modifyWalkability); if (script.modifyWalkability) { EditorGUI.indentLevel++; script.setWalkability = EditorGUILayout.Toggle(new GUIContent("Walkability", "Nodes' walkability will be set to this value"), script.setWalkability); EditorGUI.indentLevel--; } script.penaltyDelta = EditorGUILayout.IntField(new GUIContent("Penalty Delta", "A penalty will be added to the nodes, usually you need very large values, at least 1000-10000.\n" + "A higher penalty will mean that agents will try to avoid those nodes."), script.penaltyDelta); if (script.penaltyDelta < 0) { EditorGUILayout.HelpBox("Be careful when lowering the penalty. Negative penalties are not supported and will instead underflow and get really high.\n" + "You can set an initial penalty on graphs (see their settings) and then lower them like this to get regions which are easier to traverse.", MessageType.Warning); } script.modifyTag = EditorGUILayout.Toggle(new GUIContent("Modify Tags", "Should the tags of the nodes be modified"), script.modifyTag); if (script.modifyTag) { EditorGUI.indentLevel++; script.setTag = EditorGUILayout.Popup("Set Tag", script.setTag, AstarPath.FindTagNames()); EditorGUI.indentLevel--; } if (GUILayout.Button("Tags can be used to restrict which units can walk on what ground. Click here for more info", "HelpBox")) { Application.OpenURL(AstarPathEditor.GetURL("tags")); } EditorGUILayout.Separator(); bool worldSpace = EditorGUILayout.Toggle(new GUIContent("Use World Space", "Specify coordinates in world space or local space. When using local space you can move the GameObject " + "around and the points will follow.\n" + "Some operations, like calculating the convex hull, and snapping to Y will change axis depending on how the object is rotated if world space is not used." ), script.useWorldSpace); if (worldSpace != script.useWorldSpace) { #if !UNITY_LE_4_3 Undo.RecordObject(script, "switch use-world-space"); #endif script.ToggleUseWorldSpace(); } #if UNITY_4 EditorGUI.BeginChangeCheck(); #endif script.lockToY = EditorGUILayout.Toggle("Lock to Y", script.lockToY); if (script.lockToY) { EditorGUI.indentLevel++; script.lockToYValue = EditorGUILayout.FloatField("Lock to Y value", script.lockToYValue); EditorGUI.indentLevel--; #if !UNITY_LE_4_3 if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(script, "change Y locking"); } #endif script.LockToY(); } EditorGUILayout.Separator(); if (GUILayout.Button("Clear all points")) { #if UNITY_LE_4_3 Undo.RegisterUndo(script, "Removed All Points"); #endif script.points = new Vector3[0]; EditorUtility.SetDirty(target); script.RecalcConvex(); } if (GUI.changed) { #if UNITY_LE_4_3 Undo.RegisterUndo(script, "Modify Settings on GraphUpdateObject"); #endif EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { GraphUpdateScene script = target as GraphUpdateScene; if (script.points == null) { script.points = new Vector3[0]; } Vector3[] prePoints = script.points; DrawDefaultInspector(); EditorGUI.indentLevel = 1; if (prePoints != script.points) { script.RecalcConvex(); HandleUtility.Repaint(); } bool preConvex = script.convex; script.convex = EditorGUILayout.Toggle(new GUIContent("Convex", "Sets if only the convex hull of the points should be used or the whole polygon"), script.convex); if (script.convex != preConvex) { script.RecalcConvex(); HandleUtility.Repaint(); } script.minBoundsHeight = EditorGUILayout.FloatField(new GUIContent("Min Bounds Height", "Defines a minimum height to be used for the bounds of the GUO.\nUseful if you define points in 2D (which would give height 0)"), script.minBoundsHeight); script.applyOnStart = EditorGUILayout.Toggle("Apply On Start", script.applyOnStart); script.applyOnScan = EditorGUILayout.Toggle("Apply On Scan", script.applyOnScan); script.modifyWalkability = EditorGUILayout.Toggle("Modify walkability", script.modifyWalkability); if (script.modifyWalkability) { EditorGUI.indentLevel++; script.setWalkability = EditorGUILayout.Toggle("Walkability", script.setWalkability); EditorGUI.indentLevel--; } script.penaltyDelta = EditorGUILayout.IntField("Penalty Delta", script.penaltyDelta); if (script.penaltyDelta < 0) { GUILayout.Label("Be careful when lowering the penalty. Negative penalties are not supported and will instead underflow and get really high.", "HelpBox"); } bool worldSpace = EditorGUILayout.Toggle(new GUIContent("Use World Space", "Specify coordinates in world space or local space. When using local space you can move the GameObject around and the points will follow" ), script.useWorldSpace); if (worldSpace != script.useWorldSpace) { script.ToggleUseWorldSpace(); } script.modifyTag = EditorGUILayout.Toggle(new GUIContent("Modify Tags", "Should the tags of the nodes be modified"), script.modifyTag); if (script.modifyTag) { EditorGUI.indentLevel++; script.setTag = EditorGUILayout.Popup("Set Tag", script.setTag, AstarPath.FindTagNames()); EditorGUI.indentLevel--; } //GUI.color = Color.red; if (GUILayout.Button("Tags can be used to restrict which units can walk on what ground. Click here for more info", "HelpBox")) { Application.OpenURL(AstarPathEditor.GetURL("tags")); } //GUI.color = Color.white; EditorGUILayout.Separator(); //GUILayout.Space (0); //GUI.Toggle (r,script.lockToY,"","Button"); script.lockToY = EditorGUILayout.Toggle("Lock to Y", script.lockToY); if (script.lockToY) { EditorGUI.indentLevel++; script.lockToYValue = EditorGUILayout.FloatField("Lock to Y value", script.lockToYValue); EditorGUI.indentLevel--; script.LockToY(); } EditorGUILayout.Separator(); if (GUI.changed) { Undo.RegisterUndo(script, "Modify Settings on GraphUpdateObject"); EditorUtility.SetDirty(target); } if (GUILayout.Button("Clear all points")) { Undo.RegisterUndo(script, "Removed All Points"); script.points = new Vector3[0]; script.RecalcConvex(); } }