public override void OnInspectorGUI()
    {
        LookAtUnityBezier _myLAUB = (LookAtUnityBezier)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Make new curve"))
        {
            Debug.Log("Button pressed.  Congrats!!!");

            BezierExample newBE = _myLAUB.myModel.gameObject.AddComponent <BezierExample>();

            if (_myLAUB.curveList.Count > 0)
            {
                BezierExample lastBE = _myLAUB.curveList[_myLAUB.curveList.Count - 1];

                newBE.startPoint   = lastBE.endPoint;
                newBE.endPoint     = lastBE.endPoint;
                newBE.startTangent = lastBE.endPoint;
                newBE.endTangent   = lastBE.endPoint;
            }

            _myLAUB.curveList.Add(newBE);
        }
    }
Beispiel #2
0
    private void OnSceneViewGUI(SceneView sv)
    {
        BezierExample be = target as BezierExample;

        be.startPoint   = Handles.PositionHandle(be.startPoint, Quaternion.identity);
        be.endPoint     = Handles.PositionHandle(be.endPoint, Quaternion.identity);
        be.startTangent = Handles.PositionHandle(be.startTangent, Quaternion.identity);
        be.endTangent   = Handles.PositionHandle(be.endTangent, Quaternion.identity);

        Handles.DrawBezier(be.startPoint, be.endPoint, be.startTangent, be.endTangent, Color.red, null, 2f);
    }
    public override void OnInspectorGUI()
    {
        LookAtUnityBezier _myLAUB = (LookAtUnityBezier)target;

        DrawDefaultInspector();

        if (GUILayout.Button("Make new curve"))
        {
            BezierExample newBE = _myLAUB.myModel.gameObject.AddComponent <BezierExample>();

            if (_myLAUB.curveList.Count > 0)
            {
                BezierExample lastBE = _myLAUB.curveList[_myLAUB.curveList.Count - 1];

                newBE.startPoint   = lastBE.endPoint;
                newBE.endPoint     = lastBE.endPoint;
                newBE.startTangent = lastBE.endPoint;
                newBE.endTangent   = lastBE.endPoint;
            }

            _myLAUB.curveList.Add(newBE);
        }

        if (GUILayout.Button("Close Loop"))
        {
            if (_myLAUB.curveList.Count > 1)
            {
                for (int i = 0; i < _myLAUB.curveList.Count; i++)
                {
                    BezierExample curve  = _myLAUB.curveList[i];
                    int           before = i - 1;
                    if (before < 0)
                    {
                        before = _myLAUB.curveList.Count - 1;
                    }
                    int after = i + 1;
                    if (after >= _myLAUB.curveList.Count)
                    {
                        after = 0;
                    }

                    curve.startPoint = _myLAUB.curveList[before].endPoint;
                    curve.endPoint   = (_myLAUB.curveList[after].startPoint + _myLAUB.curveList[i].endPoint) / 2;
                }
            }
        }
    }
    Vector3 CalculateBezier(BezierExample curveData, float t)
    {
        Vector3 a = curveData.startPoint;
        Vector3 b = curveData.startTangent;
        Vector3 c = curveData.endTangent;
        Vector3 d = curveData.endPoint;

        Vector3 ab = Vector3.Lerp(a, b, t);
        Vector3 bc = Vector3.Lerp(b, c, t);
        Vector3 cd = Vector3.Lerp(c, d, t);

        Vector3 abc = Vector3.Lerp(ab, bc, t);
        Vector3 bcd = Vector3.Lerp(bc, cd, t);

        Vector3 final = Vector3.Lerp(abc, bcd, t);

        return(final);
    }
Beispiel #5
0
    public override void OnInspectorGUI()
    {
        LookAtUnityBezier myLAUB = (LookAtUnityBezier)target; //casting class into object

        DrawDefaultInspector();
        if (GUILayout.Button("Make new curve"))
        {
            BezierExample newBE = myLAUB.myModel.gameObject.AddComponent <BezierExample>();
            if (myLAUB.curveList.Count > 0)
            {
                BezierExample lastBE = myLAUB.curveList[myLAUB.curveList.Count - 1];
                newBE.startPoint   = lastBE.endPoint;
                newBE.endPoint     = lastBE.endPoint;
                newBE.startTangent = lastBE.endPoint;
                newBE.endTangent   = lastBE.endPoint;
            }

            myLAUB.curveList.Add(newBE);
        }
    }
    // Update is called once per frame
    void Update()
    {
        float         pTime       = currentTime;
        int           pCurveIndex = (int)pTime % curveList.Count;
        float         pTangent    = pTime - (int)pTime;
        BezierExample pCurve      = curveList[pCurveIndex];
        Vector3       pPos        = GetPosFromCurve(pCurve, pTangent);

        currentTime += Time.deltaTime * moveSpeed;
        int           currentCurveIndex = (int)currentTime % curveList.Count;
        float         tangent           = currentTime - (int)currentTime;
        BezierExample currentCurve      = curveList[currentCurveIndex];
        Vector3       pos = GetPosFromCurve(currentCurve, tangent);

        Quaternion rotation = Quaternion.LookRotation(pos - pPos, Vector3.up);

        cam.rotation = Quaternion.Lerp(cam.rotation, rotation, Time.deltaTime * rotSpeed);

        cam.position = Vector3.Lerp(pPos, pos, Time.deltaTime);
    }
    private void OnSceneViewGUI(SceneView sv)
    {
        BezierExample be = target as BezierExample;

        be.startPoint   = Handles.PositionHandle(be.startPoint, Quaternion.identity);
        be.endPoint     = Handles.PositionHandle(be.endPoint, Quaternion.identity);
        be.startTangent = Handles.PositionHandle(be.startTangent, Quaternion.identity);
        be.endTangent   = Handles.PositionHandle(be.endTangent, Quaternion.identity);
        Handles.color   = Color.cyan;
        Handles.DotHandleCap(0, be.startPoint, Quaternion.identity, 0.1f, EventType.Repaint);
        Handles.DotHandleCap(0, be.endPoint, Quaternion.identity, 0.1f, EventType.Repaint);
        Handles.color = Color.magenta;
        Handles.DotHandleCap(0, be.startTangent, Quaternion.identity, 0.1f, EventType.Repaint);
        Handles.DotHandleCap(0, be.endTangent, Quaternion.identity, 0.1f, EventType.Repaint);
        Handles.DrawBezier(be.startPoint, be.endPoint, be.startTangent, be.endTangent, Color.yellow, null, 5f);
        Handles.Label(be.startPoint + Vector3.up * 2,
                      "[0]");
        Handles.Label(be.startTangent + Vector3.up * 2,
                      "(1)");
        Handles.Label(be.endTangent + Vector3.up * 2,
                      "(2)");
        Handles.Label(be.endPoint + Vector3.up * 2,
                      "[3]");
    }