Skip to content
Snippets Groups Projects
Select Git revision
  • 9ea37b3e6f7a18fb671fa7fc0ab975cc29320441
  • master default
  • JS-based-scroll-rendering
  • Paul_Marius_Level
  • Paul_Marius_2
  • Paul_Marius
  • Andi_Mark
  • be-UnityWebView
  • gitignoreFrameitServer
  • ZimmerBSc
  • Bugfix_StageLoading
  • stages
  • MAZIFAU_Experimental
  • tsc/coneworld
  • tsc/fact-interaction
  • marcel
  • MaZiFAU_TopSort
  • mergeHelper
  • zwischenSpeichern
  • tempAndrToMaster
  • SebBranch
  • 3.0
  • v2.1
  • v2.0
  • v1.0
25 results

Restart.cs.meta

Blame
  • FOVKick.cs 2.35 KiB
    using System;
    using System.Collections;
    using UnityEngine;
    
    namespace UnityStandardAssets.Utility
    {
        [Serializable]
        public class FOVKick
        {
            public Camera Camera;                           // optional camera setup, if null the main camera will be used
            [HideInInspector] public float originalFov;     // the original fov
            public float FOVIncrease = 3f;                  // the amount the field of view increases when going into a run
            public float TimeToIncrease = 1f;               // the amount of time the field of view will increase over
            public float TimeToDecrease = 1f;               // the amount of time the field of view will take to return to its original size
            public AnimationCurve IncreaseCurve;
    
    
            public void Setup(Camera camera)
            {
                CheckStatus(camera);
    
                Camera = camera;
                originalFov = camera.fieldOfView;
            }
    
    
            private void CheckStatus(Camera camera)
            {
                if (camera == null)
                {
                    throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
                }
    
                if (IncreaseCurve == null)
                {
                    throw new Exception(
                        "FOVKick Increase curve is null, please define the curve for the field of view kicks");
                }
            }
    
    
            public void ChangeCamera(Camera camera)
            {
                Camera = camera;
            }
    
    
            public IEnumerator FOVKickUp()
            {
                float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
                while (t < TimeToIncrease)
                {
                    Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
                    t += Time.deltaTime;
                    yield return new WaitForEndOfFrame();
                }
            }
    
    
            public IEnumerator FOVKickDown()
            {
                float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
                while (t > 0)
                {
                    Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
                    t -= Time.deltaTime;
                    yield return new WaitForEndOfFrame();
                }
                //make sure that fov returns to the original size
                Camera.fieldOfView = originalFov;
            }
        }
    }