using Cysharp.Threading.Tasks; using UVC.Locale; // ButtonText의 기본값을 위해 추가 using UVC.Log; // ULog 사용 예시를 위해 추가 (필요에 따라) namespace UVC.UI.Modal { /// /// 🤔 사용자에게 "정말 ~하시겠어요?" 하고 물어보고, "예" 또는 "아니오" 선택을 받는 친구예요. /// 중요한 결정이나 되돌릴 수 없는 행동 전에 한 번 더 확인받을 때 사용하면 좋아요. /// 사용자가 어떤 버튼을 눌렀는지 (확인 또는 취소) 알려줘요. /// /// /// /// // 게임 종료 전에 정말 끌 건지 물어보는 예시 /// public async void TryExitGame() /// { /// bool wantsToExit = await Confirm.Show("게임 종료", "정말로 게임을 종료하시겠습니까?", "네, 종료합니다", "아니요, 계속할래요"); /// if (wantsToExit) /// { /// ULog.Debug("사용자가 게임 종료를 확인했습니다."); /// // Application.Quit(); // 실제 게임 종료 코드 /// } /// else /// { /// ULog.Debug("사용자가 게임 종료를 취소했습니다."); /// } /// } /// /// // 아이템 삭제 확인 /// public async void TryDeleteItem(string itemName) /// { /// string title = "아이템 삭제"; /// string message = $"정말로 '{itemName}' 아이템을 삭제하시겠습니까? 이 행동은 되돌릴 수 없습니다."; /// /// // 기본 버튼 텍스트 사용 (ModalContent에서 설정된 "확인", "취소") /// bool confirmed = await Confirm.Show(title, message); /// /// if (confirmed) /// { /// ULog.Debug($"'{itemName}' 아이템 삭제를 진행합니다."); /// // (아이템 삭제 로직...) /// } /// } /// /// public static class Confirm { /// /// 🎨 확인창의 기본 디자인(프리팹) 파일이 어디 있는지 알려주는 경로예요. /// private const string DefaultPrefabPath = "Prefabs/UI/Modal/Confirm"; // 실제 프로젝트 경로에 맞게 수정하세요. /// /// ✨ 지정된 제목과 메시지로 확인창을 화면에 뿅! 하고 보여줘요. /// 사용자가 "확인" 또는 "취소" 버튼을 누를 때까지 코드는 여기서 잠시 멈춰 기다려요. /// /// 확인창 맨 위에 크게 보일 '제목'이에요. 다국어 키도 가능해요. /// 확인창에 보여줄 '질문 또는 메시지 내용'이에요. 다국어 키도 가능해요. /// "확인" 버튼에 보여줄 글자예요. 안 적으면 기본 글자("확인")가 나와요. 다국어 키도 가능해요. /// "취소" 버튼에 보여줄 글자예요. 안 적으면 기본 글자("취소")가 나와요. 다국어 키도 가능해요. /// 특별히 만들어둔 확인창 디자인 파일 경로예요. 없으면 기본 디자인을 사용해요. 다국어 키도 가능해요. /// 사용자가 "확인"을 누르면 true, "취소"를 누르면 false를 돌려주는 작업(UniTask)이에요. /// /// /// public class ShopManager : MonoBehaviour /// { /// public async void OnPurchaseItem(string itemName, int price) /// { /// string purchaseTitle = "구매 확인"; /// string purchaseMessage = $"{itemName} 아이템을 {price} 골드에 구매하시겠습니까?"; /// /// bool confirmed = await Confirm.Show(purchaseTitle, purchaseMessage, "구매", "나중에"); /// /// if (confirmed) /// { /// ULog.Debug($"{itemName} 구매를 진행합니다."); /// // (구매 처리 로직...) /// } /// else /// { /// ULog.Debug($"{itemName} 구매를 취소했습니다."); /// } /// /// // 예시: 설정 초기화 전에 다국어로 확인을 받습니다. /// // titleLocalizationKey: "settings_reset_title" -> "설정 초기화" (한국어), "Reset Settings" (영어) /// // messageLocalizationKey: "settings_reset_confirm_message" -> "모든 설정을 초기화하시겠습니까?" (한국어), "Are you sure you want to reset all settings?" (영어) /// /// bool confirmed = await Confirm.ShowLocalized( /// "settings_reset_title", /// "settings_reset_confirm_message", /// confirmButtonLocalizationKey: "ui_button_reset", // "초기화" /// cancelButtonLocalizationKey: "ui_button_keep_current" // "유지" /// ); /// /// if (confirmed) /// { /// ULog.Debug("설정을 초기화합니다."); /// // (설정 초기화 로직...) /// } /// else /// { /// ULog.Debug("설정 초기화를 취소했습니다."); /// } /// /// } /// } /// /// public static async UniTask Show( string title, string message, string confirmButtonText = null, string cancelButtonText = null, string customPrefabPath = null) { string prefabPath = string.IsNullOrEmpty(customPrefabPath) ? DefaultPrefabPath : customPrefabPath; // ModalContent 레시피를 만들어요. 확인창은 확인/취소 버튼이 모두 필요해요. ModalContent content = new ModalContent(prefabPath) { Title = LocalizationManager.Instance.GetString(title), Message = LocalizationManager.Instance.GetString(message), ShowConfirmButton = true, // Confirm에서는 확인 버튼 항상 표시 ShowCancelButton = true // Confirm에서는 취소 버튼 항상 표시 }; // 확인 버튼 글자를 따로 정해줬다면 그걸로 설정해요. if (!string.IsNullOrEmpty(confirmButtonText)) { content.ConfirmButtonText = LocalizationManager.Instance.GetString(confirmButtonText); } // 취소 버튼 글자를 따로 정해줬다면 그걸로 설정해요. if (!string.IsNullOrEmpty(cancelButtonText)) { content.CancelButtonText = LocalizationManager.Instance.GetString(cancelButtonText); } // Modal 시스템에게 "이 레시피대로 모달 창 열어줘!" 라고 부탁하고, 사용자의 선택(true/false)을 기다려요. return await Modal.Open(content); } } }