using UnityEngine;
using System.IO;
using System.Collections.Generic;
public class CreateCSV : MonoBehaviour
{
public TextAsset[] assets;
Dictionary<string, string> ReadDictionary (TextAsset asset)
{
ByteReader reader
= new ByteReader
(asset
); return reader.ReadDictionary();
}
void Assign (Dictionary<string, string[]> full, string key, string value, int index, int max)
{
if (!full
.ContainsKey(key
)) full
[key
] = new string[max
]; full[key][index] = value;
}
[ContextMenu("Execute")]
public void Execute ()
{
Dictionary
<string,
string[]> full
= new Dictionary
<string,
string[]>();
for (int b = 0; b < assets.Length; ++b)
{
Dictionary<string, string> dict0 = ReadDictionary(assets[b]);
foreach (KeyValuePair<string, string> key in dict0)
Assign(full, key.Key, key.Value, b, 2);
}
StringWriter writer
= new StringWriter
();
writer.Write("KEY");
for (int i = 0; i < assets.Length; ++i)
writer.Write("," + assets[i].name);
writer.Write("\n");
foreach (KeyValuePair<string, string[]> pair in full)
{
writer.Write("\"" + pair.Key + "\"");
for (int i = 0; i < assets.Length; ++i)
{
string val = pair.Value[i];
if (string.IsNullOrEmpty(val)) val = pair.Key;
writer.Write(",\"" + val.Replace("\n", "\\n") + "\"");
}
writer.Write("\n");
}
StreamWriter file
= new StreamWriter
("Assets/Resources/Localization.txt",
false,
System.Text.Encoding.UTF8); file.Write(writer.ToString());
file.Flush();
file.Close();
}
}