void OnSceneGUI() { CCDSolverMB cp = (CCDSolverMB)target; CCDSolver solver = cp.GetSolver(); if (solver == null || solver.Count < 1) { return; } if (cp.ShowGizmos) { var joints = solver.GetJoints(); Camera sceneCam = EUtil.GetSceneViewCamera(); Transform camTr = sceneCam.transform; EUtil.PushHandleColor(Pref.IKBoneLinkColor); //1. draw bone line for (int i = 0; i < joints.Length - 1; ++i) { var p0 = joints[i].position; var p1 = joints[i + 1].position; Handles.DrawAAPolyLine(3f, p0, p1); Handles.DotCap(0, p0, camTr.rotation, m_markerSize.val); } if (joints.Length > 0) { Handles.DotCap(0, joints.Last().position, camTr.rotation, m_markerSize.val); } EUtil.PopHandleColor(); //1.5 draw line from end-joint to target pos { var p0 = joints.Last().position; var p1 = solver.Target; Handles.DrawDottedLine(p0, p1, 5f); } //2. call each constraint's OnSceneGUI for (int i = 0; i < joints.Length - 1; ++i) { var cons = solver.GetConstraint(i); foreach (var con in cons) { if (!con || !con.enabled) { continue; } Editor e = EUtil.GetEditor(con); IOnSceneGUI igui = e as IOnSceneGUI; if (igui != null) { igui.OnSceneGUI(); } } } } //3. debug draw if (!cp.Target) { if (m_panel != EPanel.Normal) { Tools.current = Tool.None; // move handle if (m_panel == EPanel.Continuous) { EditorGUI.BeginChangeCheck(); } solver.Target = Handles.PositionHandle(solver.Target, Quaternion.identity); if (m_panel == EPanel.Continuous && EditorGUI.EndChangeCheck()) { Undo.RecordObjects(solver.GetJoints(), "IK execute"); solver.Execute(); } // hotkeys Event e = Event.current; if (e.type == EventType.KeyUp && Tools.viewTool != ViewTool.FPS) { if (e.keyCode == KeyCode.E) { Tools.current = Tool.Rotate; m_panel = EPanel.Normal; } else if (e.keyCode == KeyCode.R) { Tools.current = Tool.Scale; m_panel = EPanel.Normal; } else if (e.keyCode == KeyCode.Q) { Tools.current = Tool.View; m_panel = EPanel.Normal; } } } } }