Esempio n. 1
0
    public static void CreateXSpline()
    {
        GameObject       go     = new GameObject("XSpline");
        XSplineComponent spcomp = go.AddComponent <XSplineComponent>();

        spcomp.Spline.AppendPoint(Vector3.zero, XSpline.BezierPointType.Smooth, Vector3.zero, Vector3.zero);

        spcomp.Spline.AppendPoint(spcomp.Spline.mPoints[spcomp.Spline.mPoints.Count - 1].mPoint + Vector3.right, XSpline.BezierPointType.Smooth, Vector3.zero, Vector3.zero);


        spcomp.Spline.Build();
        spcomp.RefreshElements();
    }
Esempio n. 2
0
    void OnSceneGUI()
    {
        if (mSplinecomp != null)
        {
            bool  selected = false;
            float hsize;

            Vector3 pPrev, pNext, pPos = Vector3.zero;

            EditorGUI.BeginChangeCheck();

            Handles.matrix = mSplinecomp.transform.localToWorldMatrix;

            mEdithelper.Reset();
            while (mEdithelper.MoveNext())
            {
                hsize = HandleUtility.GetHandleSize(mEdithelper.Point.mPoint) * 1f;

                if (Handles.Button(mEdithelper.Point.mPoint, Quaternion.identity, hsize * mPointSize, hsize * mPointSize, DrawPoint))
                {
                    mEdithelper.Selected = true;
                    selected             = true;
                }



                bool  isKeydown = false;
                Event e         = Event.current;
                Tools.hidden = false;
                if (e.alt || e.shift || e.control)
                {
                    isKeydown    = true;
                    Tools.hidden = true;
                }

                if (mEdithelper.Selected && !isKeydown)
                {
                    Handles.ArrowCap(0, mEdithelper.SelectedPoint.mPoint, Quaternion.LookRotation(Vector3.up), HandleUtility.GetHandleSize(mEdithelper.SelectedPoint.mPoint));

                    if (mSpline.InterpolateType == XSpline.SplineType.Bezier && mEdithelper.SelectedPoint.mBezierType != XSpline.BezierPointType.Smooth)
                    {
                        Handles.color = new Color(1, 1, 0, 1);
                        Handles.DrawLine(mEdithelper.SelectedPoint.mPoint, mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mPrevctrl);
                        Handles.DrawLine(mEdithelper.SelectedPoint.mPoint, mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mNextctrl);

                        Handles.color = Color.green;
                        Handles.DotCap(0, mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mPrevctrl, Tools.handleRotation, hsize * mPointSize);
                        Handles.DotCap(0, mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mNextctrl, Tools.handleRotation, hsize * mPointSize);

                        pPrev = Handles.PositionHandle(mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mPrevctrl, Tools.handleRotation);
                        pNext = Handles.PositionHandle(mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mNextctrl, Tools.handleRotation);

                        bool chgOut = (mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mPrevctrl) != pPrev;
                        bool chgIn  = (mEdithelper.SelectedPoint.mPoint + mEdithelper.SelectedPoint.mNextctrl) != pNext;

                        if (chgOut || chgIn)
                        {
                            if (chgOut)
                            {
                                mEdithelper.SelectedPoint.mPrevctrl = pPrev - mEdithelper.SelectedPoint.mPoint;
                                if (mEdithelper.SelectedPoint.mBezierType != XSpline.BezierPointType.BezierCorner)
                                {
                                    mEdithelper.SelectedPoint.mNextctrl = -mEdithelper.SelectedPoint.mPrevctrl;
                                }
                            }
                            if (chgIn)
                            {
                                mEdithelper.SelectedPoint.mNextctrl = pNext - mEdithelper.SelectedPoint.mPoint;
                                if (mEdithelper.SelectedPoint.mBezierType != XSpline.BezierPointType.BezierCorner)
                                {
                                    mEdithelper.SelectedPoint.mPrevctrl = -mEdithelper.SelectedPoint.mNextctrl;
                                }
                            }
                        }
                    }

                    //handle point pos
                    pPos = Handles.PositionHandle(mEdithelper.SelectedPoint.mPoint, Tools.handleRotation);
                    if (mEdithelper.SelectedPoint.mPoint != pPos)
                    {
                        mEdithelper.SelectedPoint.mPoint = pPos;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
            }

            if (GUI.changed)
            {
                mSpline.Build();
                mSplinecomp.RefreshElements();
                EditorUtility.SetDirty(mSplinecomp);
                Repaint();
            }
            if (selected)
            {
                Repaint();
                SceneView.RepaintAll();
                GUIUtility.keyboardControl = 0;
            }
        }
    }