void OnSceneGUI()
    {
        Vector3 newPosition = bezierControlPoint.worldControlPoint;// bezierControlPoint.controlPoint + bezierControlPoint.transform.position;
        float   handlesize  = HandleUtility.GetHandleSize(newPosition) * 0.6f;

        Handles.color = new Color(0.99f, 0.50f, 0.35f);
        newPosition   = Handles.Slider(newPosition, Vector3.right, handlesize, Handles.ArrowCap, 1);
        Handles.color = new Color(0.30f, 0.85f, 0.99f);
        newPosition   = Handles.Slider(newPosition, Vector3.forward, handlesize, Handles.ArrowCap, 1);
        Handles.color = new Color(0.85f, 0.95f, 0.30f);
        newPosition   = Handles.Slider(newPosition, Vector3.up, handlesize, Handles.ArrowCap, 1);

        //Tilting draw function for follow path
        if (bezier.mode == CameraPathBezier.viewmodes.followpath || bezier.mode == CameraPathBezier.viewmodes.reverseFollowpath)
        {
            Handles.color = Color.yellow;
            float      tiltScale = HandleUtility.GetHandleSize(bezierControlPoint.transform.position) * 1.25f;
            Vector3    forward   = bezierControlPoint.GetPathDirection().normalized *tiltScale;
            Quaternion fwdRot    = Quaternion.LookRotation(forward);
            Vector3    tilt      = Quaternion.Euler(0, 0, -bezierControlPoint.tilt) * (Vector3.up * tiltScale);
            Handles.DrawWireDisc(bezierControlPoint.transform.position, forward, tiltScale);
            Handles.DrawLine(bezierControlPoint.transform.position, bezierControlPoint.transform.position + fwdRot * tilt);
        }


        Handles.color = Color.red;
        Handles.DrawLine(bezierControlPoint.transform.position, bezierControlPoint.worldControlPoint);

        if (bezierControlPoint.worldControlPoint != newPosition)
        {
            GUI.changed = true;
            bezierControlPoint.worldControlPoint = newPosition;
        }

        Handles.Label(bezierControlPoint.transform.position + Vector3.up * HandleUtility.GetHandleSize(newPosition) * 2f, bezierControlPoint.name);

        Handles.color = (Color.white - bezier.lineColour) + new Color(0, 0, 0, 1);
        Handles.ArrowCap(0, previewCamPos, previewCamRot, handlesize * 1.5f);

        if (GUI.changed)
        {
            bezier.RecalculateStoredValues();
            Undo.RegisterUndo(bezierControlPoint, "Move Control Point");
            EditorUtility.SetDirty(bezierControlPoint);
            EditorUtility.SetDirty(bezier);
            EditorUtility.SetDirty(animator);
        }
    }
 //Ensure that the CP has not been moved
 public void CheckPosition()
 {
     if (transform.position != storedPosition)
     {
         bezier.RecalculateStoredValues();
         storedPosition = transform.position;
     }
 }
Exemplo n.º 3
0
    public void OnSceneGUI()
    {
        CameraPathBezier bezier = (CameraPathBezier)target;

        if (GUI.changed)
        {
            bezier.RecalculateStoredValues();
            EditorUtility.SetDirty(bezier);
        }
    }
