/// QPathFinder modified /// <summary> /// Method is responsible for display window in scene window /// </summary> void DrawGUIWindowOnScene() { GUILayout.Window(1, new Rect(0f, 25f, 70f, 80f), delegate(int windowID) { EditorGUILayout.BeginHorizontal(); sceneMode = (SceneMode)GUILayout.SelectionGrid((int)sceneMode, new string[] { "Add Junction", "Add Street", "Select Junction", "Select Street", "None", "Delete Junction", "Delete Street" }, 1); if (sceneMode != SceneMode.SelectStreet && selectedStreet) { selectedStreet.Select(false); selectedStreet = null; } if (sceneMode != SceneMode.SelectJunction && selectedJunction) { selectedJunction.Select(false); selectedJunction = null; } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); }, "Mode"); GUILayout.Window(2, new Rect(0, 195f, 70f, 100f), delegate(int windowID) { EditorGUILayout.BeginVertical(); if (GUILayout.Button("Clear All")) { ClearAll(); } if (GUILayout.Button("Refresh Data")) { RefreshData(); } script.TimeScale = (int)GUILayout.HorizontalSlider(script.TimeScale, 1, 5); GUI.Label(new Rect(10, 75, 80, 20), "Time Scale " + script.TimeScale); EditorGUILayout.EndVertical(); }, ""); if (sceneMode == SceneMode.AddStreet) { GUI.Window(4, new Rect(100f, 25f, 140f, 60f), delegate(int windowID) { EditorGUILayout.BeginHorizontal(); GUI.color = Color.white; GUI.Label(new Rect(0, 20, 70, 15), "Lines IN"); GUI.Label(new Rect(0, 40, 70, 15), "Lines OUT"); GUI.Label(new Rect(90, 20, 20, 15), ifrom.ToString()); GUI.Label(new Rect(90, 40, 20, 15), ito.ToString()); if (GUI.Button(new Rect(105, 20, 15, 15), "<")) { ifrom = Mathf.Clamp((ifrom - 1), 0, 10); } if (GUI.Button(new Rect(120, 20, 15, 15), ">")) { ifrom = Mathf.Clamp((ifrom + 1), 0, 10); } if (GUI.Button(new Rect(105, 40, 15, 15), "<")) { ito = Mathf.Clamp((ito - 1), 0, 10); } if (GUI.Button(new Rect(120, 40, 15, 15), ">")) { ito = Mathf.Clamp((ito + 1), 0, 10); } EditorGUILayout.EndHorizontal(); }, "Add Street"); } if (sceneMode == SceneMode.SelectJunction && selectedJunction != null) { GUI.Window(5, new Rect(100f, 25f, 140f, 160f), delegate(int windowID) { GUI.color = Color.white; EditorGUILayout.BeginHorizontal(); GUI.Label(new Rect(0, 20, 100, 25), "Roundabout"); GUI.Label(new Rect(0, 40, 100, 25), "Calculate Timers"); GUI.Label(new Rect(0, 60, 100, 25), "Cycle Time"); selectedJunction.Rondo = GUI.Toggle(new Rect(110, 20, 20, 15), selectedJunction.Rondo, ""); selectedJunction.timersCalc = GUI.Toggle(new Rect(110, 40, 20, 15), selectedJunction.timersCalc, ""); string tmp = GUI.TextField(new Rect(110, 60, 25, 15), selectedJunction.cycleTime.ToString(), 3); tmp = tmp.Length == 0 ? "1" : tmp; try { selectedJunction.cycleTime = float.Parse(tmp); } catch (FormatException) { } if (selectedJunction.Rondo == false) { Color[] col = new Color[4] { Color.red, Color.green, Color.blue, Color.yellow }; GUI.Label(new Rect(0, 80, 120, 15), "Timers"); for (int i = 0; i < selectedJunction.timers.Length; i++) { GUI.color = col[i]; tmp = GUI.TextField(new Rect(110, 80 + i * 20, 25, 15), selectedJunction.timers[i].ToString(), 3); tmp = tmp.Length == 0 ? "0" : tmp; try { selectedJunction.timers[i] = float.Parse(tmp); } catch (FormatException) { } } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); }, "Selected Junction"); } if (sceneMode == SceneMode.SelectStreet && selectedStreet) { GUI.Window(3, new Rect(100f, 25f, 140f, 190f), delegate(int windowID) { GUI.color = Color.white; EditorGUILayout.BeginHorizontal(); GUI.Label(new Rect(0, 20, 70, 15), "Name"); GUI.Label(new Rect(0, 40, 70, 15), "Lines IN"); GUI.Label(new Rect(0, 60, 70, 15), "Lines OUT"); selectedStreet.Name = GUI.TextField(new Rect(45, 20, 90, 15), selectedStreet.Name, 25); GUI.Label(new Rect(90, 40, 20, 15), selectedStreet.iFrom.ToString()); GUI.Label(new Rect(90, 60, 20, 15), selectedStreet.iTo.ToString()); if (GUI.Button(new Rect(105, 40, 15, 15), "<")) { selectedStreet.iFrom = Mathf.Clamp((selectedStreet.iFrom - 1), 0, 10); selectedStreet.Calculate(); script.graphData.ReGenerateIDs(); selectedStreet.RecalcJunction(); script.graphData.ReGenerateIDs(); } if (GUI.Button(new Rect(120, 40, 15, 15), ">")) { selectedStreet.iFrom = Mathf.Clamp((selectedStreet.iFrom + 1), 0, 10); selectedStreet.Calculate(); script.graphData.ReGenerateIDs(); selectedStreet.RecalcJunction(); script.graphData.ReGenerateIDs(); } if (GUI.Button(new Rect(105, 60, 15, 15), "<")) { selectedStreet.iTo = Mathf.Clamp((selectedStreet.iTo - 1), 0, 10); selectedStreet.Calculate(); script.graphData.ReGenerateIDs(); selectedStreet.RecalcJunction(); script.graphData.ReGenerateIDs(); } if (GUI.Button(new Rect(120, 60, 15, 15), ">")) { selectedStreet.iTo = Mathf.Clamp((selectedStreet.iTo + 1), 0, 10); selectedStreet.Calculate(); script.graphData.ReGenerateIDs(); selectedStreet.RecalcJunction(); script.graphData.ReGenerateIDs(); } // delegate / inhabitants / commercial places / work places / emigrants string[] describe = new string[5] { "Incoming", "Inhabitants", "Shopping places", "Work places", "Leaving" }; Color[] col = new Color[5] { new Color(0.9f, 0.9f, 0.9f), new Color(0, 1, 0), new Color(0, 0.75f, 1), new Color(1, 1, 0), new Color(1, 0.58f, 0.62f) }; for (int i = 0; i < 5; i++) { GUI.color = col[i]; GUI.Label(new Rect(0, 80 + i * 20, 120, 15), describe[i]); string tmp = GUI.TextField(new Rect(110, 80 + i * 20, 25, 15), selectedStreet.spawns[i].ToString(), 25); tmp = tmp.Length == 0 ? "0" : tmp; try { selectedStreet.spawns[i] = int.Parse(tmp); } catch (FormatException) { } } GUI.color = Color.white; EditorGUILayout.EndHorizontal(); }, "Selected Street"); } }
/// QPathFinder modified /// <summary> /// The method is responsible for the reaction to the click of the mouse /// </summary> /// <param name="mousePos">Position of cursor</param> void OnMouseClick(Vector2 mousePos) { LayerMask backgroundLayerMask = 1 << LayerMask.NameToLayer(groundColliderLayerName); Ray ray = HandleUtility.GUIPointToWorldRay(mousePos); if (Physics.Raycast(ray, out RaycastHit hit, 100000f, backgroundLayerMask)) { if (sceneMode == SceneMode.AddJunction) { Vector3 hitPos = hit.point; var junction = CreateJunction(hitPos); if (hit.transform.parent && hit.transform.parent.name == "Street") { var street = hit.transform.parent.GetComponent <Street>(); var fr = street.from; var to = street.to; ifrom = street.iFrom; ito = street.iTo; DeleteStreet(street); CreateStreet(fr, junction); CreateStreet(junction, to); } } if (sceneMode == SceneMode.AddStreet) { if (previous == null) { previous = hit.transform.gameObject.GetComponent <Junction>(); } else { Junction b = hit.transform.gameObject.GetComponent <Junction>(); if (b != null && previous != b) { CreateStreet(previous, b); previous = null; } } } if (sceneMode == SceneMode.SelectJunction) { if (hit.transform.name == "Junction") { if (selectedJunction) { selectedJunction.Select(false); selectedJunction = null; } selectedJunction = hit.transform.GetComponent <Junction>(); selectedJunction.Select(); } } else { if (selectedJunction) { selectedJunction.Select(false); selectedJunction = null; } } if (sceneMode == SceneMode.SelectStreet) { if (hit.transform.parent != null && hit.transform.parent.name == "Street") { if (selectedStreet) { selectedStreet.Select(false); selectedStreet = null; } selectedStreet = hit.transform.parent.GetComponent <Street>(); selectedStreet.Select(); } } else { if (selectedStreet) { selectedStreet.Select(false); selectedStreet = null; } } if (sceneMode == SceneMode.DeleteJunction) { if (hit.transform.name == "Junction") { DeleteJunction(hit.transform.GetComponent <Junction>()); } } if (sceneMode == SceneMode.DeleteStreet) { if (hit.transform.parent.name == "Street") { DeleteStreet(hit.transform.parent.GetComponent <Street>()); } } } }