85 lines
4.6 KiB
C#
85 lines
4.6 KiB
C#
|
|
using Cysharp.Threading.Tasks;
|
|||
|
|
using UVC.Locale; // ConfirmButtonText의 기본값을 위해 추가
|
|||
|
|
|
|||
|
|
namespace UVC.UI.Modal
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 간단한 알림 메시지를 표시하는 정적 클래스입니다.
|
|||
|
|
/// 확인 버튼만 있으며, 사용자의 확인을 기다립니다.
|
|||
|
|
/// </summary>
|
|||
|
|
public static class Alert
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Alert 모달 프리팹의 기본 경로입니다.
|
|||
|
|
/// </summary>
|
|||
|
|
private const string DefaultAlertPrefabPath = "Prefabs/UI/Modal/Alert";
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 지정된 제목과 메시지로 알림창을 표시합니다.
|
|||
|
|
/// 사용자가 확인 버튼을 누를 때까지 기다립니다.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="title">알림창의 제목입니다.</param>
|
|||
|
|
/// <param name="message">알림창에 표시될 메시지입니다.</param>
|
|||
|
|
/// <param name="confirmButtonText">확인 버튼에 표시될 텍스트입니다. null일 경우 LocalizationManager에서 "modal_confirm_button" 키로 조회합니다.</param>
|
|||
|
|
/// <param name="customPrefabPath">사용자 정의 알림 프리팹 경로입니다. null일 경우 기본 경로를 사용합니다.</param>
|
|||
|
|
/// <returns>모달이 닫힐 때 완료되는 UniTask입니다.</returns>
|
|||
|
|
public static async UniTask Show(
|
|||
|
|
string title,
|
|||
|
|
string message,
|
|||
|
|
string confirmButtonText = null,
|
|||
|
|
string customPrefabPath = null)
|
|||
|
|
{
|
|||
|
|
string prefabPath = string.IsNullOrEmpty(customPrefabPath) ? DefaultAlertPrefabPath : customPrefabPath;
|
|||
|
|
|
|||
|
|
// ModalContent 설정
|
|||
|
|
ModalContent content = new ModalContent(prefabPath)
|
|||
|
|
{
|
|||
|
|
Title = title,
|
|||
|
|
Message = message,
|
|||
|
|
ShowCancelButton = false, // Alert에서는 취소 버튼 숨김
|
|||
|
|
// ConfirmButtonText는 null이면 ModalContent의 getter가 LocalizationManager를 사용함
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(confirmButtonText))
|
|||
|
|
{
|
|||
|
|
content.ConfirmButtonText = confirmButtonText;
|
|||
|
|
}
|
|||
|
|
// else인 경우, ModalContent의 ConfirmButtonText getter가
|
|||
|
|
// LocalizationManager.Instance.GetString("modal_confirm_button")을 사용합니다.
|
|||
|
|
// 만약 이 키가 아닌 다른 키를 기본값으로 사용하고 싶다면 여기서 설정할 수 있습니다.
|
|||
|
|
// 예: content.ConfirmButtonText = LocalizationManager.Instance.GetString("alert_ok_button");
|
|||
|
|
|
|||
|
|
// Modal.Open<T> 호출. Alert은 별도의 결과를 반환하지 않으므로 T는 bool 또는 object 같은 기본 타입을 사용할 수 있습니다.
|
|||
|
|
// 여기서는 bool을 사용하고, 확인 버튼은 true를 반환하도록 Modal 시스템이 되어있다고 가정합니다.
|
|||
|
|
// 실제 반환값은 사용하지 않으므로, UniTask<bool>을 받고 무시합니다.
|
|||
|
|
await Modal.Open<bool>(content);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 다국어 키를 사용하여 제목과 메시지를 표시하는 알림창을 엽니다.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="titleLocalizationKey">제목으로 사용할 다국어 키입니다.</param>
|
|||
|
|
/// <param name="messageLocalizationKey">메시지로 사용할 다국어 키입니다.</param>
|
|||
|
|
/// <param name="confirmButtonLocalizationKey">확인 버튼 텍스트로 사용할 다국어 키입니다. null일 경우 "modal_confirm_button"을 사용합니다.</param>
|
|||
|
|
/// <param name="customPrefabPath">사용자 정의 알림 프리팹 경로입니다. null일 경우 기본 경로를 사용합니다.</param>
|
|||
|
|
/// <returns>모달이 닫힐 때 완료되는 UniTask입니다.</returns>
|
|||
|
|
public static async UniTask ShowLocalized(
|
|||
|
|
string titleLocalizationKey,
|
|||
|
|
string messageLocalizationKey,
|
|||
|
|
string confirmButtonLocalizationKey = null,
|
|||
|
|
string customPrefabPath = null)
|
|||
|
|
{
|
|||
|
|
string title = LocalizationManager.Instance.GetString(titleLocalizationKey);
|
|||
|
|
string message = LocalizationManager.Instance.GetString(messageLocalizationKey);
|
|||
|
|
string confirmText = null;
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(confirmButtonLocalizationKey))
|
|||
|
|
{
|
|||
|
|
confirmText = LocalizationManager.Instance.GetString(confirmButtonLocalizationKey);
|
|||
|
|
}
|
|||
|
|
// confirmText가 null이면 Show 메서드 내부에서 ModalContent의 기본 로직(modal_confirm_button 키 사용)이 적용됩니다.
|
|||
|
|
|
|||
|
|
await Show(title, message, confirmText, customPrefabPath);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|