Exemplo n.º 4
0
    void Start()
    {
        bezier = GetComponent <CameraPathBezier>();
        bezier.RecalculateStoredValues();
        playing = playOnStart;

        _percentage = 0;

        Vector3 initalRotation = bezier.GetPathRotation(0).eulerAngles;

        rotationX = initalRotation.y;
        rotationY = initalRotation.x;
    }
    public void OnSceneGUI()
    {
        if (animator.showScenePreview)
        {
            float handleSize = HandleUtility.GetHandleSize(previewCamPos * 0.5f);
            Handles.color = (Color.white - bezier.lineColour) + new Color(0, 0, 0, 1);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.up * 0.5f);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.down * 0.5f);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.left * 0.5f);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.right * 0.5f);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.forward * 0.5f);
            Handles.DrawLine(previewCamPos, previewCamPos + Vector3.back * 0.5f);

            Handles.ArrowHandleCap(0, previewCamPos, previewCamRot, handleSize, EventType.Repaint);
            Handles.Label(previewCamPos, "Preview\nCamera\nPosition");
        }

        if (GUI.changed)
        {
            bezier.RecalculateStoredValues();
            EditorUtility.SetDirty(animator);
            EditorUtility.SetDirty(bezier);
        }
    }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        CameraPathBezier bezier   = (CameraPathBezier)target;
        int numberOfControlPoints = bezier.numberOfControlPoints;

        if (numberOfControlPoints > 0)
        {
            if (numberOfControlPoints > 1)
            {
                GUILayout.Space(10);
                bezier.lineColour = EditorGUILayout.ColorField("Line Colour", bezier.lineColour);
                GUILayout.Space(5);

                bezier.mode = (CameraPathBezier.viewmodes)EditorGUILayout.EnumPopup("Camera Mode", bezier.mode);
                GUILayout.Space(5);

                if (bezier.mode == CameraPathBezier.viewmodes.target)
                {
                    if (bezier.target == null)
                    {
                        EditorGUILayout.HelpBox("No target has been specified in the bezier path", MessageType.Warning);
                    }
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Look at Target");
                    bezier.target = (Transform)EditorGUILayout.ObjectField(bezier.target, typeof(Transform), true);
                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(5);
                }

                bool newValue = EditorGUILayout.Toggle("Loop", bezier.loop);
                if (newValue != bezier.loop)
                {
                    Undo.RecordObject(bezier, "Set Loop");
                    bezier.loop = newValue;
                    bezier.RecalculateStoredValues();
                }
            }
            else
            {
                if (numberOfControlPoints == 1)
                {
                    EditorGUILayout.HelpBox("Click Add New Point to add additional points, you need at least two points to make a path.", MessageType.Info);
                }
            }

            GUILayout.Space(5);
            if (GUILayout.Button("Reset Path"))
            {
                if (EditorUtility.DisplayDialog("Resetting path?", "Are you sure you want to delete all control points?", "Delete", "Cancel"))
                {
                    //Undo.RegisterSceneUndo("Reset Camera Path");
                    bezier.ResetPath();
                    return;
                }
            }

            GUILayout.Space(10);
            GUILayout.Box(EditorGUIUtility.whiteTexture, GUILayout.Height(2), GUILayout.Width(Screen.width - 20));
            GUILayout.Space(3);

            //scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            for (int i = 0; i < numberOfControlPoints; i++)
            {
                CameraPathBezierControlPoint go = bezier.controlPoints[i];

                if (go == null)
                {
                    go = (CameraPathBezierControlPoint)EditorGUILayout.ObjectField(null, typeof(CameraPathBezierControlPoint), true);
                }
                else
                {
                    go = (CameraPathBezierControlPoint)EditorGUILayout.ObjectField(go.name, go, typeof(CameraPathBezierControlPoint), true);
                }

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Delete"))
                {
                    //Undo.RegisterSceneUndo("Delete Camera Path point");
                    bezier.DeletePoint(i, true);
                    numberOfControlPoints = bezier.numberOfControlPoints;
                    EditorUtility.SetDirty(bezier);
                    return;
                }

                if (i == numberOfControlPoints - 1)
                {
                    if (GUILayout.Button("Add New Point At End"))
                    {
                        //Undo.RegisterSceneUndo("Create a new Camera Path point");
                        bezier.AddNewPoint(i + 1);
                        EditorUtility.SetDirty(bezier);
                    }
                }
                else
                {
                    if (GUILayout.Button("Add New Point Between"))
                    {
                        //Undo.RegisterSceneUndo("Create a new Camera Path point");
                        bezier.AddNewPoint(i + 1);
                        EditorUtility.SetDirty(bezier);
                    }
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(7);
                GUILayout.Box(EditorGUIUtility.whiteTexture, GUILayout.Height(2), GUILayout.Width(Screen.width - 25));
                GUILayout.Space(7);
            }
            //EditorGUILayout.EndScrollView();
        }
        else
        {
            if (GUILayout.Button("Add New Point At End"))
            {
                //Undo.RegisterSceneUndo("Create a new Camera Path point");
                bezier.AddNewPoint();
                EditorUtility.SetDirty(bezier);
            }
            EditorGUILayout.HelpBox("Click Add New Point to add points and begin the path, you will need two points to create a path.", MessageType.Info);
        }

        if (GUI.changed)
        {
            bezier.RecalculateStoredValues();
            EditorUtility.SetDirty(bezier);
        }
    }