Reset camera rotation

Back
Tags:
Tileset
Camera
Example of animated reset camera rotation.
Requirement: Tileset Control
Allow Camera Control - ON
Usage instructions:
Add this script to map GameObject and start the scene.
Rotate the camera on and click Reset, to smoothly return the camera to its original position.
ResetCameraRotationExample.cs
/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Example of animated reset camera rotation.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/ResetCameraRotationExample")]
    public class ResetCameraRotationExample : MonoBehaviour
    {
        /// <summary>
        /// Reference to the camera orbit.
        /// </summary>
        public OnlineMapsCameraOrbit cameraOrbit;

        /// <summary>
        /// Default rotation of camera.
        /// </summary>
        public Vector2 defaultRotation = Vector2.zero;

        /// <summary>
        /// Time of animation (sec).
        /// </summary>
        public float animationTime = 3;

        /// <summary>
        /// Animation Curve.
        /// </summary>
        public AnimationCurve animationCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);

        private float time;
        private bool isReset;
        private float camX;
        private float camY;

        private void OnGUI()
        {
            if (GUI.Button(new Rect(5, 5, 100, 30), "Reset") && !isReset)
            {
                // Store the current rotation, and marks that reset is started.
                camX = cameraOrbit.rotation.x;
                camY = cameraOrbit.rotation.y;
                isReset = true;
            }
        }

        private void Start()
        {
            // If the camera orbit is not specified, get the current instance.
            if (cameraOrbit == null) cameraOrbit = OnlineMapsCameraOrbit.instance;
        }

        private void Update()
        {
            if (!isReset) return;

            // Updating the progress of the animation.
            time += Time.deltaTime;
            float t = time / animationTime;

            // If the animation is finished
            if (t >= 1)
            {
                // Reset values
                time = 0;
                isReset = false;
                t = 1;
            }

            // Update the rotation of camera.
            float f = animationCurve.Evaluate(t);
            cameraOrbit.rotation.x = Mathf.LerpAngle(camX, defaultRotation.x, f);
            cameraOrbit.rotation.y = Mathf.Lerp(camY, defaultRotation.y, f);
        }
    }
}