게임엔진/Unity
[Unity] UI - Localization (언어 번역) 레거시
ShovelingLife
2024. 11. 11. 13:06
인덱서를 사용해서 테이블에서 해당되는 언어로 string을 가져옴
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Csv_loader_manager : Singleton_local<Csv_loader_manager>
{
// ------- Variables -------
List<Dictionary<string, object>> m_csv_list = new List<Dictionary<string, object>>();
string m_current_language = "english";
// Accessing to m_csv_list by value
public object this[int _hash]
{
get => m_csv_list[_hash][m_current_language.ToUpper()];
}
// Set current language
public void Set_language(string _language) => m_current_language = _language;
}
각 버튼들은 english, spanish, korean 으로 되어있음
텍스트
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Text_property : MonoBehaviour
{
Text m_current_txt;
public int hash_code;
void Start()
{
m_current_txt = GetComponent<Text>();
}
void Update()
{
m_current_txt.text = Csv_loader_manager.instance[hash_code].ToString();
}
}
결과