Example #1
0
        protected virtual void OnSceneGUI()
        {
            // for CUITextEditor, allow using scene UI to change the control points of the bezier curves

            CUIGraphic script = (CUIGraphic)this.target;

            script.ReportSet();

            for (int c = 0; c < script.RefCurves.Length; c++)
            {
                CUIBezierCurve curve = script.RefCurves[c];

                if (curve.ControlPoints != null)
                {
                    Vector3[] controlPoints = curve.ControlPoints;

                    Transform  handleTransform = curve.transform;
                    Quaternion handleRotation  = curve.transform.rotation;

                    for (int p = 0; p < CUIBezierCurve.CubicBezierCurvePtNum; p++)
                    {
                        EditorGUI.BeginChangeCheck();
                        Handles.Label(handleTransform.TransformPoint(controlPoints[p]), string.Format("Control Point {0}", p + 1));
                        Vector3 newPt = Handles.DoPositionHandle(handleTransform.TransformPoint(controlPoints[p]), handleRotation);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(curve, "Move Point");
                            Undo.RecordObject(script, "Move Point");
                            EditorUtility.SetDirty(curve);
                            controlPoints[p] = handleTransform.InverseTransformPoint(newPt);
                        }
                    }

                    Handles.color = Color.gray;
                    Handles.DrawLine(handleTransform.TransformPoint(controlPoints[0]), handleTransform.TransformPoint(controlPoints[1]));
                    Handles.DrawLine(handleTransform.TransformPoint(controlPoints[1]), handleTransform.TransformPoint(controlPoints[2]));
                    Handles.DrawLine(handleTransform.TransformPoint(controlPoints[2]), handleTransform.TransformPoint(controlPoints[3]));

                    int sampleSize = 10;

                    Handles.color = Color.white;
                    for (int s = 0; s < sampleSize; s++)
                    {
                        Handles.DrawLine(handleTransform.TransformPoint(curve.GetPoint((float)s / sampleSize)), handleTransform.TransformPoint(curve.GetPoint((float)(s + 1) / sampleSize)));
                    }

                    curve.EDITOR_ControlPoints = controlPoints;
                }
            }


            if (script.RefCurves != null)
            {
                Handles.DrawLine(script.RefCurves[0].transform.TransformPoint(script.RefCurves[0].ControlPoints[0]), script.RefCurves[1].transform.TransformPoint(script.RefCurves[1].ControlPoints[0]));
                Handles.DrawLine(script.RefCurves[0].transform.TransformPoint(script.RefCurves[0].ControlPoints[3]), script.RefCurves[1].transform.TransformPoint(script.RefCurves[1].ControlPoints[3]));
            }

            script.Refresh();
        }
        protected void OnSceneGUI()
        {
            CUIBezierCurve script = (CUIBezierCurve)this.target;

            if (script.ControlPoints != null)
            {
                Vector3[] controlPoints = script.ControlPoints;

                Transform  handleTransform = script.transform;
                Quaternion handleRotation  = script.transform.rotation;

                for (int p = 0; p < CUIBezierCurve.CubicBezierCurvePtNum; p++)
                {
                    EditorGUI.BeginChangeCheck();
                    Vector3 newPt = Handles.DoPositionHandle(handleTransform.TransformPoint(controlPoints[p]), handleRotation);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(script, "Move Point");
                        EditorUtility.SetDirty(script);
                        controlPoints[p] = handleTransform.InverseTransformPoint(newPt);
                        script.Refresh();
                    }
                }

                Handles.color = Color.gray;
                Handles.DrawLine(handleTransform.TransformPoint(controlPoints[0]), handleTransform.TransformPoint(controlPoints[1]));
                Handles.DrawLine(handleTransform.TransformPoint(controlPoints[1]), handleTransform.TransformPoint(controlPoints[2]));
                Handles.DrawLine(handleTransform.TransformPoint(controlPoints[2]), handleTransform.TransformPoint(controlPoints[3]));

                int sampleSize = 10;

                Handles.color = Color.white;
                for (int s = 0; s < sampleSize; s++)
                {
                    Handles.DrawLine(handleTransform.TransformPoint(script.GetPoint((float)s / sampleSize)), handleTransform.TransformPoint(script.GetPoint((float)(s + 1) / sampleSize)));
                }

                script.EDITOR_ControlPoints = controlPoints;
            }
        }