Last active
March 18, 2020 09:01
-
-
Save kakenn/5fecf147b7b506dcf8b75afa1eb6be1c to your computer and use it in GitHub Desktop.
UnityのタイムラインでライティングのAmbientColorを変えれるやつ
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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Playables; | |
public class SkyColorChangeAsset : PlayableAsset | |
{ | |
[SerializeField] public Color startColor; | |
[SerializeField] public Color endColor; | |
public override Playable CreatePlayable(PlayableGraph graph, GameObject gameObject) | |
{ | |
SkyColorChangeBehaviour behaviour = new SkyColorChangeBehaviour(); | |
behaviour.startColor = startColor; | |
behaviour.endColor = endColor; | |
return ScriptPlayable<SkyColorChangeBehaviour>.Create(graph, behaviour); | |
} | |
} | |
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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Playables; | |
[System.Serializable] | |
public class SkyColorChangeBehaviour : PlayableBehaviour | |
{ | |
public Color startColor; | |
public Color endColor; | |
private float _startTime; | |
private float _duration; | |
public override void OnGraphStart(Playable playable) | |
{ | |
_duration = (float) playable.GetDuration(); | |
} | |
public override void OnBehaviourPlay(Playable playable, FrameData info) | |
{ | |
_startTime = Time.time; | |
} | |
public override void PrepareFrame(Playable playable, FrameData info) | |
{ | |
float t = (Time.time - _startTime) / _duration; | |
RenderSettings.ambientLight = Color.Lerp(startColor, endColor, t); | |
Debug.Log(RenderSettings.ambientLight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment