_xiaofang/xiaofang/Assets/Script/UI/ZZZZZZ/FreePanelManager.cs
2024-12-17 16:28:38 +08:00

109 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class FreePanelManager : MonoBehaviour
{
[Header("测试")]
public Sprite TestImage;
[Header("面板")]
//特殊情况弹窗
public GameObject TipPanel;
public GameObject AccidentIPanel;
[Header("图像")]
//特殊情况弹窗背景图
public Image TipBg;
//事故点截图
public Image AccidentImage;
[Header("文本")]
//特殊情况弹窗文本
public Text TipText;
[Header("一些奇奇怪怪的东西")]
#region
public float fadeInDuration = 1f; // 淡出时间
public float fadeOutDuration = 1f; // 淡出持续时间
public float displayDuration = 2f; // 2秒后自己淡出
private bool isFadingIn = true;
private bool isFadingOut = false;
// 指示文本当前是否正在淡入或淡出
private bool isFading = false;
private bool isFadeEnd = false;
// 运行中的淡入淡出协程引用
private Coroutine fadeCoroutine;
#endregion
public void Update()
{
#region
if (Input.GetKeyDown("j"))
{
// PopAccident(TestImage);
}
#endregion
if (isFadeEnd)
{
StopCoroutine(FadeInOutRoutine());
isFadeEnd = false;
}
}
/// <summary>
/// 打开特殊情况弹窗
/// </summary>
public void PopTipPanel()
{
TipPanel.SetActive(true);
StopCoroutine(FadeInOutRoutine());
}
/// <summary>
/// 弹出事故框框并且修改图片
/// </summary>
/// <param name="image">传入一张事故图片Spite</param>
public void PopAccident(Sprite image)
{
AccidentImage.sprite=image;
AccidentIPanel.SetActive(true);
}
/// <summary>
/// 提示面板淡入淡出的携程
/// </summary>
/// <returns></returns>
IEnumerator FadeInOutRoutine()
{
isFading = true; // 设置正在淡入淡出标志
//// 淡入
float elapsedTime = 0f;
while (elapsedTime < fadeInDuration)
{
elapsedTime += Time.deltaTime;
//Color textColor = TipText.color;
//textColor.a = elapsedTime / fadeInDuration; // 根据时间计算alpha值
//TipText.color = textColor;
//TipBg.color = textColor;
yield return null; // 等待下一帧
}
// 显示文本一段时间
yield return new WaitForSeconds(displayDuration);
// 淡出
elapsedTime = 0f;
while (elapsedTime < fadeOutDuration)
{
elapsedTime += Time.deltaTime;
Color textColor = TipText.color;
textColor.a = 1f - (elapsedTime / fadeOutDuration); // 根据时间计算alpha值
TipText.color = textColor;
TipBg.color = textColor;
yield return null; // 等待下一帧
}
isFading = false; // 重置正在淡入淡出标志
isFadeEnd = true;//这个携程结束的标志
TipPanel.SetActive(false);
}
}