//auto-add to WaypointManager void Awake() { WaypointManager.AddPath(gameObject); }
public override void OnInspectorGUI() { //show default variables of manager DrawDefaultInspector(); //get manager reference script = (WaypointManager)target; EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //get sceneview to auto-detect 2D mode SceneView view = GetSceneView(); mode2D = view.in2DMode; EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); //draw path text label GUILayout.Label("Enter Path Name: ", GUILayout.Height(15)); //display text field for creating a path with that name pathName = EditorGUILayout.TextField(pathName, GUILayout.Height(15)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); //draw path type selection enum GUILayout.Label("Select Path Type: ", GUILayout.Height(15)); pathType = (PathType)EditorGUILayout.EnumPopup(pathType); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); //display label of current mode if (mode2D) { GUILayout.Label("2D Mode Detected.", GUILayout.Height(15)); } else { GUILayout.Label("3D Mode Detected.", GUILayout.Height(15)); } EditorGUILayout.Space(); //draw path creation button if (!placing && GUILayout.Button("Start Path", GUILayout.Height(40))) { if (pathName == "") { EditorUtility.DisplayDialog("No Path Name", "Please enter a unique name for your path.", "Ok"); return; } if (script.transform.Find(pathName) != null) { if (EditorUtility.DisplayDialog("Path Exists Already", "A path with this name exists already.\n\nWould you like to edit it?", "Ok", "Cancel")) { Selection.activeTransform = script.transform.Find(pathName); } return; } //create a new container transform which will hold all new waypoints path = new GameObject(pathName); //reset position and parent container gameobject to this manager gameobject path.transform.position = script.gameObject.transform.position; path.transform.parent = script.gameObject.transform; StartPath(); //we passed all prior checks, toggle waypoint placement placing = true; //focus sceneview for placement view.Focus(); } GUI.backgroundColor = Color.yellow; //finish path button if (placing && GUILayout.Button("Finish Editing", GUILayout.Height(40))) { FinishPath(); } GUI.backgroundColor = Color.white; EditorGUILayout.Space(); //draw instructions GUILayout.TextArea("Hint:\nEnter a unique name for your path, " + "then press 'Start Path' to begin placement mode. Press '" + script.placementKey + "' on your keyboard to place new waypoints in the Scene view. In 3D Mode " + "you have to place waypoints onto game objects with colliders. You can " + "also place waypoints at the current scene view camera position by pressing '" + script.viewPlacementKey + "'.\n\nPress 'Finish Editing' to end your path."); }
public override void OnInspectorGUI() { //don't draw inspector fields if the path contains less than 2 points //(a path with less than 2 points really isn't a path) if (script.bPoints.Count < 2) { //button to create path manually if (GUILayout.Button("Create Path from Children")) { Undo.RecordObject(script, "Create Path"); script.Create(); SceneView.RepaintAll(); } return; } //create new checkboxes for path gizmo property script.showHandles = EditorGUILayout.Toggle("Show Handles", script.showHandles); script.connectHandles = EditorGUILayout.Toggle("Connect Handles", script.connectHandles); script.drawCurved = EditorGUILayout.Toggle("Draw Smooth Lines", script.drawCurved); script.drawDirection = EditorGUILayout.Toggle("Draw Direction", script.drawDirection); //create new color fields for editing path gizmo colors script.color1 = EditorGUILayout.ColorField("Color1", script.color1); script.color2 = EditorGUILayout.ColorField("Color2", script.color2); script.color3 = EditorGUILayout.ColorField("Color3", script.color3); //calculate path length of all waypoints float pathLength = WaypointManager.GetPathLength(script.pathPoints); GUILayout.Label("Path Length: " + pathLength); float thisDetail = script.pathDetail; //slider to modify the smoothing factor of the final path, //round because of path point imprecision placement (micro loops) script.pathDetail = EditorGUILayout.Slider("Path Detail", script.pathDetail, 0.5f, 10); script.pathDetail = Mathf.Round(script.pathDetail * 10f) / 10f; //toggle custom detail when modifying the whole path if (thisDetail != script.pathDetail) { script.customDetail = false; } //draw custom detail settings DetailSettings(); //button for switching over to the WaypointManager for further path editing if (GUILayout.Button("Continue Editing")) { Selection.activeGameObject = (GameObject.FindObjectOfType(typeof(WaypointManager)) as WaypointManager).gameObject; WaypointEditor.ContinuePath(script); } //more path modifiers DrawPathOptions(); EditorGUILayout.Space(); //waypoint index header GUILayout.Label("Waypoints: ", EditorStyles.boldLabel); //loop through the waypoint array for (int i = 0; i < script.bPoints.Count; i++) { GUILayout.BeginHorizontal(); //indicate each array slot with index number in front of it GUILayout.Label(i + ".", GUILayout.Width(20)); //create an object field for every waypoint EditorGUILayout.ObjectField(script.bPoints[i].wp, typeof(Transform), true); //display an "Add Waypoint" button for every array row except the last one //on click we call AddWaypointAtIndex() to insert a new waypoint slot AFTER the selected slot if (i < script.bPoints.Count && GUILayout.Button("+", GUILayout.Width(30f))) { AddWaypointAtIndex(i); break; } //display an "Remove Waypoint" button for every array row except the first and last one //on click we call RemoveWaypointAtIndex() to delete the selected waypoint slot if (i > 0 && i < script.bPoints.Count - 1 && GUILayout.Button("-", GUILayout.Width(30f))) { RemoveWaypointAtIndex(i); break; } GUILayout.EndHorizontal(); } //recalculate on inspector changes if (GUI.changed) { script.CalculatePath(); EditorUtility.SetDirty(target); } }