[Memo-Unity] 21. AnimationCurve
์นดํ ๊ณ ๋ฆฌ: MeMo Unity
ํ๊ทธ: C#, MeMo Unity
AnimationCurve
AnimationCurve
AnimationCurve
๋ฐค๋ฎ ๊ตฌํ
AnimationCurve
DayNightCycle.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DayNightCycle : MonoBehaviour
{
[Range(0.0f, 1.0f)]
public float time;
public float fullDayLength;
public float startTime = 0.4f;
private float timeRate;
public Vector3 noon;
[Header("Sun")]
public Light sun;
public Gradient sunColor;
public AnimationCurve sunIntensity;
[Header("Moon")]
public Light moon;
public Gradient moonColor;
public AnimationCurve moonIntensity;
[Header("Other Lighting")]
public AnimationCurve lightingIntensityMultiplier;
public AnimationCurve reflectionIntensityMultiplier;
private void Start()
{
timeRate = 1.0f / fullDayLength;
time = startTime;
}
private void Update()
{
time = (time + timeRate * Time.deltaTime) % 1.0f;
UpdateLighting(sun, sunColor, sunIntensity);
UpdateLighting(moon, moonColor, moonIntensity);
RenderSettings.ambientIntensity = lightingIntensityMultiplier.Evaluate(time);
RenderSettings.reflectionIntensity = reflectionIntensityMultiplier.Evaluate(time);
}
void UpdateLighting(Light lightSource, Gradient colorGradiant, AnimationCurve intensityCurve)
{
float intensity = intensityCurve.Evaluate(time);
lightSource.transform.eulerAngles = (time - (lightSource == sun ? 0.25f : 0.75f)) * noon * 4.0f;
lightSource.color = colorGradiant.Evaluate(time);
lightSource.intensity = intensity;
GameObject go = lightSource.gameObject;
if (lightSource.intensity == 0 && go.activeInHierarchy)
go.SetActive(false);
else if (lightSource.intensity > 0 && !go.activeInHierarchy)
go.SetActive(true);
}
}
UpdateLighting
UpdateLighting(Light lightSource, Gradient colorGradiant, AnimationCurve intensityCurve)
float intensity = intensityCurve.Evaluate(time);
- ์ ๋๋ฉ์ด์ ์ปค๋ธ์์ ์๊ฐ๋ณ(x์ถ) y์ ๊ฐ์ intensity ์ ์ ์ฅ
- lightSource.transform.eulerAngles = (time - (lightSource == sun ? 0.25f : 0.75f)) * noon * 4.0f;
- ํ๋น์ ๊ฐ๋๋ฅผ ์๊ฐ๋ณ๋ก ์กฐ์
- lightSource.color = colorGradiant.Evaluate(time);
- ์๊ฐ์ ๋ฐ๋ฅธ ์์๊ฐ
- if, else if ๋ฌธ
sun
์ intensity ๊ฐ 0 ์ผ๋ time ์ด 0 ~ 0.2, 0.8 ~ 1.0 ์ผ๋ sun setActive(False)Moon
์ intensity ๊ฐ 0 ์ผ๋ time ์ด 0.3 ~ 0.7 ์ผ๋ setActive(False)
[Unity] AnimationCurve
TOP
๋๊ธ๋จ๊ธฐ๊ธฐ