public void OnSceneGUI() { CameraPathBezier bezier = (CameraPathBezier)target; if (GUI.changed) { bezier.RecalculateStoredValues(); EditorUtility.SetDirty(bezier); } }
void Start() { bezier = GetComponent <CameraPathBezier>(); bezier.RecalculateStoredValues(); playing = playOnStart; _percentage = 0; Vector3 initalRotation = bezier.GetPathRotation(0).eulerAngles; rotationX = initalRotation.y; rotationY = initalRotation.x; }
//normalise the curve and apply easing public float RecalculatePercentage(float percentage) { if (!bezier) { bezier = GetComponent <CameraPathBezier>(); } if (bezier.numberOfControlPoints == 0) { return(percentage); } float normalisedPercentage = bezier.GetNormalisedT(percentage); int numberOfCurves = bezier.numberOfCurves; float curveT = 1.0f / (float)numberOfCurves; int point = Mathf.FloorToInt(normalisedPercentage / curveT); float curvet = Mathf.Clamp01((normalisedPercentage - point * curveT) * numberOfCurves); return(bezier.controlPoints[point]._curve.Evaluate(curvet) / numberOfCurves + (point * curveT)); }
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); } }
void OnEnable() { bezierControlPoint = (CameraPathBezierControlPoint)target; bezier = bezierControlPoint.bezier; animator = bezier.GetComponent<CameraPathBezierAnimator>(); }
void OnEnable() { animator = (CameraPathBezierAnimator)target; bezier = animator.GetComponent <CameraPathBezier>(); }
void OnEnable() { bezierControlPoint = (CameraPathBezierControlPoint)target; bezier = bezierControlPoint.bezier; animator = bezier.GetComponent <CameraPathBezierAnimator>(); }
void OnGUI() { if (pathAnimator == null) { return; } if (GUILayout.Button("START")) { pathAnimator.Play(); } if (GUILayout.Button("PAUSE")) { pathAnimator.Pause(); } if (GUILayout.Button("STOP")) { pathAnimator.Stop(); } if (GUILayout.Button("SWITCH")) { pathAnimator.Stop(); if (pathAnimator == pathAnimatorA) { pathAnimator = pathAnimatorB; } else { pathAnimator = pathAnimatorA; } pathAnimator.Play(); } if (GUILayout.Button("JUMP")) { pathAnimator.Stop(); pathAnimator.Seek(0.75f); pathAnimator.Play(); } if (!pathAnimator.isPlaying) { if (GUILayout.Button("REPLAY")) { if (pathAnimator.mode != CameraPathBezierAnimator.modes.reverse) { pathAnimator.Seek(0); } else { pathAnimator.Seek(1); } pathAnimator.Play(); } } GUILayout.Space(10.0f); GUILayout.Label("ANIMATION MODE"); GUILayout.Label("current:" + pathAnimator.mode); if (GUILayout.Button("FORWARD")) { pathAnimator.mode = CameraPathBezierAnimator.modes.once; } if (GUILayout.Button("REVERSE")) { pathAnimator.mode = CameraPathBezierAnimator.modes.reverse; } if (GUILayout.Button("LOOP")) { pathAnimator.mode = CameraPathBezierAnimator.modes.loop; } //Urgh! This is cheap way of doing things - better to keep this value stored somewhere instead of setting it every frame... CameraPathBezier bezier = pathAnimator.bezier; GUILayout.Space(10.0f); GUILayout.Label("CAMERA MODE"); GUILayout.Label("current:" + bezier.mode); if (GUILayout.Button("USER CONTROLLED")) { bezier.mode = CameraPathBezier.viewmodes.usercontrolled; } if (GUILayout.Button("MOUSE LOOK")) { bezier.mode = CameraPathBezier.viewmodes.mouselook; } if (GUILayout.Button("FOLLOW PATH")) { bezier.mode = CameraPathBezier.viewmodes.followpath; } if (GUILayout.Button("REVERSE FOLLOW PATH")) { bezier.mode = CameraPathBezier.viewmodes.reverseFollowpath; } }
void OnEnable() { animator = (CameraPathBezierAnimator)target; bezier = animator.GetComponent<CameraPathBezier>(); }