49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
public class Translator : MonoBehaviour
|
|
{
|
|
string filePath = "translationtable";
|
|
static Dictionary<string, string> translateTable = new Dictionary<string, string>();
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
LoadTable();
|
|
}
|
|
|
|
void LoadTable()
|
|
{
|
|
var ta = Resources.Load<TextAsset>($"{filePath}");
|
|
string csvText = Encoding.UTF8.GetString(ta.bytes);
|
|
Debug.Log(csvText);
|
|
var lines = csvText.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
for (int i = 1; i < lines.Length; i++)
|
|
{
|
|
var cols = lines[i].Split(',');
|
|
if (cols.Length < 2) continue;
|
|
|
|
var key = cols[0].Trim();
|
|
var value = cols[1].Trim();
|
|
|
|
if (!translateTable.ContainsKey(key))
|
|
translateTable.Add(key, value);
|
|
else
|
|
translateTable[key] = value;
|
|
}
|
|
}
|
|
|
|
public static string Translate(string key)
|
|
{
|
|
if (translateTable.ContainsKey(key))
|
|
{
|
|
return translateTable[key];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|