You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.6 KiB
107 lines
2.6 KiB
10 years ago
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.IO;
|
||
|
using Rotorz.ReorderableList;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
|
||
10 years ago
|
[CustomEditor(typeof(Localization))]
|
||
|
public class LocalizationEditor : Editor
|
||
10 years ago
|
{
|
||
|
protected SerializedProperty activeLanguageProp;
|
||
10 years ago
|
protected SerializedProperty localizationFileProp;
|
||
10 years ago
|
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
activeLanguageProp = serializedObject.FindProperty("activeLanguage");
|
||
10 years ago
|
localizationFileProp = serializedObject.FindProperty("localizationFile");
|
||
10 years ago
|
}
|
||
|
|
||
|
public override void OnInspectorGUI()
|
||
|
{
|
||
|
serializedObject.Update();
|
||
|
|
||
10 years ago
|
Localization localization = target as Localization;
|
||
10 years ago
|
|
||
|
EditorGUILayout.PropertyField(activeLanguageProp);
|
||
10 years ago
|
EditorGUILayout.PropertyField(localizationFileProp);
|
||
10 years ago
|
|
||
10 years ago
|
if (GUILayout.Button(new GUIContent("Export Localization File")))
|
||
10 years ago
|
{
|
||
10 years ago
|
ExportLocalizationFile(localization);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
if (GUILayout.Button(new GUIContent("Export Standard Text")))
|
||
|
{
|
||
10 years ago
|
ExportStandardText(localization);
|
||
10 years ago
|
}
|
||
|
|
||
|
if (GUILayout.Button(new GUIContent("Import Standard Text")))
|
||
|
{
|
||
10 years ago
|
ImportStandardText(localization);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
serializedObject.ApplyModifiedProperties();
|
||
|
}
|
||
|
|
||
10 years ago
|
public virtual void ExportLocalizationFile(Localization localization)
|
||
10 years ago
|
{
|
||
10 years ago
|
string path = EditorUtility.SaveFilePanel("Export Localization File", "Assets/",
|
||
10 years ago
|
"localization.csv", "");
|
||
10 years ago
|
if (path.Length == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
string csvData = localization.GetCSVData();
|
||
10 years ago
|
File.WriteAllText(path, csvData);
|
||
10 years ago
|
AssetDatabase.Refresh();
|
||
10 years ago
|
|
||
10 years ago
|
ShowNotification(localization);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public virtual void ExportStandardText(Localization localization)
|
||
10 years ago
|
{
|
||
10 years ago
|
string path = EditorUtility.SaveFilePanel("Export Standard Text", "Assets/", "standard.txt", "");
|
||
10 years ago
|
if (path.Length == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
string textData = localization.GetStandardText();
|
||
10 years ago
|
File.WriteAllText(path, textData);
|
||
10 years ago
|
AssetDatabase.Refresh();
|
||
|
|
||
10 years ago
|
ShowNotification(localization);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public virtual void ImportStandardText(Localization localization)
|
||
10 years ago
|
{
|
||
|
string path = EditorUtility.OpenFilePanel("Import Standard Text", "Assets/", "txt");
|
||
|
if (path.Length == 0)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
string textData = File.ReadAllText(path);
|
||
10 years ago
|
localization.SetStandardText(textData);
|
||
10 years ago
|
|
||
10 years ago
|
ShowNotification(localization);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
protected virtual void ShowNotification(Localization localization)
|
||
10 years ago
|
{
|
||
|
EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart");
|
||
|
if (window != null)
|
||
|
{
|
||
10 years ago
|
window.ShowNotification(new GUIContent(localization.notificationText));
|
||
|
localization.notificationText = "";
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|