2024-11-23 14:25:10 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
public class FadeToBlack : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float fadeDuration = 1.5f; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
private Image blackImage;
|
2024-11-23 15:28:39 +08:00
|
|
|
|
public GameObject LightLinp;//<2F>ƹ<EFBFBD>
|
2024-11-23 14:25:10 +08:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
blackImage = GetComponent<Image>();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>ⲿ<EFBFBD><E2B2BF><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public void StartFade()
|
|
|
|
|
{
|
2024-11-23 15:28:39 +08:00
|
|
|
|
LightLinp.SetActive(false);
|
2024-11-23 14:25:10 +08:00
|
|
|
|
StartCoroutine(FadeToBlackCoroutine());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>ⲿ<EFBFBD><E2B2BF><EFBFBD>ã<EFBFBD>ֱ<EFBFBD>ӱ<EFBFBD><D3B1><EFBFBD>
|
|
|
|
|
public void InstantBlack()
|
|
|
|
|
{
|
|
|
|
|
blackImage.color = new Color(0, 0, 0, 1f); // <20><><EFBFBD><EFBFBD>Ϊȫ<CEAA><C8AB>
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 15:28:39 +08:00
|
|
|
|
public void ReturnWhite()
|
|
|
|
|
{
|
|
|
|
|
LightLinp.SetActive(true);
|
|
|
|
|
blackImage.color = new Color(0, 0, 0, 0f); // <20><><EFBFBD><EFBFBD>Ϊȫ<CEAA><C8AB>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-23 14:25:10 +08:00
|
|
|
|
// Э<>̣<EFBFBD><CCA3><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
private IEnumerator FadeToBlackCoroutine()
|
|
|
|
|
{
|
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
|
|
2024-11-23 15:28:39 +08:00
|
|
|
|
// Ŀ<><C4BF><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|
|
|
|
float targetAlpha = 0.6f;
|
|
|
|
|
|
2024-11-23 14:25:10 +08:00
|
|
|
|
while (elapsedTime < fadeDuration)
|
|
|
|
|
{
|
|
|
|
|
elapsedTime += Time.deltaTime;
|
2024-11-23 15:28:39 +08:00
|
|
|
|
// <20><><EFBFBD>㵱ǰ<C7B0><CDB8><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD>0<EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><CDB8><EFBFBD><EFBFBD>0.6<EFBFBD><EFBFBD>
|
|
|
|
|
float alpha = Mathf.Lerp(0f, targetAlpha, elapsedTime / fadeDuration);
|
2024-11-23 14:25:10 +08:00
|
|
|
|
blackImage.color = new Color(0, 0, 0, alpha);
|
|
|
|
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 15:28:39 +08:00
|
|
|
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>մﵽĿ<EFB5BD><C4BF><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|
|
|
|
blackImage.color = new Color(0, 0, 0, targetAlpha);
|
2024-11-23 14:25:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|