Files
PrinceOfGlory/Assets/Scripts/Help/CameraGradient.cs
kridoo 6e91a0c7f0 111
2025-09-15 17:32:08 +08:00

128 lines
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BigSpace.XRCore.Event;
using BigSpace.Logic;
public class CameraGradient : MonoBehaviour
{
public GameObject cube;
public MeshRenderer material;
Color color;
//bool isGoBlack = false; //±äºÚ
//bool isGoTransparent = false; //͸Ã÷
////¼ÆÊ±Ïà¹Ø
//float waitTime = 2f;
// Start is called before the first frame update
void Start()
{
color = new Color(0, 0, 0, 0);
GlobalEventMgr.Listen<bool,float>(GameEvent.EventChangeCameraTransparent, GameDataManage_EventChangeCameraTransparent);
}
// Update is called once per frame
void Update()
{
//if (isGoBlack)
//{
// //runTime += Time.deltaTime;
// color.a = runTime/ waitTime;
// material.materials[0].SetColor("_BaseColor", color);
// if (runTime >= waitTime)
// {
// color.a = 1;
// material.materials[0].SetColor("_BaseColor", color);
// isGoBlack = false;
// runTime = 0;
// }
//}
//if (isGoTransparent)
//{
// runTime += Time.deltaTime;
// color.a = 1 - runTime/ waitTime;
// material.materials[0].SetColor("_BaseColor", color);
// if (runTime >= waitTime)
// {
// color.a = 0;
// material.materials[0].SetColor("_BaseColor", color);
// isGoTransparent = false;
// runTime = 0;
// cube.SetActive(false);
// }
//}
}
private IEnumerator Fade(float startAlpha, float endAlpha, float duration)
{
float time = 0;
while (time < duration)
{
time += Time.deltaTime;
color.a = Mathf.Lerp(startAlpha, endAlpha, time / duration);
material.materials[0].SetColor("_BaseColor", color);
yield return null;
}
color.a = endAlpha;
if(endAlpha==0)
cube.SetActive(false);
}
//private IEnumerator Fade(float startAlpha, float endAlpha, float duration)
//{
// float time = 0;
// while (time < duration)
// {
// time += Time.deltaTime;
// canvasGroup.alpha = Mathf.Lerp(startAlpha, endAlpha, time / duration);
// yield return null;
// }
// canvasGroup.alpha = endAlpha;
// fadeCompleteCallback?.Invoke();
// fadeCompleteCallback = null;
//}
private void GameDataManage_EventChangeCameraTransparent(bool isShow,float waitTime)
{
Debug.Log("CameraÊÕµ½Ê¼þ:"+isShow);
if (isShow)
{
SetBlack();
}
else
{
SetTransparent();
//StartCoroutine(WaitSet(waitTime));
}
}
//IEnumerator WaitSet(float waitTime)
//{
// yield return new WaitForSeconds(waitTime); //;µÈ´ýÖ´ÐÐ
// SetTransparent();
//}
void SetBlack()
{
color.a = 0;
material.materials[0].SetColor("_BaseColor", color);
cube.SetActive(true);
StartCoroutine(Fade(0,1,1.5f));
}
void SetTransparent()
{
color.a = 1;
material.materials[0].SetColor("_BaseColor", color);
cube.SetActive(true);
StartCoroutine(Fade(1, 0, 1.5f));
}
}