56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Rendering.Universal;
|
|||
|
public class CircadianSystem : MonoBehaviour
|
|||
|
{
|
|||
|
private Light2D globalLight; // 2D ȫ<>ֹ<EFBFBD>Դ
|
|||
|
public Gradient lightColor; // <20>ƹ<EFBFBD><C6B9><EFBFBD>ɫ<EFBFBD><C9AB>ʱ<EFBFBD><CAB1><EFBFBD>仯
|
|||
|
[Header("<22><>Χ1-4")]
|
|||
|
public AnimationCurve lightIntensity; // <20>ƹ<EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
[Header("ģ<><C4A3>ʱ<EFBFBD><CAB1>")]
|
|||
|
[Range(0, 24)] public float currentTime = 12f; // <20><>ǰʱ<C7B0>䣨0-24Сʱ<D0A1><CAB1>
|
|||
|
[Header("һ<><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>룩")]
|
|||
|
public float dayDuration = 24f;
|
|||
|
|
|||
|
private float timeMultiplier
|
|||
|
{
|
|||
|
get { return 24f / dayDuration; }
|
|||
|
}
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
globalLight = transform.Find("ȫ<>ֹ<EFBFBD>").GetComponent<Light2D>();
|
|||
|
}
|
|||
|
void Start()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
UpdateTime();
|
|||
|
UpdateLighting();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
private void UpdateTime()
|
|||
|
{
|
|||
|
currentTime += Time.deltaTime * timeMultiplier;
|
|||
|
if (currentTime >= 24f) currentTime = 0f; // ʱ<><CAB1>ѭ<EFBFBD><D1AD>
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>µƹ<C2B5>״̬
|
|||
|
private void UpdateLighting()
|
|||
|
{
|
|||
|
float normalizedTime = currentTime / 24f; // <20><>һ<EFBFBD><D2BB>ʱ<EFBFBD>䣨0-1<><31>
|
|||
|
|
|||
|
// <20><><EFBFBD>õƹ<C3B5><C6B9><EFBFBD>ɫ
|
|||
|
globalLight.color = lightColor.Evaluate(normalizedTime);
|
|||
|
|
|||
|
// <20><><EFBFBD>õƹ<C3B5>ǿ<EFBFBD><C7BF>
|
|||
|
globalLight.intensity = lightIntensity.Evaluate(normalizedTime*4);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|