Files
aibis-dream/Assets/Scripts/SystemWindow/WindowManager.cs
T
2025-03-07 22:28:12 +08:00

114 lines
4.0 KiB
C#

using UnityEngine;
using RainbowArt.CleanFlatUI;
using Yarn.Unity;
using System.Collections;
using DG.Tweening;
using AibisDream;
using AibisDream.Kit;
public class WindowManager : MonoBehaviour
{
public static WindowManager Instance { get; private set; }
[Header("Window Prefabs")] public ModalWindow singleButtonWindowPrefab;
public ModalWindow ImageSingleButtonWindowPrefab;
public ModalWindowProgressBar progressWindowPrefab;
private GameObject currentWindow;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject); // 如果需要全局保留
}
[YarnCommand("OpenSingleButtonWindow")]
public IEnumerator OpenSingleButtonWindow(string title, string description, bool ispanelActive = true)
{
FmodManager.Instance.PlaySfx("event:/Scriptal/Ui");
bool isConfirmed = false;
singleButtonWindowPrefab.transform.GetChild(0).gameObject.SetActive(ispanelActive);
singleButtonWindowPrefab.TitleValue = title;
singleButtonWindowPrefab.DescriptionValue = description;
singleButtonWindowPrefab.OnConfirm.AddListener(() => isConfirmed = true);
singleButtonWindowPrefab.ShowModalWindow();
// 等待用户确认
yield return new WaitUntil(() => isConfirmed);
singleButtonWindowPrefab.OnConfirm.RemoveAllListeners();
}
[YarnCommand("OpenMutiSingleButtonWindow")]
public IEnumerator OpenMutiSingleButtonWindow(string title, string description, int number)
{
FmodManager.Instance.PlaySfx("event:/Scriptal/Ui");
bool isConfirmed = false;
singleButtonWindowPrefab.transform.GetChild(0).gameObject.SetActive(false);
singleButtonWindowPrefab.TitleValue = title;
singleButtonWindowPrefab.DescriptionValue = description;
singleButtonWindowPrefab.OnConfirm.AddListener(() => isConfirmed = true);
singleButtonWindowPrefab.ShowModalWindow();
// 等待用户确认
yield return new WaitUntil(() => isConfirmed);
singleButtonWindowPrefab.OnConfirm.RemoveAllListeners();
}
[YarnCommand("OpenProgressWindow")]
public IEnumerator OpenProgressWindow(string title, string description, float duration)
{
FmodManager.Instance.PlaySfx("event:/Scriptal/Ui");
progressWindowPrefab.TitleValue = title;
progressWindowPrefab.DescriptionValue = description;
float currentProgress = 0;
DOTween.To(
() => currentProgress,
value =>
{
currentProgress = value;
progressWindowPrefab.SetProgress(currentProgress); // 更新进度
},
100,
duration
);
progressWindowPrefab.ShowModalWindow();
// 等待用户确认
yield return new WaitUntil(() => currentProgress >= 100);
progressWindowPrefab.HideModalWindow();
}
[YarnCommand("OpenImageWindow_UFImage")]
public void OpenImageSingleButtonWindowPrefab(string title, string imageName)
{
//bool isConfirmed = false;
ImageSingleButtonWindowPrefab.IsConfirmButtonActive = false;
ImageSingleButtonWindowPrefab.TitleValue = title;
ImageSingleButtonWindowPrefab.ImageValue = Resources.Load<Sprite>("Art/Photos/" + imageName);
ImageSingleButtonWindowPrefab.DescriptionValue = "";
//progressWindowPrefab.OnFinish.AddListener(() => isConfirmed = true);
ImageSingleButtonWindowPrefab.ShowModalWindow();
}
[YarnCommand("EnableAndWaitForClosingUFImage")]
public IEnumerator EnableAndWaitForClosingUFImage()
{
bool isConfirmed = false;
ImageSingleButtonWindowPrefab.IsConfirmButtonActive = true;
ImageSingleButtonWindowPrefab.OnConfirm.AddListener(() => isConfirmed = true);
yield return new WaitUntil(() => isConfirmed);
ImageSingleButtonWindowPrefab.OnConfirm.RemoveAllListeners();
}
}