void CreateNode(vWaypointArea wayArea, Vector3 position) { var nodeObj = new GameObject("node"); var node = nodeObj.AddComponent <vWaypoint>(); node.subPoints = new List <vPoint>(); nodeObj.transform.position = position; nodeObj.transform.parent = wayArea.transform; wayArea.waypoints.Add(node); currentNode = node; indexOfWaypoint = wayArea.waypoints.IndexOf(currentNode); }
void OnEnable() { m_Logo = (Texture2D)Resources.Load("icon_v2", typeof(Texture2D)); tool = Tools.current; pathArea = (vWaypointArea)target; editMode = serializedObject.FindProperty("editMode"); if (pathArea.waypoints == null) { pathArea.waypoints = new List <vWaypoint>(); } if (pathArea.waypoints.Count > 0) { currentNode = pathArea.waypoints[0]; } SetVisiblePoints(editMode.boolValue); }
void CreatePatrolPoint(vWaypointArea wayArea, Vector3 position) { if (currentNode) { if (currentNode.subPoints == null) { currentNode.subPoints = new List <vPoint>(); } var nodeObj = new GameObject("patrolPoint"); var node = nodeObj.AddComponent <vPoint>(); nodeObj.transform.position = position; nodeObj.transform.parent = currentNode.transform; currentNode.subPoints.Add(node); indexOfPatrolPoint = currentNode.subPoints.IndexOf(node); } }
void OnEnable() { pathArea = (vWaypointArea)target; if (pathArea.waypoints == null) { pathArea.waypoints = new List <vWaypoint>(); } if (pathArea.waypoints.Count > 0) { currentNode = pathArea.waypoints[0]; } #if UNITY_2017_2_OR_NEWER EditorApplication.pauseStateChanged += HandleOnPlayModeChanged; #else EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged; #endif SetVisiblePoints(false); }
public override void OnInspectorGUI() { if (skin == null) { skin = Resources.Load("skin") as GUISkin; } GUI.skin = skin; _wayArea = new SerializedObject(target); editMode = _wayArea.FindProperty("editMode"); var waypoints = _wayArea.FindProperty("waypoints"); _wayArea.Update(); pathArea = (vWaypointArea)target; GUILayout.BeginVertical("WAYPOINT AREA", "window", GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(true)); GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); if (GUILayout.Button(editMode.boolValue ? "Exit Edit Mode" : "Enter Edit Mode", GUILayout.ExpandWidth(true))) { editMode.boolValue = !editMode.boolValue; SetVisiblePoints(editMode.boolValue); Repaint(); } GUI.color = Color.white; GUI.enabled = editMode.boolValue; EditorGUILayout.Space(); if (editMode.boolValue && pathArea.waypoints.Count == 0) { EditorGUILayout.HelpBox("Starting by holding Shift and Left Click on any surface with a collider.", MessageType.Info); } if (pathArea.waypoints != null && pathArea.waypoints.Count > 0) { for (int i = 0; i < waypoints.arraySize; i++) { GUI.color = (i.Equals(indexOfWaypoint) ? Color.green : Color.white); GUILayout.BeginHorizontal(); if (GUILayout.Button("Waypoint " + (i + 1).ToString("00"), "box", GUILayout.ExpandWidth(true))) { indexOfWaypoint = i; currentNode = pathArea.waypoints[i]; Selection.activeGameObject = currentNode.gameObject; SceneView.lastActiveSceneView.FrameSelected(); Selection.activeGameObject = pathArea.gameObject; } if (!PointIsInNavMesh(pathArea.waypoints[i].transform.position)) { GUI.color = Color.white; EditorGUILayout.HelpBox("Out of NavMesh", MessageType.Error); Repaint(); } if (GUILayout.Button("X", GUILayout.MaxWidth(20), GUILayout.MaxHeight(25))) { RemoveNode(ref waypoints, i); GUILayout.EndVertical(); break; } GUILayout.EndHorizontal(); } } GUI.color = Color.white; if (indexOfWaypoint >= waypoints.arraySize) { indexOfWaypoint = waypoints.arraySize - 1; } try { if (waypoints != null && waypoints.arraySize > 0) { var vPoint = new SerializedObject(waypoints.GetArrayElementAtIndex(indexOfWaypoint).objectReferenceValue as vWaypoint); DrawWaypoint(vPoint, waypoints); } } catch { } GUILayout.EndVertical(); GUI.enabled = true; GUILayout.BeginVertical("HOT KEYS", "window"); GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); hotKeys = GUILayout.Toggle(hotKeys, hotKeys ? "Hide Hot Keys" : "Show Hot Keys", "button", GUILayout.ExpandWidth(true)); if (hotKeys) { GUILayout.BeginVertical("box"); GUI.color = Color.green; GUILayout.Label("Shift + Left Mouse Click", "box"); GUI.color = Color.white; GUILayout.Label("Create New Way Point"); GUILayout.EndVertical(); EditorGUILayout.Separator(); GUILayout.BeginVertical("box"); GUI.color = Color.green; GUILayout.Label("Ctrl + Left Mouse Click", "box"); GUI.color = Color.white; GUILayout.Label("Create New Patrol Point to selected way point"); GUILayout.EndVertical(); EditorGUILayout.Separator(); GUILayout.BeginVertical("box"); GUI.color = Color.green; GUILayout.Label("Shift + Right Mouse Click", "box"); GUI.color = Color.white; GUILayout.Label("Set click point position to way point selected"); GUILayout.EndVertical(); EditorGUILayout.Separator(); GUILayout.BeginVertical("box"); GUI.color = Color.green; GUILayout.Label("Ctrl + Right Mouse Click", "box"); GUI.color = Color.white; GUILayout.Label("Set click point position to patrol point selected"); GUILayout.EndVertical(); EditorGUILayout.Separator(); } EditorGUILayout.Separator(); GUILayout.EndVertical(); if (Event.current.commandName == "UndoRedoPerformed") { Repaint(); } if (GUI.changed) { _wayArea.ApplyModifiedProperties(); EditorUtility.SetDirty(pathArea); } }