171 lines
5.2 KiB
C#
171 lines
5.2 KiB
C#
using System.Collections;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using DG.Tweening;
|
|
using RainbowArt.CleanFlatUI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
/// <summary>
|
|
/// 主要用来放置淡入淡出,图片展示等演出工具
|
|
/// </summary>
|
|
public class PlayToolPanel : MonoBehaviour, IUIPanel
|
|
{
|
|
public bool IsOpen => gameObject.activeSelf;
|
|
|
|
[Header("Obj尺寸参数")] public float objWidth;
|
|
public float objHeight;
|
|
|
|
#region 索引
|
|
|
|
private Image _fadeImage;
|
|
private GameObject _showObjPanel;
|
|
private Image _showObjImage;
|
|
private Image _fullScreenImage;
|
|
private Image _redFlash;
|
|
private ModalWindowProgressBar _window;
|
|
|
|
#endregion
|
|
|
|
private void Awake()
|
|
{
|
|
InitRefs();
|
|
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, HideAll);
|
|
}
|
|
|
|
private void InitRefs()
|
|
{
|
|
_fadeImage = transform.Find("Fade Image").GetComponent<Image>();
|
|
_showObjPanel = transform.Find("Show Obj").gameObject;
|
|
_showObjImage = _showObjPanel.transform.Find("Obj").GetComponent<Image>();
|
|
_fullScreenImage = transform.Find("Full Screen Image").GetComponent<Image>();
|
|
_window = transform.Find("进度条窗口").GetComponent<ModalWindowProgressBar>();
|
|
_redFlash = transform.Find("Red Flash").GetComponent<Image>();
|
|
}
|
|
|
|
public IEnumerator FadeInAsync(float duration = 1)
|
|
{
|
|
return _fadeImage.FadeInAsync(duration);
|
|
}
|
|
|
|
public IEnumerator FadeOutAsync(float duration = 1)
|
|
{
|
|
return _fadeImage.FadeOutAsync(duration);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示物体
|
|
/// </summary>
|
|
/// <returns>协程</returns>
|
|
public IEnumerator ShowObj(string picName)
|
|
{
|
|
_showObjPanel.gameObject.SetActive(true);
|
|
|
|
// 切换图片
|
|
var newSprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
|
// 获取图片的长宽比
|
|
var imageAspect = (float)newSprite.texture.width / newSprite.texture.height;
|
|
|
|
// 计算新的尺寸
|
|
if (imageAspect > 1) // 宽图
|
|
{
|
|
var newHeight = objWidth / imageAspect;
|
|
_showObjImage.rectTransform.sizeDelta = new Vector2(objWidth, newHeight);
|
|
}
|
|
else // 高图
|
|
{
|
|
var newWidth = objHeight * imageAspect;
|
|
_showObjImage.rectTransform.sizeDelta = new Vector2(newWidth, objHeight);
|
|
}
|
|
|
|
// 淡入
|
|
_showObjImage.sprite = newSprite;
|
|
yield return _showObjImage.FadeInAsync(1);
|
|
}
|
|
|
|
public IEnumerator HideObj()
|
|
{
|
|
yield return _showObjImage.FadeOutAsync(1);
|
|
_showObjPanel.SetActive(false);
|
|
}
|
|
|
|
public IEnumerator ShowFullScreen(string picName)
|
|
{
|
|
_fullScreenImage.sprite = Resources.Load<Sprite>($"Art/Obj/{picName}");
|
|
|
|
// 淡入
|
|
yield return _fullScreenImage.FadeInAsync(1);
|
|
}
|
|
|
|
public IEnumerator HideFullScreen()
|
|
{
|
|
return _fullScreenImage.FadeOutAsync(1);
|
|
}
|
|
|
|
public IEnumerator OpenProgressWindow(string title, string description, float duration)
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/Scriptal/Ui");
|
|
_window.TitleValue = title;
|
|
_window.DescriptionValue = description;
|
|
float currentProgress = 0;
|
|
|
|
DOTween.To(
|
|
() => currentProgress,
|
|
value =>
|
|
{
|
|
currentProgress = value;
|
|
_window.SetProgress(currentProgress); // 更新进度
|
|
},
|
|
100,
|
|
duration
|
|
);
|
|
|
|
_window.ShowModalWindow();
|
|
|
|
// 获取 moveText 的 RectTransform
|
|
RectTransform moveTextRect =
|
|
_window.transform.Find("View/mask/moveText")?.GetComponent<RectTransform>();
|
|
if (moveTextRect != null)
|
|
{
|
|
moveTextRect.DOAnchorPosY(330f, duration).SetEase(Ease.Linear);
|
|
}
|
|
|
|
// 等待用户确认
|
|
yield return new WaitUntil(() => currentProgress >= 100);
|
|
_window.HideModalWindow();
|
|
moveTextRect.DOAnchorPosY(-611f, 0.1f).SetEase(Ease.Linear);
|
|
}
|
|
|
|
// 红色闪烁效果
|
|
public IEnumerator FlashRed(float duration)
|
|
{
|
|
_redFlash.gameObject.SetActive(true);
|
|
yield return _redFlash.FadeInAsync(duration / 2);
|
|
yield return _redFlash.FadeOutAsync(duration / 2);
|
|
_redFlash.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void HideAll()
|
|
{
|
|
_fullScreenImage.FadeOut(0.1f);
|
|
_showObjImage.FadeOut(0.1f);
|
|
_showObjPanel.SetActive(false);
|
|
}
|
|
|
|
#region 感觉这个面板应该常驻
|
|
|
|
public void Show()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |