public static void DrawPath(TrafRoad t) { if (t.waypoints != null && t.waypoints.Count > 0) { var wps = t.waypoints; for (int wp = 0; wp < wps.Count; wp++) { wps[wp].position = Handles.PositionHandle(wps[wp].position, Quaternion.identity); if (wp == 0) { Handles.color = Color.red; } else if (wp == wps.Count - 1) { Handles.color = Color.green; } else { Handles.color = Color.yellow; } Handles.SphereHandleCap(HandleUtility.nearestControl, wps[wp].position, Quaternion.identity, 1f, EventType.Repaint); } Handles.DrawPolyLine(wps.Select(w => w.position).ToArray()); } }
private TrafRoad InitRoadMulti(TrafRoad cursor, float offset, bool reverse) { var r = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; r.waypoints = new List <TrafRoadPoint>(); for (int wp = 0; wp < cursor.waypoints.Count; wp++) { if (wp < cursor.waypoints.Count - 1) { Vector3 tangent = cursor.waypoints[wp + 1].position - cursor.waypoints[wp].position; r.waypoints.Add(new TrafRoadPoint() { position = cursor.waypoints[wp].position + (Quaternion.Euler(0, 90f, 0) * tangent).normalized * offset }); } else { Vector3 tangent = cursor.waypoints[wp].position - cursor.waypoints[wp - 1].position; r.waypoints.Add(new TrafRoadPoint() { position = cursor.waypoints[wp].position + (Quaternion.Euler(0, 90f, 0) * tangent).normalized * offset }); } } if (reverse) { r.waypoints.Reverse(); } return(r); }
public static void DrawPathMultiTHREE(TrafRoad r, float laneWidth) { if (r.waypoints != null && r.waypoints.Count > 0) { var wps = r.waypoints; for (int wp = 0; wp < wps.Count; wp++) { wps[wp].position = Handles.PositionHandle(wps[wp].position, Quaternion.identity); if (wp == 0) { Handles.color = Color.red; } else if (wp == wps.Count - 1) { Handles.color = Color.green; } else { Handles.color = Color.yellow; } if (wp < r.waypoints.Count - 1) { Vector3 tangent = wps[wp + 1].position - wps[wp].position; var offset = (Quaternion.Euler(0, 90f, 0) * tangent); offset.y = 0; offset.Normalize(); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * -1f, Quaternion.identity, 1f); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * 0f, Quaternion.identity, 1f); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * 1f, Quaternion.identity, 1f); } else { Vector3 tangent = wps[wp].position - wps[wp - 1].position; var offset = (Quaternion.Euler(0, 90f, 0) * tangent); offset.y = 0; offset.Normalize(); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * -1f, Quaternion.identity, 1f); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * 0f, Quaternion.identity, 1f); Handles.SphereCap(HandleUtility.nearestControl, wps[wp].position + offset * laneWidth * 1f, Quaternion.identity, 1f); } } Handles.DrawPolyLine(wps.Select(w => w.position).ToArray()); } }
public void InitRoad(TrafRoad road) { var t = road; t.waypoints = new List <TrafRoadPoint>(); var scenecam = SceneView.currentDrawingSceneView.camera; RaycastHit[] hits = Physics.RaycastAll(scenecam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 2f)), 1000f); for (int i = 0; i < hits.Length; i++) { if (t != null) { Vector3 pos = hits[i].point + Vector3.up * terrainOffsetUp; t.waypoints.Add(new TrafRoadPoint { position = pos }); t.waypoints.Add(new TrafRoadPoint { position = pos + Vector3.right * startDisplayOffsetRight }); break; } } }
public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); currentId = EditorGUILayout.IntField("ID", currentId); if (GUILayout.Button("Next Free ID")) { var t = target as TrafSystem; currentId = t.entries.Max(e => e.identifier) + 1; } currentSubId = EditorGUILayout.IntField("SubID", currentSubId); EditorGUILayout.EndHorizontal(); switch (currentState) { case TrafEditState.IDLE: if (GUILayout.Button("DELETE - CAREFUL!")) { var t = target as TrafSystem; t.entries.RemoveAll(e => e.identifier == currentId); } if (GUILayout.Button("new/edit")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId)) { var road = t.entries.Find(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId); currentRoad = road.road; t.entries.Remove(road); currentState = TrafEditState.EDIT; } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT; } } if (GUILayout.Button("new multi one way")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI; } } if (GUILayout.Button("new multi two way")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI_TWOWAY; } } if (GUILayout.Button("Visualize Entries and Intersections")) { currentState = TrafEditState.DISPLAY_ENTRIES_INTERSECTIONS; Debug.Log("Total entry count " + (target as TrafSystem).entries.Count); Debug.Log("Total intersection count " + (target as TrafSystem).intersections.Count); SceneView.RepaintAll(); } if (GUILayout.Button("Visualize Entries")) { currentState = TrafEditState.DISPLAY_ENTRIES; Debug.Log("Total entry count " + (target as TrafSystem).entries.Count); SceneView.RepaintAll(); } if (GUILayout.Button("Visualize Intersections")) { currentState = TrafEditState.DISPLAY_INTERSECTIONS; Debug.Log("Total intersection count " + (target as TrafSystem).intersections.Count); SceneView.RepaintAll(); } if (GUILayout.Button("Register all intersections")) { var t = target as TrafSystem; t.intersections.Clear(); TrafIntersectionEditor.GoAll(t); EditorUtility.SetDirty(target); } if (GUILayout.Button("Deregister all intersections")) { var t = target as TrafSystem; t.intersections.Clear(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Populate all owning entries")) { var t = target as TrafSystem; foreach (var i in t.intersections) { if (i.intersection != null) { i.intersection.owningEntry = i; } } EditorUtility.SetDirty(target); } if (GUILayout.Button("Generate RoadGraph")) { GenerateRoadGraph(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Clear RoadGraph")) { var t = target as TrafSystem; t.roadGraph = new TrafRoadGraph(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Remove Markers")) { var t = target as TrafSystem; foreach (var g in t.GetComponentsInChildren <Renderer>()) { g.enabled = false; } } if (GUILayout.Button("TEMP")) { var t = target as TrafSystem; foreach (var e in t.entries) { if (e.road != null) { e.waypoints = new List <Vector3>(); foreach (var v in e.road.waypoints) { e.waypoints.Add(v.position); } } } } if (GUILayout.Button("Localize Waypoint World Transformations")) { var t = target as TrafSystem; var allEntries = new List <TrafEntry>(); allEntries.AddRange(t.entries); allEntries.AddRange(t.intersections); foreach (var e in allEntries) { for (int i = 0; i < e.waypoints.Count; i++) { e.waypoints[i] = t.transform.localToWorldMatrix.MultiplyPoint(e.waypoints[i]); } } t.transform.position = Vector3.zero; t.transform.rotation = Quaternion.identity; t.transform.localScale = Vector3.one; } if (GUILayout.Button("EXPORT DATA")) { var t = target as TrafSystem; var intersections = t.intersections; string output = ""; for (int i = 0; i < intersections.Count; i++) { var inter = intersections[i]; string index = i.ToString(); string name = inter.light == null ? "" : inter.light.gameObject.name; string x = inter.light == null ? "" : inter.light.transform.position.x.ToString(); string y = inter.light == null ? "" : inter.light.transform.position.y.ToString(); string z = inter.light == null ? "" : inter.light.transform.position.z.ToString(); output += $"{index},{name},{x},{y},{z}\n"; } using (StreamWriter sw = File.CreateText("dataTransfer.rl")) { sw.Write(output); } } if (GUILayout.Button("READ DATA")) { var t = target as TrafSystem; var intersections = t.intersections; var lines = File.ReadAllLines("dataTransfer.rl"); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; string[] items = line.Split(','); string searchName = items[1]; if (searchName == "") { continue; } Vector3 pos = new Vector3(float.Parse(items[2]), float.Parse(items[3]), float.Parse(items[4])); var containers = GameObject.FindObjectsOfType <TrafficLightContainer>(); foreach (var c in containers) { if (c.gameObject.name != searchName) { continue; } float dist = (c.transform.position - pos).magnitude; if (dist < 0.01f) { Debug.Log("assign"); intersections[i].light = c; break; } } } } if (GUILayout.Button("Debug Number")) { var t = target as TrafSystem; var intersections = t.intersections; int num = 0; foreach (var inter in intersections) { if (inter.light != null) { num++; } } Debug.Log(num); } EditorGUILayout.Space(); if (GUILayout.Button("Generate Lanes Texture")) { GenerateInfractionsTexture(); } if (GUILayout.Button("Generate Highway Lanes Texture")) { GenerateInfractionsTextureHighway(); } if (GUILayout.Button("Apply stoplight infraction triggers")) { ApplyStoplightInfractionTriggers(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Specific Entry:"); specificId = EditorGUILayout.IntField("ID", specificId); specificSubId = EditorGUILayout.IntField("SubID", specificSubId); specificIndex = EditorGUILayout.IntField("Index", specificIndex); if (GUILayout.Button("Visualize single entry/intersection")) { currentState = TrafEditState.DISPLAY_SINGLE; SceneView.RepaintAll(); } if (GUILayout.Button("Snap scene camera to specific entry point(\"-1\" is end point)")) { SnapSceneCameraToEntry(); } EditorGUILayout.Space(); if (GUILayout.Button("Debug road graph")) { DebugRoadGraph(); } if (GUILayout.Button("Auto fix road graph")) { AutoFixRoadGraph(); } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); fromId = EditorGUILayout.IntField("From ID", fromId); fromSubId = EditorGUILayout.IntField("From sub ID", fromSubId); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Manual check road graph edge")) { ManualCheckRoadGraph(fromId, fromSubId); } EditorGUILayout.BeginHorizontal(); toId = EditorGUILayout.IntField("To ID", toId); toSubId = EditorGUILayout.IntField("To sub ID", toSubId); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Manual connect road graph edge")) { ManualConnectRoadGraph(fromId, fromSubId, toId, toSubId); } if (GUILayout.Button("Manual remove road graph edge")) { ManualRemoveRoadGraph(fromId, fromSubId, toId, toSubId); } break; case TrafEditState.EDIT: if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = currentRoad, identifier = currentId, subIdentifier = currentSubId }); } break; case TrafEditState.EDIT_MULTI: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, false), identifier = currentId, subIdentifier = 0 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, false), identifier = currentId, subIdentifier = 1 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } if (GUILayout.Button("cancel")) { currentState = TrafEditState.IDLE; } break; case TrafEditState.EDIT_MULTI_TWOWAY: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, true), identifier = currentId, subIdentifier = 0 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, true), identifier = currentId, subIdentifier = 1 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } break; case TrafEditState.EDIT_MULTI_RA: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 0, waypoints = currentRoadMulti[0] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 1, waypoints = currentRoadMulti[1] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 2, waypoints = currentRoadMulti[2] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 3, waypoints = currentRoadMulti[3] }); } break; case TrafEditState.DISPLAY_ENTRIES: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; case TrafEditState.DISPLAY_INTERSECTIONS: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; case TrafEditState.DISPLAY_ENTRIES_INTERSECTIONS: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; case TrafEditState.DISPLAY_SINGLE: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; } EditorGUILayout.EndVertical(); }
public override void OnInspectorGUI() { //DrawDefaultInspector(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); currentId = EditorGUILayout.IntField("ID", currentId); if (GUILayout.Button("Next Free ID")) { var t = target as TrafSystem; currentId = t.entries.Max(e => e.identifier) + 1; } currentSubId = EditorGUILayout.IntField("SubID", currentSubId); EditorGUILayout.EndHorizontal(); switch (currentState) { case TrafEditState.IDLE: if (GUILayout.Button("DELETE - CAREFUL!")) { var t = target as TrafSystem; t.entries.RemoveAll(e => e.identifier == currentId); } if (GUILayout.Button("new/edit")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId)) { var road = t.entries.Find(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId); currentRoad = road.road; t.entries.Remove(road); currentState = TrafEditState.EDIT; } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT; } } if (GUILayout.Button("new multi one way")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI; } } if (GUILayout.Button("new multi two way")) { var t = target as TrafSystem; if (t.entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI_TWOWAY; } } if (GUILayout.Button("Visualize")) { currentState = TrafEditState.DISPLAY; SceneView.RepaintAll(); } if (GUILayout.Button("Register all intersections")) { var t = target as TrafSystem; t.intersections.Clear(); TrafIntersectionEditor.GoAll(t); EditorUtility.SetDirty(target); } if (GUILayout.Button("Deregister all intersections")) { var t = target as TrafSystem; t.intersections.Clear(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Generate RoadGraph")) { GenerateRoadGraph(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Clear RoadGraph")) { var t = target as TrafSystem; t.roadGraph = new TrafRoadGraph(); EditorUtility.SetDirty(target); } if (GUILayout.Button("Remove Markers")) { var t = target as TrafSystem; foreach (var g in t.GetComponentsInChildren <Renderer>()) { g.enabled = false; } } if (GUILayout.Button("TEMP")) { var t = target as TrafSystem; foreach (var e in t.entries) { if (e.road != null) { e.waypoints = new List <Vector3>(); foreach (var v in e.road.waypoints) { e.waypoints.Add(v.position); } } } } EditorGUILayout.Space(); if (GUILayout.Button("Generate Lanes Texture")) { GenerateInfractionsTexture(); } if (GUILayout.Button("Generate Highway Lanes Texture")) { GenerateInfractionsTextureHighway(); } if (GUILayout.Button("Apply stoplight infraction triggers")) { ApplyStoplightInfractionTriggers(); } break; case TrafEditState.EDIT: if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = currentRoad, identifier = currentId, subIdentifier = currentSubId }); } break; case TrafEditState.EDIT_MULTI: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, false), identifier = currentId, subIdentifier = 0 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, false), identifier = currentId, subIdentifier = 1 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } if (GUILayout.Button("cancel")) { currentState = TrafEditState.IDLE; } break; case TrafEditState.EDIT_MULTI_TWOWAY: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, true), identifier = currentId, subIdentifier = 0 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, true), identifier = currentId, subIdentifier = 1 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); t.entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } break; case TrafEditState.EDIT_MULTI_RA: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { var t = target as TrafSystem; currentState = TrafEditState.IDLE; t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 0, waypoints = currentRoadMulti[0] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 1, waypoints = currentRoadMulti[1] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 2, waypoints = currentRoadMulti[2] }); t.entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 3, waypoints = currentRoadMulti[3] }); } break; case TrafEditState.DISPLAY: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; } EditorGUILayout.EndVertical(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); currentId = EditorGUILayout.IntField("ID", currentId); if (GUILayout.Button("Next Free ID")) { currentId = entries.Max(e => e.identifier) + 1; } currentSubId = EditorGUILayout.IntField("SubID", currentSubId); EditorGUILayout.EndHorizontal(); switch (currentState) { case TrafEditState.IDLE: if (GUILayout.Button("UpdateSystem")) { var sys = (target as TrafSystemData).system; sys.entries = entries; EditorUtility.SetDirty(sys); } if (GUILayout.Button("DELETE - CAREFUL!")) { entries.RemoveAll(e => e.identifier == currentId); } if (GUILayout.Button("new/edit")) { if (entries.Any(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId)) { var road = entries.Find(entry => entry.identifier == currentId && entry.subIdentifier == currentSubId); currentRoad = road.road; entries.Remove(road); currentState = TrafEditState.EDIT; } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT; } } if (GUILayout.Button("new multi one way 4 lanes")) { if (entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI; } } if (GUILayout.Button("new multi one way 3 lanes")) { if (entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI_3; } } if (GUILayout.Button("new multi two way")) { if (entries.Any(entry => entry.identifier == currentId)) { Debug.Log("TrafSystem: A road with that ID already exists. Multi editing not supported"); } else { currentRoad = ScriptableObject.CreateInstance(typeof(TrafRoad)) as TrafRoad; InitRoad(currentRoad); currentState = TrafEditState.EDIT_MULTI_TWOWAY; SceneView.RepaintAll(); } } if (GUILayout.Button("Visualize")) { currentState = TrafEditState.DISPLAY; SceneView.RepaintAll(); } if (GUILayout.Button("Visualize Splines")) { currentState = TrafEditState.DISPLAY_SPLINES; SceneView.RepaintAll(); } if (GUILayout.Button("Visualize Intersection Splines")) { currentState = TrafEditState.DISPLAY_INTERSECTION_SPLINES; SceneView.RepaintAll(); } if (GUILayout.Button("Edit Ends")) { currentState = TrafEditState.EDIT_ENDS; SceneView.RepaintAll(); } if (GUILayout.Button("TEMP")) { foreach (var e in entries) { if (e.road != null) { e.waypoints = new List <Vector3>(); foreach (var v in e.road.waypoints) { e.waypoints.Add(v.position); } } } } break; case TrafEditState.EDIT: if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; entries.Add(new TrafEntry() { road = currentRoad, identifier = currentId, subIdentifier = currentSubId }); } break; case TrafEditState.EDIT_MULTI: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, false), identifier = currentId, subIdentifier = 0 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, false), identifier = currentId, subIdentifier = 1 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } if (GUILayout.Button("cancel")) { currentState = TrafEditState.IDLE; } break; case TrafEditState.EDIT_MULTI_3: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("add")) { currentRoad.waypoints.Add( new TrafRoadPoint { position = currentRoad.waypoints[currentRoad.waypoints.Count - 1].position + (currentRoad.waypoints[currentRoad.waypoints.Count - 1].position - currentRoad.waypoints[currentRoad.waypoints.Count - 2].position).normalized * 5f }); SceneView.RepaintAll(); } if (GUILayout.Button("align height")) { foreach (var wp in currentRoad.waypoints) { RaycastHit[] hits = Physics.RaycastAll(wp.position + Vector3.up * 20f, Vector3.down, 1000f); if (hits.Length == 0 || collisionLayer >= hits.Length) { Debug.Log("Nothing hit on wp " + wp.position); } else { wp.position = hits[collisionLayer].point + Vector3.up * 0.5f; } } SceneView.RepaintAll(); } if (GUILayout.Button("Save temp")) { RoadSaver.Instance.currentRoad = currentRoad; SceneView.RepaintAll(); } if (GUILayout.Button("Restore temp")) { currentRoad = RoadSaver.Instance.currentRoad; SceneView.RepaintAll(); } if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1f, false), identifier = currentId, subIdentifier = 0 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 0f, false), identifier = currentId, subIdentifier = 1 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1f, false), identifier = currentId, subIdentifier = 2 }); } if (GUILayout.Button("cancel")) { currentState = TrafEditState.IDLE; } break; case TrafEditState.EDIT_MULTI_TWOWAY: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -1.5f, true), identifier = currentId, subIdentifier = 0 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * -.5f, true), identifier = currentId, subIdentifier = 1 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * .5f, false), identifier = currentId, subIdentifier = 2 }); entries.Add(new TrafEntry() { road = InitRoadMulti(currentRoad, laneWidth * 1.5f, false), identifier = currentId, subIdentifier = 3 }); } break; case TrafEditState.EDIT_MULTI_RA: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 0, waypoints = currentRoadMulti[0] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 1, waypoints = currentRoadMulti[1] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 2, waypoints = currentRoadMulti[2] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 3, waypoints = currentRoadMulti[3] }); } break; case TrafEditState.EDIT_MULTI_RA_TWOWAY: laneWidth = EditorGUILayout.Slider("lane width", laneWidth, 0f, 50f); if (GUILayout.Button("save")) { currentState = TrafEditState.IDLE; currentRoadMulti[0].Reverse(); currentRoadMulti[1].Reverse(); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 0, waypoints = currentRoadMulti[0] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 1, waypoints = currentRoadMulti[1] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 2, waypoints = currentRoadMulti[2] }); entries.Add(new TrafEntry() { identifier = currentId, subIdentifier = 3, waypoints = currentRoadMulti[3] }); } break; case TrafEditState.DISPLAY: case TrafEditState.DISPLAY_SPLINES: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } showIds = GUILayout.Toggle(showIds, "Show IDs?"); break; case TrafEditState.EDIT_ENDS: if (GUILayout.Button("Back")) { currentState = TrafEditState.IDLE; SceneView.RepaintAll(); } break; } EditorGUILayout.EndVertical(); }