com.xmobitea.changx.mini-localization 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/LocalizationComponentEditor.cs +66 -0
- package/Editor/{LocalizationComponentBaseEditor.cs.meta → LocalizationComponentEditor.cs.meta} +11 -11
- package/Editor/LocalizationComponentWindowsEditor.cs +49 -5
- package/Editor/LocalizationKeyDrawer.cs +121 -0
- package/Editor/{TMP_LocalizationComponentWindowsEditor.cs.meta → LocalizationKeyDrawer.cs.meta} +11 -11
- package/Editor/LocalizationManagerEditor.cs +35 -13
- package/Editor/LocalizationSettingsEditor.cs +4 -5
- package/Editor/TMP_LocalizationComponentEditor.cs +66 -0
- package/Editor/TMP_LocalizationComponentEditor.cs.meta +11 -0
- package/Editor/Tools/GetLocalizationTools/linux-x64/GetLocalization +0 -0
- package/Editor/Tools/GetLocalizationTools/linux-x64/GetLocalization.pdb +0 -0
- package/Editor/Tools/GetLocalizationTools/osx-x64/GetLocalization +0 -0
- package/Editor/Tools/GetLocalizationTools/osx-x64/GetLocalization.pdb +0 -0
- package/Editor/Tools/GetLocalizationTools/win-x64/GetLocalization.exe +0 -0
- package/Editor/Tools/GetLocalizationTools/win-x64/GetLocalization.pdb +0 -0
- package/Runtime/LocalizationComponent.cs +3 -0
- package/Runtime/LocalizationConstanceId.cs +5 -0
- package/Runtime/LocalizationConstanceId.cs.meta +11 -0
- package/package.json +1 -1
- package/Editor/LocalizationComponentBaseEditor.cs +0 -20
- package/Editor/TMP_LocalizationComponentWindowsEditor.cs +0 -133
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
namespace XmobiTea.MiniLocalization.Editor
|
|
2
|
+
{
|
|
3
|
+
using System.IO;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
[CustomEditor(typeof(LocalizationComponent))]
|
|
9
|
+
public class LocalizationComponentEditor : Editor
|
|
10
|
+
{
|
|
11
|
+
SerializedProperty keyProp;
|
|
12
|
+
SerializedProperty mainTxtProp;
|
|
13
|
+
|
|
14
|
+
private void OnEnable()
|
|
15
|
+
{
|
|
16
|
+
keyProp = serializedObject.FindProperty("_key");
|
|
17
|
+
mainTxtProp = serializedObject.FindProperty("_mainTxt");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override void OnInspectorGUI()
|
|
21
|
+
{
|
|
22
|
+
serializedObject.Update();
|
|
23
|
+
|
|
24
|
+
EditorGUILayout.PropertyField(mainTxtProp);
|
|
25
|
+
|
|
26
|
+
EditorGUILayout.PropertyField(keyProp);
|
|
27
|
+
|
|
28
|
+
if (serializedObject.hasModifiedProperties) serializedObject.ApplyModifiedProperties();
|
|
29
|
+
|
|
30
|
+
EditorGUILayout.Space(20);
|
|
31
|
+
|
|
32
|
+
if (GUILayout.Button("Reload Text"))
|
|
33
|
+
{
|
|
34
|
+
var localizationComponentBase = (LocalizationComponentBase)target;
|
|
35
|
+
localizationComponentBase.OnUpdateText();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[MenuItem("XmobiTea Tools/Localization/Open Settings")]
|
|
40
|
+
private static void OpenSettings()
|
|
41
|
+
{
|
|
42
|
+
var localizationSettings = GetSettings();
|
|
43
|
+
|
|
44
|
+
Selection.SetActiveObjectWithContext(localizationSettings, localizationSettings);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static LocalizationSettings GetSettings()
|
|
48
|
+
{
|
|
49
|
+
var localizationSettings = Resources.Load<LocalizationSettings>(LocalizationSettings.ResourcesPath);
|
|
50
|
+
if (localizationSettings == null)
|
|
51
|
+
{
|
|
52
|
+
localizationSettings = ScriptableObject.CreateInstance<LocalizationSettings>();
|
|
53
|
+
|
|
54
|
+
var dirPath = Application.dataPath + "/Resources";
|
|
55
|
+
if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
|
|
56
|
+
|
|
57
|
+
var path = "Assets/Resources/" + LocalizationSettings.ResourcesPath + ".asset";
|
|
58
|
+
AssetDatabase.CreateAsset(localizationSettings, path);
|
|
59
|
+
|
|
60
|
+
Debug.Log("[Localization] Localization Settings create success at path " + path);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return localizationSettings;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
package/Editor/{LocalizationComponentBaseEditor.cs.meta → LocalizationComponentEditor.cs.meta}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid:
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 5b5bfbf16db005d4c92afef84a4c324e
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -5,10 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
using UnityEngine;
|
|
7
7
|
using UnityEngine.UI;
|
|
8
|
+
using UnityEditor.IMGUI.Controls;
|
|
9
|
+
using TMPro;
|
|
8
10
|
|
|
9
11
|
public class LocalizationComponentWindowsEditor : EditorWindow
|
|
10
12
|
{
|
|
11
|
-
private
|
|
13
|
+
private AdvancedDropdownState dropdownState = new AdvancedDropdownState();
|
|
14
|
+
|
|
15
|
+
private GameObject[] textsInScene;
|
|
12
16
|
|
|
13
17
|
Vector2 scrollPos = new Vector2(0, 0);
|
|
14
18
|
GUIStyle grayTextColor = GUIStyle.none;
|
|
@@ -30,11 +34,24 @@
|
|
|
30
34
|
{
|
|
31
35
|
if (parentGO)
|
|
32
36
|
{
|
|
33
|
-
|
|
37
|
+
var texts = parentGO.GetComponentsInChildren<Text>(true);
|
|
38
|
+
var tmpTexts = parentGO.GetComponentsInChildren<TMP_Text>(true);
|
|
39
|
+
|
|
40
|
+
textsInScene = new GameObject[texts.Length + tmpTexts.Length];
|
|
41
|
+
|
|
42
|
+
for (var i = 0; i < texts.Length; i++)
|
|
43
|
+
{
|
|
44
|
+
textsInScene[i] = texts[i].gameObject;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (var i = 0; i < tmpTexts.Length; i++)
|
|
48
|
+
{
|
|
49
|
+
textsInScene[texts.Length + i] = tmpTexts[i].gameObject;
|
|
50
|
+
}
|
|
34
51
|
}
|
|
35
52
|
else
|
|
36
53
|
{
|
|
37
|
-
textsInScene = new
|
|
54
|
+
textsInScene = new GameObject[0];
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|
|
@@ -81,21 +98,48 @@
|
|
|
81
98
|
}
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
var localizationComponent = text.GetComponent<
|
|
101
|
+
var localizationComponent = text.GetComponent<LocalizationComponentBase>();
|
|
85
102
|
if (localizationComponent)
|
|
86
103
|
{
|
|
87
104
|
localizationComponent.Key = GUILayout.TextField(localizationComponent.Key, GUILayout.Width(maxWidth * 2 / 5));
|
|
88
105
|
|
|
106
|
+
var keys = LocalizationKeyDrawer.GetKeys();
|
|
107
|
+
|
|
108
|
+
if (GUILayout.Button("▼", GUILayout.Width(maxWidth / 8)))
|
|
109
|
+
{
|
|
110
|
+
var buttonRect = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 30, EditorGUIUtility.singleLineHeight);
|
|
111
|
+
var dropdown = new LocalizationDropdown(dropdownState, keys, selectedKey =>
|
|
112
|
+
{
|
|
113
|
+
localizationComponent.Key = selectedKey;
|
|
114
|
+
});
|
|
115
|
+
dropdown.Show(buttonRect);
|
|
116
|
+
}
|
|
117
|
+
|
|
89
118
|
if (GUILayout.Button("Remove", GUILayout.Width(maxWidth / 5)))
|
|
90
119
|
{
|
|
91
120
|
DestroyImmediate(localizationComponent, true);
|
|
92
121
|
}
|
|
122
|
+
|
|
123
|
+
if (!string.IsNullOrEmpty(localizationComponent.Key))
|
|
124
|
+
{
|
|
125
|
+
if (!keys.Contains(localizationComponent.Key))
|
|
126
|
+
{
|
|
127
|
+
var style = new GUIStyle(EditorStyles.label);
|
|
128
|
+
style.richText = true;
|
|
129
|
+
|
|
130
|
+
GUILayout.Label("<color=red>" + localizationComponent.Key + "</color> missing on LocalizationConstanceId.cs", style);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
93
133
|
}
|
|
94
134
|
else
|
|
95
135
|
{
|
|
96
136
|
if (GUILayout.Button("Add LocalizationComponent", GUILayout.Width(maxWidth * 2 / 5)))
|
|
97
137
|
{
|
|
98
|
-
|
|
138
|
+
if (text.GetComponent<Text>() != null)
|
|
139
|
+
localizationComponent = text.gameObject.AddComponent<LocalizationComponent>();
|
|
140
|
+
else
|
|
141
|
+
localizationComponent = text.gameObject.AddComponent<TMP_LocalizationComponent>();
|
|
142
|
+
|
|
99
143
|
Selection.objects = new Object[] { text.gameObject };
|
|
100
144
|
}
|
|
101
145
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
namespace XmobiTea.MiniLocalization.Editor
|
|
2
|
+
{
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
|
|
6
|
+
using System;
|
|
7
|
+
using System.Collections.Generic;
|
|
8
|
+
using System.Linq;
|
|
9
|
+
using System.Reflection;
|
|
10
|
+
using UnityEditor.IMGUI.Controls;
|
|
11
|
+
|
|
12
|
+
public class LocalizationDropdown : AdvancedDropdown
|
|
13
|
+
{
|
|
14
|
+
private Action<string> onSelect;
|
|
15
|
+
private List<string> keys;
|
|
16
|
+
|
|
17
|
+
public LocalizationDropdown(AdvancedDropdownState state, List<string> keys, Action<string> onSelect) : base(state)
|
|
18
|
+
{
|
|
19
|
+
this.keys = keys;
|
|
20
|
+
this.onSelect = onSelect;
|
|
21
|
+
minimumSize = new Vector2(200, 300);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
protected override AdvancedDropdownItem BuildRoot()
|
|
25
|
+
{
|
|
26
|
+
var root = new AdvancedDropdownItem("Select Localization Key");
|
|
27
|
+
foreach (var key in keys)
|
|
28
|
+
{
|
|
29
|
+
root.AddChild(new AdvancedDropdownItem(key));
|
|
30
|
+
}
|
|
31
|
+
return root;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected override void ItemSelected(AdvancedDropdownItem item)
|
|
35
|
+
{
|
|
36
|
+
onSelect?.Invoke(item.name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[CustomPropertyDrawer(typeof(LocalizationKeyAttribute))]
|
|
41
|
+
public class LocalizationKeyDrawer : PropertyDrawer
|
|
42
|
+
{
|
|
43
|
+
private static List<string> keys = new List<string>();
|
|
44
|
+
private static long nextTimeUpdate;
|
|
45
|
+
|
|
46
|
+
private AdvancedDropdownState dropdownState = new AdvancedDropdownState();
|
|
47
|
+
|
|
48
|
+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
49
|
+
{
|
|
50
|
+
var keys = GetKeys();
|
|
51
|
+
|
|
52
|
+
EditorGUI.BeginProperty(position, label, property);
|
|
53
|
+
|
|
54
|
+
// Tạo khung cho filter và input text
|
|
55
|
+
var newKeyValue = EditorGUI.TextField(new Rect(position.x, position.y, position.width - 28, EditorGUIUtility.singleLineHeight), "Key", property.stringValue);
|
|
56
|
+
if (newKeyValue != property.stringValue) property.stringValue = newKeyValue;
|
|
57
|
+
|
|
58
|
+
if (!string.IsNullOrEmpty(property.stringValue))
|
|
59
|
+
{
|
|
60
|
+
if (!keys.Contains(property.stringValue))
|
|
61
|
+
{
|
|
62
|
+
var style = new GUIStyle(EditorStyles.label);
|
|
63
|
+
style.richText = true;
|
|
64
|
+
|
|
65
|
+
EditorGUI.LabelField(new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight), "\t\t<color=red>" + property.stringValue + "</color> missing on LocalizationConstanceId.cs", style);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (GUI.Button(new Rect(position.x + position.width - 25, position.y, 25, EditorGUIUtility.singleLineHeight), "▼"))
|
|
70
|
+
{
|
|
71
|
+
var buttonRect = new Rect(position.x + position.width - 30, position.y, 30, EditorGUIUtility.singleLineHeight);
|
|
72
|
+
var dropdown = new LocalizationDropdown(dropdownState, keys, selectedKey =>
|
|
73
|
+
{
|
|
74
|
+
property.stringValue = selectedKey;
|
|
75
|
+
property.serializedObject.ApplyModifiedProperties();
|
|
76
|
+
});
|
|
77
|
+
dropdown.Show(buttonRect);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
EditorGUI.EndProperty();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public static List<string> GetKeys()
|
|
84
|
+
{
|
|
85
|
+
var milliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
86
|
+
|
|
87
|
+
if (nextTimeUpdate < milliseconds)
|
|
88
|
+
{
|
|
89
|
+
nextTimeUpdate = 60000 + milliseconds;
|
|
90
|
+
|
|
91
|
+
keys.Clear();
|
|
92
|
+
|
|
93
|
+
var types = AppDomain.CurrentDomain.GetAssemblies()
|
|
94
|
+
.SelectMany(s => s.GetTypes())
|
|
95
|
+
.Where(p => p.Name == "LocalizationConstanceId" && p.Namespace == "XmobiTea.MiniLocalization").ToList();
|
|
96
|
+
|
|
97
|
+
foreach (var type in types)
|
|
98
|
+
{
|
|
99
|
+
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
|
100
|
+
|
|
101
|
+
foreach (var field in fields)
|
|
102
|
+
{
|
|
103
|
+
if (field.FieldType == typeof(string))
|
|
104
|
+
{
|
|
105
|
+
var value = field.GetValue(null) as string;
|
|
106
|
+
if (!string.IsNullOrEmpty(value))
|
|
107
|
+
{
|
|
108
|
+
if (!keys.Contains(value)) keys.Add(value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
keys = keys.OrderBy(x => x).ToList();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return keys;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
package/Editor/{TMP_LocalizationComponentWindowsEditor.cs.meta → LocalizationKeyDrawer.cs.meta}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
2
|
-
guid:
|
|
3
|
-
MonoImporter:
|
|
4
|
-
externalObjects: {}
|
|
5
|
-
serializedVersion: 2
|
|
6
|
-
defaultReferences: []
|
|
7
|
-
executionOrder: 0
|
|
8
|
-
icon: {instanceID: 0}
|
|
9
|
-
userData:
|
|
10
|
-
assetBundleName:
|
|
11
|
-
assetBundleVariant:
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: c89e549aa37295f4b934b14c58f5726d
|
|
3
|
+
MonoImporter:
|
|
4
|
+
externalObjects: {}
|
|
5
|
+
serializedVersion: 2
|
|
6
|
+
defaultReferences: []
|
|
7
|
+
executionOrder: 0
|
|
8
|
+
icon: {instanceID: 0}
|
|
9
|
+
userData:
|
|
10
|
+
assetBundleName:
|
|
11
|
+
assetBundleVariant:
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
[CustomEditor(typeof(LocalizationManager))]
|
|
11
11
|
public class LocalizationManagerEditor : Editor
|
|
12
12
|
{
|
|
13
|
-
private const string Version = "1.4.
|
|
13
|
+
private const string Version = "1.4.1";
|
|
14
14
|
private const string Library = @".\Library\PackageCache\com.xmobitea.changx.mini-localization@" + Version;
|
|
15
|
+
//private const string Library = @".\Assets\MiniLocalization";
|
|
15
16
|
private const string ProcessPath = @"\Editor\Tools\GetLocalizationTools";
|
|
16
17
|
private const string CredentialsPath = @"\Editor\Tools\GetLocalizationTools\credentials.json";
|
|
17
18
|
|
|
@@ -24,10 +25,10 @@
|
|
|
24
25
|
ShowLocalizationComponentWindowsEditor();
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
if (GUILayout.Button("Show TMP_LocalizationComponentWindows"))
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
}
|
|
28
|
+
//if (GUILayout.Button("Show TMP_LocalizationComponentWindows"))
|
|
29
|
+
//{
|
|
30
|
+
// ShowTMPLocalizationComponentWindowsEditor();
|
|
31
|
+
//}
|
|
31
32
|
|
|
32
33
|
if (GUILayout.Button("Generate LocalizationConstanceId.cs"))
|
|
33
34
|
{
|
|
@@ -46,11 +47,11 @@
|
|
|
46
47
|
LocalizationComponentWindowsEditor.ShowWindow();
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
[MenuItem("XmobiTea Tools/Localization/Show TMP_LocalizationComponentWindows")]
|
|
50
|
-
public static void ShowTMPLocalizationComponentWindowsEditor()
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
}
|
|
50
|
+
//[MenuItem("XmobiTea Tools/Localization/Show TMP_LocalizationComponentWindows")]
|
|
51
|
+
//public static void ShowTMPLocalizationComponentWindowsEditor()
|
|
52
|
+
//{
|
|
53
|
+
// TMP_LocalizationComponentWindowsEditor.ShowWindow();
|
|
54
|
+
//}
|
|
54
55
|
|
|
55
56
|
[MenuItem("XmobiTea Tools/Localization/Fetch Localization")]
|
|
56
57
|
public static void FetchLocalization()
|
|
@@ -92,8 +93,6 @@
|
|
|
92
93
|
|
|
93
94
|
processPath += "\\" + folderPath + "\\" + filePath123;
|
|
94
95
|
|
|
95
|
-
Debug.LogError(Application.dataPath);
|
|
96
|
-
|
|
97
96
|
var credentialsPath = Library + CredentialsPath;
|
|
98
97
|
|
|
99
98
|
var arguments = credentialsPath + " " + worksheetKey + (usingFetchLocalLocalization ? " true " : " false ") + (usingFetchOnlineLocalization ? "true " : "false ") + (string.IsNullOrEmpty(localizationSettings.SheetnameFetchLocalLocalization) ? "local" : localizationSettings.SheetnameFetchLocalLocalization) + " " + (string.IsNullOrEmpty(localizationSettings.SheetnameFetchOnlineLocalization) ? "online" : localizationSettings.SheetnameFetchOnlineLocalization);
|
|
@@ -102,9 +101,32 @@
|
|
|
102
101
|
|
|
103
102
|
for (var i = 0; i < localizationLanguageItems.Length; i++) arguments += " " + localizationLanguageItems[i].SystemLanguage;
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
Debug.Log("Run CommandLine " + processPath + " " + arguments);
|
|
105
|
+
|
|
106
|
+
var process = new System.Diagnostics.Process
|
|
107
|
+
{
|
|
108
|
+
StartInfo = new System.Diagnostics.ProcessStartInfo
|
|
109
|
+
{
|
|
110
|
+
FileName = processPath,
|
|
111
|
+
Arguments = arguments,
|
|
112
|
+
RedirectStandardOutput = true,
|
|
113
|
+
RedirectStandardError = true,
|
|
114
|
+
UseShellExecute = false,
|
|
115
|
+
CreateNoWindow = true
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
process.Start();
|
|
120
|
+
var output = process.StandardOutput.ReadToEnd();
|
|
121
|
+
var error = process.StandardError.ReadToEnd();
|
|
106
122
|
process.WaitForExit();
|
|
107
123
|
|
|
124
|
+
if (!string.IsNullOrEmpty(output))
|
|
125
|
+
Debug.Log("CommandLine with output " + output);
|
|
126
|
+
|
|
127
|
+
if (!string.IsNullOrEmpty(error))
|
|
128
|
+
Debug.LogError("Error while running CommandLine " + error);
|
|
129
|
+
|
|
108
130
|
for (var i = 0; i < localizationLanguageItems.Length; i++)
|
|
109
131
|
{
|
|
110
132
|
var localizationLanguageItem = localizationLanguageItems[i];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
namespace XmobiTea.MiniLocalization.Editor
|
|
2
2
|
{
|
|
3
3
|
using System.IO;
|
|
4
|
-
using NUnit.Framework;
|
|
5
4
|
using UnityEditor;
|
|
6
5
|
|
|
7
6
|
using UnityEngine;
|
|
@@ -83,10 +82,10 @@ namespace XmobiTea.MiniLocalization.Editor
|
|
|
83
82
|
LocalizationManagerEditor.ShowLocalizationComponentWindowsEditor();
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
if (GUILayout.Button("Show TMP_LocalizationComponentWindows"))
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
}
|
|
85
|
+
//if (GUILayout.Button("Show TMP_LocalizationComponentWindows"))
|
|
86
|
+
//{
|
|
87
|
+
// LocalizationManagerEditor.ShowTMPLocalizationComponentWindowsEditor();
|
|
88
|
+
//}
|
|
90
89
|
|
|
91
90
|
if (GUILayout.Button("Generate LocalizationConstanceId.cs"))
|
|
92
91
|
{
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
namespace XmobiTea.MiniLocalization.Editor
|
|
2
|
+
{
|
|
3
|
+
using System.IO;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
[CustomEditor(typeof(TMP_LocalizationComponent))]
|
|
9
|
+
public class TMP_LocalizationComponentEditor : Editor
|
|
10
|
+
{
|
|
11
|
+
SerializedProperty keyProp;
|
|
12
|
+
SerializedProperty mainTxtProp;
|
|
13
|
+
|
|
14
|
+
private void OnEnable()
|
|
15
|
+
{
|
|
16
|
+
keyProp = serializedObject.FindProperty("_key");
|
|
17
|
+
mainTxtProp = serializedObject.FindProperty("_mainTxt");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override void OnInspectorGUI()
|
|
21
|
+
{
|
|
22
|
+
serializedObject.Update();
|
|
23
|
+
|
|
24
|
+
EditorGUILayout.PropertyField(mainTxtProp);
|
|
25
|
+
|
|
26
|
+
EditorGUILayout.PropertyField(keyProp);
|
|
27
|
+
|
|
28
|
+
if (serializedObject.hasModifiedProperties) serializedObject.ApplyModifiedProperties();
|
|
29
|
+
|
|
30
|
+
EditorGUILayout.Space(20);
|
|
31
|
+
|
|
32
|
+
if (GUILayout.Button("Reload Text"))
|
|
33
|
+
{
|
|
34
|
+
var localizationComponentBase = (LocalizationComponentBase)target;
|
|
35
|
+
localizationComponentBase.OnUpdateText();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[MenuItem("XmobiTea Tools/Localization/Open Settings")]
|
|
40
|
+
private static void OpenSettings()
|
|
41
|
+
{
|
|
42
|
+
var localizationSettings = GetSettings();
|
|
43
|
+
|
|
44
|
+
Selection.SetActiveObjectWithContext(localizationSettings, localizationSettings);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static LocalizationSettings GetSettings()
|
|
48
|
+
{
|
|
49
|
+
var localizationSettings = Resources.Load<LocalizationSettings>(LocalizationSettings.ResourcesPath);
|
|
50
|
+
if (localizationSettings == null)
|
|
51
|
+
{
|
|
52
|
+
localizationSettings = ScriptableObject.CreateInstance<LocalizationSettings>();
|
|
53
|
+
|
|
54
|
+
var dirPath = Application.dataPath + "/Resources";
|
|
55
|
+
if (!Directory.Exists(dirPath)) Directory.CreateDirectory(dirPath);
|
|
56
|
+
|
|
57
|
+
var path = "Assets/Resources/" + LocalizationSettings.ResourcesPath + ".asset";
|
|
58
|
+
AssetDatabase.CreateAsset(localizationSettings, path);
|
|
59
|
+
|
|
60
|
+
Debug.Log("[Localization] Localization Settings create success at path " + path);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return localizationSettings;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
using UnityEngine;
|
|
4
4
|
using UnityEngine.UI;
|
|
5
5
|
|
|
6
|
+
public class LocalizationKeyAttribute : PropertyAttribute { }
|
|
7
|
+
|
|
6
8
|
[DisallowMultipleComponent]
|
|
7
9
|
public class LocalizationComponentBase : MonoBehaviour
|
|
8
10
|
{
|
|
11
|
+
[LocalizationKey]
|
|
9
12
|
[SerializeField]
|
|
10
13
|
protected string _key;
|
|
11
14
|
public string Key { get { return _key; } set { _key = value; } }
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
namespace XmobiTea.MiniLocalization.Editor
|
|
2
|
-
{
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
using UnityEditor;
|
|
5
|
-
|
|
6
|
-
[CustomEditor(typeof(LocalizationComponentBase))]
|
|
7
|
-
public class LocalizationComponentBaseEditor : Editor
|
|
8
|
-
{
|
|
9
|
-
public override void OnInspectorGUI()
|
|
10
|
-
{
|
|
11
|
-
base.OnInspectorGUI();
|
|
12
|
-
|
|
13
|
-
if (GUILayout.Button("Reload Text"))
|
|
14
|
-
{
|
|
15
|
-
var localizationComponentBase = (LocalizationComponentBase)target;
|
|
16
|
-
localizationComponentBase.OnUpdateText();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
namespace XmobiTea.MiniLocalization.Editor
|
|
2
|
-
{
|
|
3
|
-
using XmobiTea.MiniLocalization;
|
|
4
|
-
using UnityEditor;
|
|
5
|
-
|
|
6
|
-
using UnityEngine;
|
|
7
|
-
using TMPro;
|
|
8
|
-
|
|
9
|
-
public class TMP_LocalizationComponentWindowsEditor : EditorWindow
|
|
10
|
-
{
|
|
11
|
-
private TMP_Text[] textsInScene;
|
|
12
|
-
|
|
13
|
-
Vector2 scrollPos = new Vector2(0, 0);
|
|
14
|
-
GUIStyle grayTextColor = GUIStyle.none;
|
|
15
|
-
GameObject parentGO;
|
|
16
|
-
GameObject tempGO;
|
|
17
|
-
|
|
18
|
-
public static void ShowWindow()
|
|
19
|
-
{
|
|
20
|
-
//Show existing window instance. If one doesn't exist, make one.
|
|
21
|
-
EditorWindow.GetWindow(typeof(TMP_LocalizationComponentWindowsEditor));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private void OnEnable()
|
|
25
|
-
{
|
|
26
|
-
Refresh();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
void Refresh()
|
|
30
|
-
{
|
|
31
|
-
if (parentGO)
|
|
32
|
-
{
|
|
33
|
-
textsInScene = parentGO.GetComponentsInChildren<TMP_Text>(true);
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
{
|
|
37
|
-
textsInScene = new TMP_Text[0];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void OnGUI()
|
|
42
|
-
{
|
|
43
|
-
grayTextColor = new GUIStyle(GUI.skin.button);
|
|
44
|
-
grayTextColor.normal.textColor = Color.gray;
|
|
45
|
-
|
|
46
|
-
if (GUILayout.Button("Refresh")) Refresh();
|
|
47
|
-
//currentTab = GUILayout.Toolbar(currentTab, new string[] { "Text", "TMP" });
|
|
48
|
-
GUILayout.Label("Parent");
|
|
49
|
-
parentGO = (GameObject)EditorGUILayout.ObjectField(parentGO, typeof(GameObject), true);
|
|
50
|
-
if (tempGO != parentGO)
|
|
51
|
-
{
|
|
52
|
-
tempGO = parentGO;
|
|
53
|
-
Refresh();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUILayout.Width(position.width), GUILayout.Height(position.height - 20));
|
|
57
|
-
GUILayout.BeginVertical();
|
|
58
|
-
|
|
59
|
-
var maxWidth = position.width;
|
|
60
|
-
if (maxWidth > 500) maxWidth = 500;
|
|
61
|
-
|
|
62
|
-
for (var i = 0; i < textsInScene.Length; i++)
|
|
63
|
-
{
|
|
64
|
-
var text = textsInScene[i];
|
|
65
|
-
if (text)
|
|
66
|
-
{
|
|
67
|
-
GUILayout.BeginHorizontal();
|
|
68
|
-
|
|
69
|
-
if (!text.gameObject.activeInHierarchy)
|
|
70
|
-
{
|
|
71
|
-
if (GUILayout.Button(text.name, grayTextColor, GUILayout.Width(maxWidth * 2 / 5)))
|
|
72
|
-
{
|
|
73
|
-
Selection.objects = new Object[] { text.gameObject };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else
|
|
77
|
-
{
|
|
78
|
-
if (GUILayout.Button(text.name, GUILayout.Width(maxWidth * 2 / 5)))
|
|
79
|
-
{
|
|
80
|
-
Selection.objects = new Object[] { text.gameObject };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var localizationComponent = text.GetComponent<TMP_LocalizationComponent>();
|
|
85
|
-
if (localizationComponent)
|
|
86
|
-
{
|
|
87
|
-
localizationComponent.Key = GUILayout.TextField(localizationComponent.Key, GUILayout.Width(maxWidth * 2 / 5));
|
|
88
|
-
|
|
89
|
-
if (GUILayout.Button("Remove", GUILayout.Width(maxWidth / 5)))
|
|
90
|
-
{
|
|
91
|
-
DestroyImmediate(localizationComponent, true);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else
|
|
95
|
-
{
|
|
96
|
-
if (GUILayout.Button("Add LocalizationComponent", GUILayout.Width(maxWidth * 2 / 5)))
|
|
97
|
-
{
|
|
98
|
-
localizationComponent = text.gameObject.AddComponent<TMP_LocalizationComponent>();
|
|
99
|
-
Selection.objects = new Object[] { text.gameObject };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//if (GUI.Button(new Rect() { x = 0, y = 20 + 20 * i, width = 250, height = 20 }, text.name))
|
|
104
|
-
//{
|
|
105
|
-
// Selection.objects = new Object[] { text.gameObject };
|
|
106
|
-
//}
|
|
107
|
-
|
|
108
|
-
//var localizationComponent = text.GetComponent<LocalizationComponent>();
|
|
109
|
-
//if (localizationComponent)
|
|
110
|
-
//{
|
|
111
|
-
// localizationComponent.Key = GUI.TextField(new Rect() { x = 300, y = 20 + 20 * i, width = 250, height = 20 }, localizationComponent.Key);
|
|
112
|
-
//}
|
|
113
|
-
|
|
114
|
-
GUILayout.EndHorizontal();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
GUILayout.Space(5);
|
|
119
|
-
GUILayout.EndVertical();
|
|
120
|
-
GUILayout.EndScrollView();
|
|
121
|
-
|
|
122
|
-
//GUILayout.Label("Base Settings", EditorStyles.boldLabel);
|
|
123
|
-
//myString = EditorGUILayout.TextField("Text Field", myString);
|
|
124
|
-
|
|
125
|
-
//groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled);
|
|
126
|
-
//myBool = EditorGUILayout.Toggle("Toggle", myBool);
|
|
127
|
-
//myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
|
|
128
|
-
//EditorGUILayout.EndToggleGroup();
|
|
129
|
-
|
|
130
|
-
Repaint();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|