private void RectifyCurrentPointEnum(PolyBezier polyBezier) { DestroyImmediate(testPath); if (curPointIndex == -1) curPointType = cpte.Node; if (curPointIndex == 0 && curPointType == cpte.HandleA) curPointType = cpte.HandleB; if (curPointIndex == polyBezier.bez.nodes.Length && curPointType == cpte.HandleB) curPointType = cpte.HandleA; }
void DisplayPointsAndLines(PolyBezier polyBezier) { int someHashCode = GetHashCode(); Transform tr = polyBezier.transform; int nl = polyBezier.bez.nodes.Length; Vector3[] worldNodes = new Vector3[nl]; Vector3[] worldHandlesA = new Vector3[nl]; Vector3[] worldHandlesB = new Vector3[nl]; for (int i = 0; i < nl; i++) { Vector3 node = tr.TransformPoint(polyBezier.bez.nodes[i]); Vector3 hanA = tr.TransformPoint(polyBezier.bez.handlesA[i]); Vector3 hanB = tr.TransformPoint(polyBezier.bez.handlesB[i]); //Handles.color = Color.yellow; //Handles.DrawLine(hanA, node); //Handles.DrawLine(node, hanB); //if (i != nl-1) Handles.DrawLine(hanB, tr.TransformPoint(polyBezier.bez.handlesA[i+1])); Handles.color = Color.white; Handles.Label(node, " " + i); float size; // Display Node and check if it has the focus // size = HandleUtility.GetHandleSize(node); SetControlIDState(someHashCode); Handles.ScaleValueHandle(0, node, Quaternion.identity, size, Handles.SphereCap, 0); // display cap if (GetControlIDState(someHashCode)) { //Debug.Log(i); curPointIndex = i; curPointType = cpte.Node; RectifyCurrentPointEnum(polyBezier); } Handles.color = Color.blue; // Display First Handle and check if it has the focus // if (i != 0) { size = HandleUtility.GetHandleSize(hanA); SetControlIDState(someHashCode); Handles.ScaleValueHandle(0, hanA, Quaternion.identity, size, Handles.SphereCap, 0); if (GetControlIDState(someHashCode)) { //Debug.Log(i); curPointIndex = i; curPointType = cpte.HandleA; RectifyCurrentPointEnum(polyBezier); } Handles.DrawLine(hanA, node); } // Display Last Handle and check if it has the focus // if (i != nl-1) { size = HandleUtility.GetHandleSize(hanB); SetControlIDState(someHashCode); Handles.ScaleValueHandle(0, hanB, Quaternion.identity, size, Handles.SphereCap, 0); if (GetControlIDState(someHashCode)) { //Debug.Log(i); curPointIndex = i; curPointType = cpte.HandleB; RectifyCurrentPointEnum(polyBezier); } Handles.DrawLine(hanB, node); } // Move points for selected object // if (curPointIndex == i) { /* Quaternion q = Handles.RotationHandle(Quaternion.identity, node); if (q != qRec) // do not call EditorUtility.Set Dirty() if nothing is moved { q = q * Quaternion.Inverse(qRec); qRec = q; //RotateHandles(polyBezier, q, curPointIndex); // display rotation gizmo } //*/ if (curPointType == cpte.Node) { node = Handles.PositionHandle(node, Quaternion.identity); // display position gizmo if (node != nodeRec) // do not call EditorUtility.Set Dirty() if nothing is moved { MoveNode(polyBezier, tr.InverseTransformPoint(node), i); nodeRec = node; } } else if (curPointType == cpte.HandleA) { hanA = Handles.PositionHandle(hanA, Quaternion.identity); if (hanA != hanARec) // do not call EditorUtility.Set Dirty() if nothing is moved { MoveHandle(polyBezier, tr.InverseTransformPoint(hanA), i, true); hanARec = hanA; } } else { hanB = Handles.PositionHandle(hanB, Quaternion.identity); if (hanB != hanBRec) // do not call EditorUtility.Set Dirty() if nothing is moved { MoveHandle(polyBezier, tr.InverseTransformPoint(hanB), i, false); hanBRec = hanB; } } } // Store nodes to display lines // worldNodes[i] = node; worldHandlesA[i] = hanA; worldHandlesB[i] = hanB; } insideSceneGUI(polyBezier); //Handles.color = Color.red; //Handles.DrawPolyLine(worldNodes); }