Created
January 10, 2021 23:28
-
-
Save rodellison/e42d7dcc409e4f120ce13ddcb0cc0852 to your computer and use it in GitHub Desktop.
A (Unity monobehaviour) script for animating Deckard Render transitions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using UnityEngine; | |
/// <summary> | |
/// A Monobehaviour class with routines to animate certain Deckard Render properties | |
/// </summary> | |
public class AnimateDeckardRenderProps : MonoBehaviour | |
{ | |
private DeckardRender.DeckardRender myDeckardRender; | |
private float OriginalDeckardRenderFStop; | |
private float OriginalDeckardRenderShutterAngle; | |
/// <summary> | |
/// At start, get a reference to the Deckard Render component and the original FStop and Shutter Angle values. | |
/// </summary> | |
public void Start() | |
{ | |
myDeckardRender = GetComponent<DeckardRender.DeckardRender>(); | |
OriginalDeckardRenderFStop = myDeckardRender.fStop; | |
OriginalDeckardRenderShutterAngle = myDeckardRender.shutterAngle; | |
} | |
/// <summary> | |
/// Public method that can be called by a Timeline Trigger/Signal receiver to setup FStop animation | |
/// </summary> | |
/// <param name="parms">A pipe '|' delimited string that will provide the values to be used in the | |
/// Coroutine. | |
/// </param> | |
public void AnimateChangeFStop(string parms) | |
{ | |
StartCoroutine(ChangeFStopRoutine(parms)); | |
} | |
/// <summary> | |
/// Public method that can be called by a Timeline Trigger/Signal receiver to setup Shutter Angle animation | |
/// </summary> | |
/// <param name="parms">A pipe '|' delimited string that will provide the values to be used in the | |
/// Coroutine. | |
/// </param> | |
public void AnimateChangeShutterAngle(string parms) | |
{ | |
StartCoroutine(ChangeShutterAngleRoutine(parms)); | |
} | |
/// <summary> | |
/// Coroutine to animate FStop value over time | |
/// </summary> | |
/// <param name="parms">A pipe '|' delimited string that will provide the values to be used in the | |
/// Coroutine. Essentially, the parm string should be similar to: "5|11|4", which says.. | |
/// Over a period of 5 seconds, animate from FStop 11 to FStop 4</param> | |
/// <returns>NA</returns> | |
IEnumerator ChangeFStopRoutine(string parmVals) | |
{ | |
string[] parms = parmVals.Split('|'); | |
var duration = float.Parse(parms[0]); | |
var startingFStop = float.Parse(parms[1]); | |
var endingFStop = float.Parse(parms[2]); | |
for (float t = 0f; t < duration; t += Time.deltaTime) | |
{ | |
float normalizedTime = t / duration; | |
myDeckardRender.fStop = Mathf.SmoothStep(startingFStop, endingFStop, normalizedTime); | |
yield return null; | |
} | |
myDeckardRender.fStop = endingFStop; | |
} | |
/// <summary> | |
/// Coroutine to animate Shutter Angle value over time | |
/// </summary> | |
/// <param name="parms">A pipe '|' delimited string that will provide the values to be used in the | |
/// Coroutine. Essentially, the parm string should be similar to: "5|180|45", which says.. | |
/// Over a period of 5 seconds, animate from Shutter Angle 180 to 45</param> | |
/// <returns>NA</returns> | |
IEnumerator ChangeShutterAngleRoutine(string parmVals) | |
{ | |
string[] parms = parmVals.Split('|'); | |
var duration = float.Parse(parms[0]); | |
var startingAngle = float.Parse(parms[1]); | |
var endingAngle = float.Parse(parms[2]); | |
for (float t = 0f; t < duration; t += Time.deltaTime) | |
{ | |
float normalizedTime = t / duration; | |
myDeckardRender.shutterAngle = Mathf.SmoothStep(startingAngle, endingAngle, normalizedTime); | |
yield return null; | |
} | |
myDeckardRender.shutterAngle = endingAngle; | |
} | |
/// <summary> | |
/// Public method that can be called by a Timeline Trigger/Signal receiver to reset Shutter Angle to the | |
/// original value | |
/// </summary> | |
public void ResetShutterAngle() | |
{ | |
myDeckardRender.shutterAngle = OriginalDeckardRenderShutterAngle; | |
} | |
/// <summary> | |
/// Public method that can be called by a Timeline Trigger/Signal receiver to reset FStop to the | |
/// original value | |
/// </summary> | |
public void ResetFStop() | |
{ | |
myDeckardRender.fStop = OriginalDeckardRenderFStop; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment