Skip to content

Instantly share code, notes, and snippets.

@kakenn
Last active March 18, 2020 09:01
Show Gist options
  • Save kakenn/5fecf147b7b506dcf8b75afa1eb6be1c to your computer and use it in GitHub Desktop.
Save kakenn/5fecf147b7b506dcf8b75afa1eb6be1c to your computer and use it in GitHub Desktop.
UnityのタイムラインでライティングのAmbientColorを変えれるやつ
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);
}
}
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