108 lines
2.4 KiB
C#
108 lines
2.4 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_MaskPanel : BasePanel
|
|
{
|
|
/// <summary>
|
|
/// 淡入淡出速度0.5/s
|
|
/// </summary>
|
|
public float fadeInSpeed = 0.5f; // 淡入速度
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
public void Init()
|
|
{
|
|
FadeInAndOut(E_FadeInAndOut.FadeIn);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 淡入/出
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
public void FadeInAndOut(E_FadeInAndOut type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case E_FadeInAndOut.FadeIn:
|
|
StartCoroutine(FadeInAsync());
|
|
break;
|
|
case E_FadeInAndOut.FadeOut:
|
|
StartCoroutine(FadeOutAsync());
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏蒙版
|
|
/// </summary>
|
|
private void HideMask()
|
|
{
|
|
FadeInAndOut(E_FadeInAndOut.FadeOut);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 淡入
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IEnumerator FadeInAsync()
|
|
{
|
|
// 淡入
|
|
float alpha = 0.0f;
|
|
while (alpha < 1.0f)
|
|
{
|
|
alpha += fadeInSpeed * Time.deltaTime;
|
|
alpha = Mathf.Clamp(alpha,0,1);
|
|
GetControl<Image>("Mask").color = new Color(0, 0, 0, alpha);
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 淡出
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IEnumerator FadeOutAsync()
|
|
{
|
|
// 淡入
|
|
float alpha = 1.0f;
|
|
while (alpha > 0.0f)
|
|
{
|
|
alpha -= fadeInSpeed * Time.deltaTime;
|
|
alpha = Mathf .Clamp(alpha,0,1);
|
|
GetControl<Image>("Mask").color = new Color(0, 0, 0, alpha);
|
|
yield return null;
|
|
}
|
|
UIManager.Instance.HidePanel<UI_MaskPanel>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示
|
|
/// </summary>
|
|
public override void ShowMe()
|
|
{
|
|
#if UNITY_EDITOR
|
|
EventCenter.Instance.AddEventListener(Enum_EventType.HideMask, HideMask);
|
|
#else
|
|
GameManager.EventMgr.AddEventListener(Enum_EventType.HideMask, HideMask);
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏面板
|
|
/// </summary>
|
|
public override void HideMe()
|
|
{
|
|
#if UNITY_EDITOR
|
|
EventCenter.Instance.RemoveEventListener(Enum_EventType.HideMask, HideMask);
|
|
#else
|
|
GameManager.EventMgr.RemoveEventListener(Enum_EventType.HideMask, HideMask);
|
|
#endif
|
|
|
|
}
|
|
}
|