85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
#nullable enable
|
|
using UnityEngine;
|
|
using UVC.Locale;
|
|
|
|
namespace UVC.UI.Commands
|
|
{
|
|
|
|
// 언어 변경 커맨드
|
|
public class ChangeLanguageCommand : ICommand, IUndoable
|
|
{
|
|
private readonly string _languageCode;
|
|
private string _currentLanguageBeforeChange = string.Empty;
|
|
|
|
public ChangeLanguageCommand(string languageCode)
|
|
{
|
|
_languageCode = languageCode;
|
|
}
|
|
|
|
public void Execute(object? parameter = null)
|
|
{
|
|
string targetLanguage = _languageCode;
|
|
|
|
// Start 호출 시 전달된 파라미터가 있다면 그것을 우선 사용
|
|
if (parameter is string langCodeFromParam && !string.IsNullOrEmpty(langCodeFromParam))
|
|
{
|
|
targetLanguage = langCodeFromParam;
|
|
Debug.Log($"ChangeLanguageCommand: 파라미터로 언어 코드 '{targetLanguage}' 사용.");
|
|
}
|
|
else if (!string.IsNullOrEmpty(_languageCode))
|
|
{
|
|
Debug.Log($"ChangeLanguageCommand: 생성자에서 설정된 언어 코드 '{targetLanguage}' 사용.");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("ChangeLanguageCommand: 변경할 언어 코드가 지정되지 않았습니다.");
|
|
return;
|
|
}
|
|
|
|
if (LocalizationManager.Instance != null)
|
|
{
|
|
_currentLanguageBeforeChange = LocalizationManager.Instance.CurrentLanguage;
|
|
LocalizationManager.Instance.SetCurrentLanguage(targetLanguage);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("LocalizationManager 인스턴스를 찾을 수 없습니다.");
|
|
}
|
|
}
|
|
|
|
public void Undo(object? parameter = null)
|
|
{
|
|
string targetLanguage = _currentLanguageBeforeChange;
|
|
|
|
// Start 호출 시 전달된 파라미터가 있다면 그것을 우선 사용
|
|
if (parameter is string langCodeFromParam && !string.IsNullOrEmpty(langCodeFromParam))
|
|
{
|
|
targetLanguage = langCodeFromParam;
|
|
Debug.Log($"ChangeLanguageCommand: 파라미터로 언어 코드 '{targetLanguage}' 사용.");
|
|
}
|
|
else if (!string.IsNullOrEmpty(_currentLanguageBeforeChange))
|
|
{
|
|
Debug.Log($"ChangeLanguageCommand: 이전에 설정된 언어 코드 '{targetLanguage}' 사용.");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("ChangeLanguageCommand: 변경할 언어 코드가 지정되지 않았습니다.");
|
|
return;
|
|
}
|
|
|
|
if (LocalizationManager.Instance != null)
|
|
{
|
|
_currentLanguageBeforeChange = LocalizationManager.Instance.CurrentLanguage;
|
|
LocalizationManager.Instance.SetCurrentLanguage(targetLanguage);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("LocalizationManager 인스턴스를 찾을 수 없습니다.");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|