void OnSceneGUI(SceneView sceneView) { Handles.BeginGUI(); arrow.arrowlength = arrowlength; arrow.arrowoff = arrowoff; arrow.arrowwidth = arrowwidth; arrow.vertStart = vertStart; arrow.vertLength = vertLength; arrow.lineCol = lineCol; arrow.otherCol = otherCol; arrow.arrowcol = arrowCol; arrow.dashCol = dashCol; arrow.units = MegaArrow.GetUnitsString(units); arrow.unitsscale = MegaArrow.GetUnitsScale(units, unitsScale); arrow.dashdist = dashdist; GUIStyle style = new GUIStyle(); style.normal.textColor = lineCol; for (int i = 0; i < selection.Count; i++) { Handles.Label(selection[i].transform.position, " " + i); if (i > 0) { //Handles.DrawLine(selection[i - 1].transform.position, selection[i].transform.position); Vector3 p1 = selection[i - 1].transform.position; Vector3 p2 = selection[i].transform.position; arrow.DrawArrow(i, p1, p2, style); } } Handles.EndGUI(); }
void OnSceneGUI() { MegaWirePlantPolesList mod = (MegaWirePlantPolesList)target; arrow.arrowlength = mod.arrowlength; arrow.arrowoff = mod.arrowoff; arrow.arrowwidth = mod.arrowwidth; arrow.vertStart = mod.vertStart; arrow.vertLength = mod.vertLength; arrow.lineCol = mod.lineCol; arrow.otherCol = mod.otherCol; arrow.arrowcol = mod.arrowCol; arrow.dashCol = mod.dashCol; arrow.units = MegaArrow.GetUnitsString(mod.units); arrow.unitsscale = MegaArrow.GetUnitsScale(mod.units, mod.unitsScale); arrow.dashdist = mod.dashdist; if (mod.showgizmo && (mod.gizmoType == MegaWireGizmoType.Waypoint || mod.gizmoType == MegaWireGizmoType.Both)) { switch (Event.current.type) { case EventType.keyDown: if (Event.current.keyCode == KeyCode.A) { if (!addmode) { Debug.Log("Start Add Mode"); addmode = true; Event.current.Use(); } } break; case EventType.keyUp: if (Event.current.keyCode == KeyCode.A) { if (addmode) { Debug.Log("End Add mode"); addmode = false; addingpoint = false; Event.current.Use(); } } break; } if (mod.showgizmo && (mod.gizmoType == MegaWireGizmoType.Waypoint || mod.gizmoType == MegaWireGizmoType.Both)) { Camera cam = UnityEditor.SceneView.currentDrawingSceneView.camera; if (cam) { Vector3 camwp = Event.current.mousePosition; camwp.z = 0.0f; float dist = 100000.0f; seg = -1; // Just do distance from mid point, and use closest for (int i = 0; i < mod.waypoints.Count - 1; i++) { Vector3 p = mod.waypoints[i]; Vector3 p1 = mod.waypoints[i + 1]; Vector3 wp = mod.transform.TransformPoint(p); Vector3 wp1 = mod.transform.TransformPoint(p1); Vector3 sp = cam.WorldToScreenPoint(wp); Vector3 sp1 = cam.WorldToScreenPoint(wp1); sp.z = 0.0f; sp1.z = 0.0f; Vector3 cp2 = (sp + sp1) * 0.5f; float d = Vector3.Distance(camwp, cp2); if (d < dist) { dist = d; seg = i; } } if (seg >= 0) { Vector3 pos = Vector3.Lerp(mod.waypoints[seg], mod.waypoints[seg + 1], 0.5f); Handles.color = Color.green; Handles.DotCap(1066, mod.transform.TransformPoint(pos), Quaternion.identity, 0.2f); } } } if (addmode) { int controlID = GUIUtility.GetControlID(FocusType.Passive); Camera cam = UnityEditor.SceneView.currentDrawingSceneView.camera; if (cam) { switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseDown: GUIUtility.hotControl = controlID; Event.current.Use(); if (!addingpoint) { addingpoint = true; if (seg >= 0) { Vector3 cp = (mod.waypoints[seg] + mod.waypoints[seg + 1]) * 0.5f; mod.waypoints.Insert(seg + 1, cp); } } break; case EventType.MouseUp: addingpoint = false; GUIUtility.hotControl = 0; Event.current.Use(); break; } } } } // Draw the fancier lines // Show waypoints and or pole spacing // option to control units //string units = MegaArrow.GetUnitsString(mod.units); //float unitsscale = MegaArrow.GetUnitsScale(mod.units, mod.unitsScale); GUIStyle style = new GUIStyle(); style.normal.textColor = mod.lineCol; if (mod.waypoints.Count > 1 && mod.showgizmo) { float arrowoff = mod.vertStart + (mod.vertLength * mod.arrowoff); arrow.arrowoff = arrowoff; if (mod.gizmoType == MegaWireGizmoType.Waypoint || mod.gizmoType == MegaWireGizmoType.Both) { for (int i = 0; i < mod.waypoints.Count; i++) { Vector3 lp = mod.transform.TransformPoint(mod.waypoints[i]); lp = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(lp); Handles.color = mod.lineCol; if (lp.z > 0.0f) { Handles.Label(mod.transform.TransformPoint(mod.waypoints[i]), "" + i, style); } if (i > 0) { Vector3 p1 = mod.transform.TransformPoint(mod.waypoints[i - 1]); Vector3 p2 = mod.transform.TransformPoint(mod.waypoints[i]); arrow.DrawArrow(i, p1, p2, style); } Vector3 p = mod.transform.worldToLocalMatrix.MultiplyPoint(Handles.PositionHandle(mod.transform.localToWorldMatrix.MultiplyPoint(mod.waypoints[i]), Quaternion.identity)); if (p != mod.waypoints[i]) { mod.waypoints[i] = p; mod.Rebuild(); } } if (mod.closed) { Handles.DrawLine(mod.waypoints[mod.waypoints.Count - 1], mod.waypoints[0]); } } // Poles if (mod.gizmoType == MegaWireGizmoType.Pole || mod.gizmoType == MegaWireGizmoType.Both) { Handles.matrix = Matrix4x4.identity; for (int i = 0; i < mod.poles.Count; i++) { Vector3 lp = mod.transform.TransformPoint(mod.poles[i].transform.position); lp = SceneView.currentDrawingSceneView.camera.WorldToScreenPoint(lp); if (i > 0) { Vector3 p1 = mod.poles[i - 1].transform.position; Vector3 p2 = mod.poles[i].transform.position; arrow.DrawArrow(i, p1, p2, style); } } } } }