Files
aibis-dream/Assets/Scripts/SystemWindow/WindowManager.cs
T
2024-12-05 22:57:31 +08:00

85 lines
2.7 KiB
C#

using UnityEngine;
using RainbowArt.CleanFlatUI;
using Yarn.Unity;
using System.Collections;
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 isConfirmed = false;
singleButtonWindowPrefab.TitleValue = title;
singleButtonWindowPrefab.DescriptionValue = description;
singleButtonWindowPrefab.OnConfirm.AddListener(() => isConfirmed = true);
singleButtonWindowPrefab.gameObject.SetActive(true);
// 等待用户确认
yield return new WaitUntil(() => isConfirmed);
singleButtonWindowPrefab.OnConfirm.RemoveAllListeners();
}
[YarnCommand("OpenProgressWindow")]
public IEnumerator OpenProgressWindow(string title, string description)
{
bool isConfirmed = false;
progressWindowPrefab.TitleValue = title;
progressWindowPrefab.DescriptionValue = description;
progressWindowPrefab.OnFinish.AddListener(() => isConfirmed = true);
progressWindowPrefab.gameObject.SetActive(true);
// 等待用户确认
yield return new WaitUntil(() => isConfirmed);
progressWindowPrefab.OnFinish.RemoveAllListeners();
}
[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);
progressWindowPrefab.gameObject.SetActive(true);
}
[YarnCommand("EnableAndWaitForClosingUFImage")]
public IEnumerator EnableAndWaitForClosingUFImage()
{
bool isConfirmed = false;
ImageSingleButtonWindowPrefab.IsConfirmButtonActive=true;
yield return new WaitUntil(() => isConfirmed);
progressWindowPrefab.OnFinish.RemoveAllListeners();
}
}