using UnityEngine; using RainbowArt.CleanFlatUI; using Yarn.Unity; using System.Collections; using DG.Tweening; 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) { 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("OpenProgressWindow")] public IEnumerator OpenProgressWindow(string title, string description,float duration) { 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("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(); } }