Ejemplo n.º 1
0
        void OnGUI()
        {
            // before using the spline, ensure it's initialized and the Controller is available
            if (mSpline == null || !mSpline.IsInitialized || !Controller)
            {
                return;
            }

            var e = Event.current;

            switch (e.type)
            {
            case EventType.MouseDrag:
                // Start a new line?
                if (mResetSpline)
                {
                    mSpline.Clear();        // delete all Control Points
                    addCP(e.mousePosition); // add the first Control Point
                    Controller.gameObject.SetActive(true);
                    Controller.Position  = 0;
                    mLastControlPointPos = e.mousePosition;     // Store current mouse position
                    mResetSpline         = false;
                }
                else
                {
                    // only create a new Control Point if the minimum distance is reached
                    float dist = (e.mousePosition - mLastControlPointPos).magnitude;
                    if (dist >= StepDistance)
                    {
                        mLastControlPointPos = e.mousePosition;
                        addCP(e.mousePosition);
                        if (!Controller.IsPlaying)
                        {
                            Controller.Play();
                        }
                    }
                }

                break;

            case EventType.MouseUp:
                mResetSpline = true;

                break;
            }
        }