using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
public class PPController : MonoBehaviour
{
public PostProcessVolume ppv;
public ColorGrading cgd;
float value = 1;
float transValue;
public float counter;
bool change = true;
public float changeTime;
// Start is called before the first frame update
void Start()
{
//抓取PostProcessVolume
ppv = gameObject.GetComponent<PostProcessVolume>();
//抓取PostProcessVolume裡面的ColorGrading
cgd = ppv.profile.GetSetting<ColorGrading>();
}
// Update is called once per frame
void Update()
{
//紅轉(zhuǎn)白或白轉(zhuǎn)紅
if(change){
//value之值會(huì)在0至1之間線性增減
value += 1f/changeTime * Time.deltaTime;
//感覺(jué)用三角函數(shù)在偏紅色區(qū)段會(huì)停留更久一些
transValue = 1+Mathf.Cos(value*Mathf.PI/2f);
}else{
value -= 1f/changeTime * Time.deltaTime;
transValue = 1+Mathf.Cos(value*Mathf.PI/2f);
}
//時(shí)間到要改變顏色方向
if(counter > changeTime){
change = !change;
counter = 0;
}
counter +=Time.deltaTime;
//輸入值
cgd.mixerGreenOutGreenIn.value = transValue*100f;
cgd.mixerBlueOutBlueIn.value = transValue*100f;
}
}