コード例 #1
0
        private void OnSceneGUI()
        {
            curve = target as BezierCurve;

            // -- The tools used to draw in the scene view (Handles) operates in world space.
            // Therefore, we have to convert our object's local space to world space
            handleTransform = curve.transform;

            // By default, it also doesn't take into account the unity's pivot rotation setting (global vs local)
            // handleRotation = Tools.pivotRotation == PivotRotation.Local ?  handleTransform.rotation : Quaternion.identity;
            if (Tools.pivotRotation == PivotRotation.Local)
            {
                handleRotation = handleTransform.rotation;
            }
            else
            {
                handleRotation = Quaternion.identity;
            }

            Vector3 p0 = ShowPoint(0);
            Vector3 p1 = ShowPoint(1);
            Vector3 p2 = ShowPoint(2);
            Vector3 p3 = ShowPoint(3);

            Handles.color = Color.grey;
            Handles.DrawLine(p0, p1);
            Handles.DrawLine(p2, p3);

            Handles.color = Color.white;
            Vector3 lineStart = curve.GetPoint(0f);

            //for (int i = 1; i <= lineSteps; i++) {
            //    Vector3 lineEnd = curve.GetPoint(i / (float)lineSteps);

            //    Handles.DrawLine(lineStart, lineEnd);

            //    lineStart = lineEnd;
            //}

            Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
        }
コード例 #2
0
        private void OnSceneGUI()
        {
            spline = target as BezierSpline;

            // Validate that the user didn't mangle the spline's points array
            if (spline.numControlPoints == 0) return;
            if (spline.numControlPoints < 4
                || (spline.numControlPoints - 4) % 3 != 0) {
                Debug.LogError("The number of points in this spline is invalid!");
                return;
            }

            // -- The tools used to draw in the scene view (Handles) operates in world space.
            // Therefore, we have to convert our object's local space to world space
            handleTransform = spline.transform;

            // By default, it also doesn't take into account the unity's pivot rotation setting (global vs local)
            handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity;

            Vector3 p0 = ShowPoint(0);
            for (int i = 1; i < spline.numControlPoints; i += 3) {
                Vector3 p1 = ShowPoint(i);
                Vector3 p2 = ShowPoint(i + 1);
                Vector3 p3 = ShowPoint(i + 2);

                Handles.color = Color.grey;
                Handles.DrawLine(p0, p1);
                Handles.DrawLine(p2, p3);

                Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);

                p0 = p3;
            }

            ShowDirections();
        }