109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using TMPro;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class FreePanelManager : MonoBehaviour
|
|||
|
{
|
|||
|
[Header("<22><><EFBFBD><EFBFBD>")]
|
|||
|
public Sprite TestImage;
|
|||
|
[Header("<22><><EFBFBD><EFBFBD>")]
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public GameObject TipPanel;
|
|||
|
public GameObject AccidentIPanel;
|
|||
|
[Header("ͼ<><CDBC>")]
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ
|
|||
|
public Image TipBg;
|
|||
|
//<2F>¹ʵ<C2B9><CAB5><EFBFBD>ͼ
|
|||
|
public Image AccidentImage;
|
|||
|
[Header("<22>ı<EFBFBD>")]
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|||
|
public Text TipText;
|
|||
|
[Header("һЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD>ֵֹĶ<D6B5><C4B6><EFBFBD>")]
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵭<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>
|
|||
|
public float fadeInDuration = 1f; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
public float fadeOutDuration = 1f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
public float displayDuration = 2f; // 2<><32><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
private bool isFadingIn = true;
|
|||
|
private bool isFadingOut = false;
|
|||
|
// ָʾ<D6B8>ı<EFBFBD><C4B1><EFBFBD>ǰ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private bool isFading = false;
|
|||
|
private bool isFadeEnd = false;
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5><C4B5>뵭<EFBFBD><EBB5AD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private Coroutine fadeCoroutine;
|
|||
|
#endregion
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (Input.GetKeyDown("j"))
|
|||
|
{
|
|||
|
// PopAccident(TestImage);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
if (isFadeEnd)
|
|||
|
{
|
|||
|
StopCoroutine(FadeInOutRoutine());
|
|||
|
isFadeEnd = false;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public void PopTipPanel()
|
|||
|
{
|
|||
|
TipPanel.SetActive(true);
|
|||
|
StopCoroutine(FadeInOutRoutine());
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>¹ʿ<C2B9><CABF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ
|
|||
|
/// </summary>
|
|||
|
/// <param name="image"><3E><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>¹<EFBFBD>ͼƬ<CDBC><C6AC>Spite<74><65></param>
|
|||
|
public void PopAccident(Sprite image)
|
|||
|
{
|
|||
|
AccidentImage.sprite=image;
|
|||
|
AccidentIPanel.SetActive(true);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><>ʾ<EFBFBD><CABE><EFBFBD>嵭<EFBFBD>뵭<EFBFBD><EBB5AD><EFBFBD><EFBFBD>Я<EFBFBD><D0AF>
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
IEnumerator FadeInOutRoutine()
|
|||
|
{
|
|||
|
isFading = true; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>뵭<EFBFBD><EBB5AD><EFBFBD><EFBFBD>־
|
|||
|
|
|||
|
//// <20><><EFBFBD><EFBFBD>
|
|||
|
float elapsedTime = 0f;
|
|||
|
while (elapsedTime < fadeInDuration)
|
|||
|
{
|
|||
|
elapsedTime += Time.deltaTime;
|
|||
|
//Color textColor = TipText.color;
|
|||
|
//textColor.a = elapsedTime / fadeInDuration; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>alphaֵ
|
|||
|
//TipText.color = textColor;
|
|||
|
//TipBg.color = textColor;
|
|||
|
|
|||
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ʾ<EFBFBD>ı<EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>
|
|||
|
yield return new WaitForSeconds(displayDuration);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>
|
|||
|
elapsedTime = 0f;
|
|||
|
while (elapsedTime < fadeOutDuration)
|
|||
|
{
|
|||
|
elapsedTime += Time.deltaTime;
|
|||
|
Color textColor = TipText.color;
|
|||
|
textColor.a = 1f - (elapsedTime / fadeOutDuration); // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>alphaֵ
|
|||
|
TipText.color = textColor;
|
|||
|
TipBg.color = textColor;
|
|||
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|||
|
}
|
|||
|
|
|||
|
isFading = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5>뵭<EFBFBD><EBB5AD><EFBFBD><EFBFBD>־
|
|||
|
isFadeEnd = true;//<2F><><EFBFBD><EFBFBD>Я<EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD>ı<EFBFBD>־
|
|||
|
TipPanel.SetActive(false);
|
|||
|
}
|
|||
|
}
|