void JointsSceneGUI() { SplineEditor.ShowEditor = false; for (int i = 0; i < rope.Links.Length; i++) { if (!rope.Links[i].IsActive) { continue; } Vector3 pos = rope.Links[i].transform.position; float handleSz = HandleUtility.GetHandleSize(pos) * handleSize; if (selectedLink == i) { EditorX.CircleButton(pos, Color.yellow, handleSz * 0.7f); } else { bool isCustom = (rope.Links[i].overrideColliderSettings || rope.Links[i].overrideJointSettings || rope.Links[i].overrideOffsetSettings || rope.Links[i].overridePrefab || rope.Links[i].overrideRigidbodySettings); if (EditorX.CircleButton(pos, isCustom ? new Color(0.7f, 0.3f, 0.3f) : Color.white, handleSz * (isCustom ? 0.7f : 0.5f))) { selectedLink = i; this.Repaint(); } } } }
void OnSceneGUI() { if (!SplineEditor.ShowEditor || (Application.isPlaying && !ShowEditorInPlayMode)) { return; } #region Keypress Events // Get Events float btnSize; int pointsToDraw = spline.IsLooped ? spline.Points.Length - 1 : spline.Points.Length; //bool cntrlDwn = false; if (!Event.current.control) { btnSize = HandleUtility.GetHandleSize(transform.position) * handleSize; if (EditorX.CircleButton(transform.position, Color.red, btnSize)) { selectedControl = -1; Tools.hidden = false; } if (Tools.hidden && selectedControl == -1) { Tools.hidden = false; } } else { Tools.hidden = true; } // Draw Spline for (int i = 0; i < pointsToDraw; i++) { Vector3 cpPos = transform.TransformPoint(spline.GetPoint(i)); btnSize = HandleUtility.GetHandleSize(cpPos) * handleSize; bool isPivot = (i % 3) == 0; if (selectedControl == i) { EditorX.DrawDot(cpPos, Color.yellow, isPivot ? btnSize : btnSize * 0.75f); EditorGUI.BeginChangeCheck(); Vector3 newPos = transform.InverseTransformPoint(Handles.DoPositionHandle(cpPos, Quaternion.identity)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Moved Control Point"); spline.SetPoint(i, newPos); } } else { if (i == 0 && !Event.current.control) { continue; } if (EditorX.CircleButton(cpPos, isPivot ? Color.blue : Color.cyan, isPivot ? btnSize : btnSize * 0.75f)) { selectedControl = i; Tools.hidden = true; Repaint(); } } } for (int i = 0; i < spline.ControlCount; i++) { Vector3 p0 = transform.TransformPoint(spline.GetPoint((i * 3) + 0)); Vector3 p1 = transform.TransformPoint(spline.GetPoint((i * 3) + 1)); Vector3 p2 = transform.TransformPoint(spline.GetPoint((i * 3) + 2)); Vector3 p3 = transform.TransformPoint(spline.GetPoint((i * 3) + 3)); Handles.color = Color.green; Handles.DrawDottedLine(p0, p3, 5f); Handles.color = Color.black; Handles.DrawAAPolyLine(null, 2f, p0, p1); Handles.DrawAAPolyLine(null, 2f, p2, p3); Vector3 center = (p0 + p3) * 0.5f; float handleSz = HandleUtility.GetHandleSize(center) * handleSize; if (EditorX.CircleButton(center, Color.green, handleSz * 0.7f)) { Undo.RecordObject(spline, "Added Spline Point"); spline.AddCurve(i); Repaint(); } } DrawSpline(); Event e = Event.current; switch (e.type) { case EventType.KeyDown: { switch (e.keyCode) { case KeyCode.Backspace: { // Delete Selected Control Undo.RecordObject(spline, "Deleted Spline Point"); spline.RemoveCurve(selectedControl / 3); selectedControl = -1; EditorUtility.SetDirty(spline); e.Use(); } break; default: break; } } break; } #endregion }