# Conflicts: # 03_RoyalGallery/Unity-19050-03_RoyalGallery_Navigator_PC/19050-03_RoyalGallery_Navigator_PC/Assets/PaintingNavigator.unitymaster
commit
fecb5af4c7
317 changed files with 47135 additions and 183 deletions
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 5043dbfa919aaf748813ccde4f3b395d |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Binary file not shown.
@ -0,0 +1,25 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 78520bdb08432d341bc6ebc3799d2bc9 |
||||
TrueTypeFontImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 4 |
||||
fontSize: 16 |
||||
forceTextureCase: -2 |
||||
characterSpacing: 0 |
||||
characterPadding: 1 |
||||
includeFontData: 1 |
||||
fontName: ITC Legacy Sans Std |
||||
fontNames: |
||||
- ITC Legacy Sans Std |
||||
fallbackFontReferences: |
||||
- {fileID: 12800000, guid: 299e5747903dc2e4bb9a9da6e10407a4, type: 3} |
||||
- {fileID: 12800000, guid: 03ad2e2a2160ef747bf8b8434882a677, type: 3} |
||||
- {fileID: 12800000, guid: 03d1ce0b5d08ae34bb701e32e49190d4, type: 3} |
||||
customCharacters: |
||||
fontRenderingMode: 0 |
||||
ascentCalculationMode: 1 |
||||
useLegacyBoundsCalculation: 0 |
||||
shouldRoundAdvanceValue: 1 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Binary file not shown.
@ -0,0 +1,24 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 03d1ce0b5d08ae34bb701e32e49190d4 |
||||
TrueTypeFontImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 4 |
||||
fontSize: 16 |
||||
forceTextureCase: -2 |
||||
characterSpacing: 0 |
||||
characterPadding: 1 |
||||
includeFontData: 1 |
||||
fontName: ITC Legacy Sans Std |
||||
fontNames: |
||||
- ITC Legacy Sans Std |
||||
fallbackFontReferences: |
||||
- {fileID: 12800000, guid: 299e5747903dc2e4bb9a9da6e10407a4, type: 3} |
||||
- {fileID: 12800000, guid: 03ad2e2a2160ef747bf8b8434882a677, type: 3} |
||||
customCharacters: |
||||
fontRenderingMode: 0 |
||||
ascentCalculationMode: 1 |
||||
useLegacyBoundsCalculation: 0 |
||||
shouldRoundAdvanceValue: 1 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Binary file not shown.
@ -0,0 +1,29 @@ |
||||
fileFormatVersion: 2 |
||||
guid: b4bc84d553f9ade40a335ca008476e0c |
||||
TrueTypeFontImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 4 |
||||
fontSize: 16 |
||||
forceTextureCase: -2 |
||||
characterSpacing: 0 |
||||
characterPadding: 1 |
||||
includeFontData: 1 |
||||
fontName: Noto Serif TC |
||||
fontNames: |
||||
- Noto Serif TC |
||||
fallbackFontReferences: |
||||
- {fileID: 12800000, guid: e3b006f78a69d094c8541f00f92ecd2d, type: 3} |
||||
- {fileID: 12800000, guid: d5352d299496eeb4c9941677b484d3ab, type: 3} |
||||
- {fileID: 12800000, guid: 9cfd8f3ae96017a4d80a52acd05dca6f, type: 3} |
||||
- {fileID: 12800000, guid: 559b687a35d5483428b6abde3726d21e, type: 3} |
||||
- {fileID: 12800000, guid: baaebbda857fb434088188bc8e3f45a9, type: 3} |
||||
- {fileID: 12800000, guid: 78760ffde7128a242936eadb7a7a236c, type: 3} |
||||
- {fileID: 12800000, guid: b618e9ffd0110c54e92791c9fa119f11, type: 3} |
||||
customCharacters: |
||||
fontRenderingMode: 0 |
||||
ascentCalculationMode: 1 |
||||
useLegacyBoundsCalculation: 0 |
||||
shouldRoundAdvanceValue: 1 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Binary file not shown.
@ -0,0 +1,22 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 670b62df12ed8d642b8d7cb9bbe03a6f |
||||
TrueTypeFontImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 4 |
||||
fontSize: 16 |
||||
forceTextureCase: -2 |
||||
characterSpacing: 0 |
||||
characterPadding: 1 |
||||
includeFontData: 1 |
||||
fontName: Noto Serif Thai |
||||
fontNames: |
||||
- Noto Serif Thai |
||||
fallbackFontReferences: [] |
||||
customCharacters: |
||||
fontRenderingMode: 0 |
||||
ascentCalculationMode: 1 |
||||
useLegacyBoundsCalculation: 0 |
||||
shouldRoundAdvanceValue: 1 |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 3074b4f32f699ca4d8f6f9760b75ae03 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 49a83a8bbbd9d8b4b81bedcea0774420 |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,9 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 379147f1ab5034075a5b1578456aca00 |
||||
folderAsset: yes |
||||
timeCreated: 1461137613 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 8f9a3530624fd5c47a2dc16eb641ddb8 |
||||
folderAsset: yes |
||||
timeCreated: 1520745251 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,13 @@ |
||||
fileFormatVersion: 2 |
||||
guid: ec5b9e0d683ff2b409340ac814051bb8 |
||||
timeCreated: 1507704861 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
externalObjects: {} |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,188 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public class BaseSpecializationManager |
||||
{ |
||||
public string[] mSpecializations; |
||||
public Dictionary<string, string> mSpecializationsFallbacks; |
||||
|
||||
public virtual void InitializeSpecializations() |
||||
{ |
||||
mSpecializations = new[] { "Any", "PC", "Touch", "Controller", "VR", |
||||
"XBox", "PS4", "OculusVR", "ViveVR", "GearVR", "Android", "IOS" }; |
||||
mSpecializationsFallbacks = new Dictionary<string, string>(System.StringComparer.Ordinal) |
||||
{ |
||||
{ "XBox", "Controller" }, { "PS4", "Controller" }, |
||||
{ "OculusVR", "VR" }, { "ViveVR", "VR" }, { "GearVR", "VR" }, |
||||
{ "Android", "Touch" }, { "IOS", "Touch" } |
||||
}; |
||||
} |
||||
|
||||
public virtual string GetCurrentSpecialization() |
||||
{ |
||||
if (mSpecializations == null) |
||||
InitializeSpecializations(); |
||||
|
||||
#if UNITY_ANDROID |
||||
return "Android"; |
||||
#elif UNITY_IOS |
||||
return "IOS"; |
||||
#elif UNITY_PS4 |
||||
return "PS4"; |
||||
#elif UNITY_XBOXONE |
||||
return "XBox"; |
||||
#elif UNITY_STANDALONE || UNITY_WEBGL |
||||
return "PC"; |
||||
#else |
||||
return (Input.touchSupported ? "Touch" : "PC"); |
||||
#endif |
||||
} |
||||
|
||||
public virtual string GetFallbackSpecialization(string specialization) |
||||
{ |
||||
if (mSpecializationsFallbacks == null) |
||||
InitializeSpecializations(); |
||||
|
||||
string fallback; |
||||
if (mSpecializationsFallbacks.TryGetValue(specialization, out fallback)) |
||||
return fallback; |
||||
return "Any"; |
||||
} |
||||
} |
||||
public class SpecializationManager : BaseSpecializationManager |
||||
{ |
||||
public static SpecializationManager Singleton = new SpecializationManager(); |
||||
|
||||
private SpecializationManager() |
||||
{ |
||||
InitializeSpecializations(); |
||||
} |
||||
|
||||
public static string GetSpecializedText(string text, string specialization = null) |
||||
{ |
||||
var idxFirst = text.IndexOf("[i2s_", StringComparison.Ordinal); |
||||
if (idxFirst < 0) |
||||
return text; |
||||
|
||||
if (string.IsNullOrEmpty(specialization)) |
||||
specialization = Singleton.GetCurrentSpecialization(); |
||||
|
||||
while (!string.IsNullOrEmpty(specialization) && specialization != "Any") |
||||
{ |
||||
var tag = "[i2s_" + specialization + "]"; |
||||
int idx = text.IndexOf(tag, StringComparison.Ordinal); |
||||
if (idx < 0) |
||||
{ |
||||
specialization = Singleton.GetFallbackSpecialization(specialization); |
||||
continue; |
||||
} |
||||
|
||||
idx += tag.Length; |
||||
var idxEnd = text.IndexOf("[i2s_", idx, StringComparison.Ordinal); |
||||
if (idxEnd < 0) idxEnd = text.Length; |
||||
|
||||
return text.Substring(idx, idxEnd - idx); |
||||
} |
||||
|
||||
return text.Substring(0, idxFirst); |
||||
} |
||||
|
||||
public static string SetSpecializedText(string text, string newText, string specialization) |
||||
{ |
||||
if (string.IsNullOrEmpty(specialization)) |
||||
specialization = "Any"; |
||||
if ((text==null || !text.Contains("[i2s_")) && specialization=="Any") |
||||
{ |
||||
return newText; |
||||
} |
||||
|
||||
var dict = GetSpecializations(text); |
||||
dict[specialization] = newText; |
||||
|
||||
return SetSpecializedText(dict); |
||||
} |
||||
|
||||
public static string SetSpecializedText( Dictionary<string,string> specializations ) |
||||
{ |
||||
string text; |
||||
if (!specializations.TryGetValue("Any", out text)) |
||||
text = string.Empty; |
||||
|
||||
foreach (var kvp in specializations) |
||||
{ |
||||
if (kvp.Key != "Any" && !string.IsNullOrEmpty(kvp.Value)) |
||||
text += "[i2s_" + kvp.Key + "]" + kvp.Value; |
||||
} |
||||
return text; |
||||
} |
||||
|
||||
public static Dictionary<string, string> GetSpecializations(string text, Dictionary<string, string> buffer = null) |
||||
{ |
||||
if (buffer == null) |
||||
buffer = new Dictionary<string, string>(StringComparer.Ordinal); |
||||
else |
||||
buffer.Clear(); |
||||
|
||||
if (text==null) |
||||
{ |
||||
buffer["Any"] = ""; |
||||
return buffer; |
||||
} |
||||
|
||||
var idxFirst = 0; |
||||
var idxEnd = text.IndexOf("[i2s_", StringComparison.Ordinal); |
||||
if (idxEnd < 0) |
||||
idxEnd=text.Length; |
||||
|
||||
buffer["Any"] = text.Substring(0, idxEnd); |
||||
idxFirst = idxEnd; |
||||
|
||||
while (idxFirst<text.Length) |
||||
{ |
||||
idxFirst += "[i2s_".Length; |
||||
int idx = text.IndexOf(']', idxFirst); |
||||
if (idx < 0) break; |
||||
var tag = text.Substring(idxFirst, idx - idxFirst); |
||||
idxFirst = idx+1; // ']' |
||||
|
||||
idxEnd = text.IndexOf("[i2s_", idxFirst, StringComparison.Ordinal); |
||||
if (idxEnd < 0) idxEnd = text.Length; |
||||
var value = text.Substring(idxFirst, idxEnd - idxFirst); |
||||
|
||||
buffer[tag] = value; |
||||
idxFirst = idxEnd; |
||||
} |
||||
return buffer; |
||||
} |
||||
public static void AppendSpecializations(string text, List<string> list=null) |
||||
{ |
||||
if (text == null) |
||||
return; |
||||
|
||||
if (list == null) |
||||
list = new List<string>(); |
||||
|
||||
if (!list.Contains("Any")) |
||||
list.Add("Any"); |
||||
|
||||
var idxFirst = 0; |
||||
while (idxFirst<text.Length) |
||||
{ |
||||
idxFirst = text.IndexOf("[i2s_", idxFirst, StringComparison.Ordinal); |
||||
if (idxFirst < 0) |
||||
break; |
||||
|
||||
idxFirst += "[i2s_".Length; |
||||
int idx = text.IndexOf(']', idxFirst); |
||||
if (idx < 0) |
||||
break; |
||||
|
||||
var tag = text.Substring(idxFirst, idx - idxFirst); |
||||
if (!list.Contains(tag)) |
||||
list.Add(tag); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: a72e5d6dba43bf249987cd37521e38bb |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: c123c665b73ed7c4999162c0d009550d |
||||
folderAsset: yes |
||||
DefaultImporter: |
||||
externalObjects: {} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: df33c1000ac895241a433812e40a2096 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
@ -0,0 +1,9 @@ |
||||
fileFormatVersion: 2 |
||||
guid: a500716e59f61824ba1fa6b418ce31a7 |
||||
folderAsset: yes |
||||
timeCreated: 1461137613 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: f03a75bf70a306a4fb36646f24c1c1f1 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: a441ed994a43a0a4a9d33be67a8d3f15 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 90c932abd0dc445448366dfe101408ba |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,12 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 93f1f9aecf6f7ed40ad1a082c22c47e5 |
||||
timeCreated: 1468111539 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,12 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 65bbef08e6e42d24d9834945c3769202 |
||||
timeCreated: 1468111539 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,896 @@ |
||||
//#define UGUI |
||||
//#define NGUI |
||||
//#define DFGUI |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Reflection; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using Object = UnityEngine.Object; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
[CustomEditor(typeof(Localize))] |
||||
[CanEditMultipleObjects] |
||||
public class LocalizeInspector : Editor |
||||
{ |
||||
#region Variables |
||||
|
||||
Localize mLocalize; |
||||
SerializedProperty mProp_mTerm, mProp_mTermSecondary, |
||||
mProp_TranslatedObjects, mProp_LocalizeOnAwake, mProp_AlwaysForceLocalize, mProp_AllowLocalizedParameters, mProp_AllowParameters, |
||||
mProp_IgnoreRTL, mProp_MaxCharactersInRTL, mProp_CorrectAlignmentForRTL, mProp_IgnoreNumbersInRTL, mProp_TermSuffix, mProp_TermPrefix, mProp_SeparateWords, |
||||
mProp_CallbackEvent; |
||||
|
||||
|
||||
bool mAllowEditKeyName; |
||||
string mNewKeyName = ""; |
||||
|
||||
string[] mTermsArray; |
||||
|
||||
|
||||
public static string HelpURL_forum = "http://goo.gl/Uiyu8C";//http://www.inter-illusion.com/forum/i2-localization"; |
||||
public static string HelpURL_Documentation = "http://www.inter-illusion.com/assets/I2LocalizationManual/I2LocalizationManual.html"; |
||||
public static string HelpURL_Tutorials = "http://inter-illusion.com/tools/i2-localization"; |
||||
public static string HelpURL_ReleaseNotes = "http://inter-illusion.com/forum/i2-localization/26-release-notes"; |
||||
public static string HelpURL_AssetStore = "https://www.assetstore.unity3d.com/#!/content/14884"; |
||||
|
||||
public static LocalizeInspector mLocalizeInspector; |
||||
#endregion |
||||
|
||||
#region Inspector |
||||
|
||||
void OnEnable() |
||||
{ |
||||
mLocalize = (Localize)target; |
||||
mLocalizeInspector = this; |
||||
LocalizationEditor.mCurrentInspector = this; |
||||
mProp_mTerm = serializedObject.FindProperty("mTerm"); |
||||
mProp_mTermSecondary = serializedObject.FindProperty("mTermSecondary"); |
||||
mProp_TranslatedObjects = serializedObject.FindProperty("TranslatedObjects"); |
||||
mProp_IgnoreRTL = serializedObject.FindProperty("IgnoreRTL"); |
||||
mProp_SeparateWords = serializedObject.FindProperty("AddSpacesToJoinedLanguages"); |
||||
mProp_MaxCharactersInRTL = serializedObject.FindProperty ("MaxCharactersInRTL"); |
||||
mProp_IgnoreNumbersInRTL = serializedObject.FindProperty("IgnoreNumbersInRTL"); |
||||
mProp_CorrectAlignmentForRTL = serializedObject.FindProperty ("CorrectAlignmentForRTL"); |
||||
mProp_LocalizeOnAwake = serializedObject.FindProperty("LocalizeOnAwake"); |
||||
mProp_AlwaysForceLocalize = serializedObject.FindProperty("AlwaysForceLocalize"); |
||||
mProp_TermSuffix = serializedObject.FindProperty("TermSuffix"); |
||||
mProp_TermPrefix = serializedObject.FindProperty("TermPrefix"); |
||||
mProp_CallbackEvent = serializedObject.FindProperty("LocalizeEvent"); |
||||
mProp_AllowLocalizedParameters = serializedObject.FindProperty("AllowLocalizedParameters"); |
||||
mProp_AllowParameters = serializedObject.FindProperty("AllowParameters"); |
||||
|
||||
|
||||
if (LocalizationManager.Sources.Count==0) |
||||
LocalizationManager.UpdateSources(); |
||||
//LocalizationEditor.ParseTerms (true); |
||||
|
||||
//mGUI_ShowReferences = (mLocalize.TranslatedObjects!=null && mLocalize.TranslatedObjects.Length>0); |
||||
//mGUI_ShowCallback = (mLocalize.LocalizeCallBack.Target!=null); |
||||
//mGUI_ShowTems = true; |
||||
LocalizationEditor.mKeysDesc_AllowEdit = false; |
||||
GUI_SelectedTerm = 0; |
||||
mNewKeyName = mLocalize.Term; |
||||
|
||||
if (mLocalize.Source != null) |
||||
LocalizationEditor.mLanguageSource = mLocalize.Source.SourceData; |
||||
else |
||||
{ |
||||
if (LocalizationManager.Sources.Count==0) |
||||
LocalizationManager.UpdateSources(); |
||||
LocalizationEditor.mLanguageSource = LocalizationManager.GetSourceContaining( mLocalize.Term ); |
||||
} |
||||
|
||||
//UpgradeManager.EnablePlugins(); |
||||
LocalizationEditor.ApplyInferredTerm (mLocalize); |
||||
RemoveUnusedReferences(mLocalize); |
||||
} |
||||
|
||||
void OnDisable() |
||||
{ |
||||
mLocalizeInspector = null; |
||||
if (LocalizationEditor.mCurrentInspector == this) LocalizationEditor.mCurrentInspector = null; |
||||
|
||||
|
||||
if (mLocalize == null) |
||||
return; |
||||
|
||||
//#if TextMeshPro |
||||
//string previous = null; |
||||
|
||||
//if (!Application.isPlaying && !string.IsNullOrEmpty(mLocalize.TMP_previewLanguage)) |
||||
//{ |
||||
// previous = LocalizationManager.CurrentLanguage; |
||||
// LocalizationManager.PreviewLanguage( mLocalize.TMP_previewLanguage ); |
||||
//} |
||||
//#endif |
||||
|
||||
//mLocalize.OnLocalize(); |
||||
|
||||
// Revert the preview language |
||||
// except when in TMPro and not changing to another GameObject (TMPro has a bug where any change causes the inspector to Disable and Enable) |
||||
if (!mLocalize.mLocalizeTargetName.Contains("LocalizeTarget_TextMeshPro") || Selection.activeGameObject==null || !Selection.gameObjects.Contains(mLocalize.gameObject)) |
||||
{ |
||||
LocalizationManager.LocalizeAll(); |
||||
} |
||||
|
||||
//#if TextMeshPro |
||||
//if (!string.IsNullOrEmpty(previous)) |
||||
//{ |
||||
// LocalizationManager.PreviewLanguage(previous); |
||||
// mLocalize.TMP_previewLanguage = null; |
||||
//} |
||||
//#endif |
||||
|
||||
RemoveUnusedReferences(mLocalize); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region GUI |
||||
|
||||
public override void OnInspectorGUI() |
||||
{ |
||||
Undo.RecordObject(target, "Localize"); |
||||
|
||||
//GUI.backgroundColor = Color.Lerp (Color.black, Color.gray, 1); |
||||
//GUILayout.BeginVertical(GUIStyle_Background, GUILayout.Height(1)); |
||||
//GUI.backgroundColor = Color.white; |
||||
|
||||
if (GUILayout.Button("Localize", GUIStyle_Header)) |
||||
{ |
||||
//Application.OpenURL(HelpURL_Documentation); |
||||
} |
||||
GUILayout.Space(-10); |
||||
|
||||
LocalizationManager.UpdateSources(); |
||||
|
||||
if (LocalizationManager.Sources.Count==0) |
||||
{ |
||||
EditorGUILayout.HelpBox("Unable to find a Language Source.", MessageType.Warning); |
||||
} |
||||
else |
||||
{ |
||||
GUILayout.Space(10); |
||||
OnGUI_Target (); |
||||
GUILayout.Space(10); |
||||
OnGUI_Terms(); |
||||
|
||||
//if (mGUI_ShowTems || mGUI_ShowReferences) GUILayout.Space(5); |
||||
|
||||
OnGUI_References(); |
||||
|
||||
if (mLocalize.mGUI_ShowReferences || mLocalize.mGUI_ShowCallback) GUILayout.Space(10); |
||||
|
||||
//Localize loc = target as Localize; |
||||
|
||||
//--[ Localize Callback ]---------------------- |
||||
EditorGUILayout.PropertyField(mProp_CallbackEvent, new GUIContent("On Localize Callback")); |
||||
|
||||
//string HeaderTitle = "On Localize Call:"; |
||||
//if (!mLocalize.mGUI_ShowCallback && loc.LocalizeCallBack.Target!=null && !string.IsNullOrEmpty(loc.LocalizeCallBack.MethodName)) |
||||
// HeaderTitle = string.Concat(HeaderTitle, " <b>",loc.LocalizeCallBack.Target.name, ".</b><i>", loc.LocalizeCallBack.MethodName, "</i>"); |
||||
//mLocalize.mGUI_ShowCallback = GUITools.DrawHeader(HeaderTitle, mLocalize.mGUI_ShowCallback); |
||||
//if (mLocalize.mGUI_ShowCallback) |
||||
//{ |
||||
// GUITools.BeginContents(); |
||||
// DrawEventCallBack( loc.LocalizeCallBack, loc ); |
||||
// GUITools.EndContents(); |
||||
//} |
||||
} |
||||
OnGUI_Source (); |
||||
|
||||
GUILayout.Space (10); |
||||
|
||||
GUITools.OnGUI_Footer("I2 Localization", LocalizationManager.GetVersion(), HelpURL_forum, HelpURL_Documentation, HelpURL_AssetStore); |
||||
|
||||
//GUILayout.EndVertical(); |
||||
|
||||
serializedObject.ApplyModifiedProperties(); |
||||
if (Event.current.type == EventType.Repaint) |
||||
{ |
||||
LocalizationEditor.mTestAction = LocalizationEditor.eTest_ActionType.None; |
||||
LocalizationEditor.mTestActionArg = null; |
||||
LocalizationEditor.mTestActionArg2 = null; |
||||
} |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region References |
||||
|
||||
void OnGUI_References() |
||||
{ |
||||
if (mLocalize.mGUI_ShowReferences = GUITools.DrawHeader ("References", mLocalize.mGUI_ShowReferences)) |
||||
{ |
||||
GUITools.BeginContents(); |
||||
|
||||
bool canTest = Event.current.type == EventType.Repaint; |
||||
|
||||
var testAddObj = canTest && LocalizationEditor.mTestAction == LocalizationEditor.eTest_ActionType.Button_Assets_Add ? (Object)LocalizationEditor.mTestActionArg : null; |
||||
var testReplaceIndx = canTest && LocalizationEditor.mTestAction == LocalizationEditor.eTest_ActionType.Button_Assets_Replace ? (int)LocalizationEditor.mTestActionArg : -1; |
||||
var testReplaceObj = canTest && LocalizationEditor.mTestAction == LocalizationEditor.eTest_ActionType.Button_Assets_Replace ? (Object)LocalizationEditor.mTestActionArg2 : null; |
||||
var testDeleteIndx = canTest && LocalizationEditor.mTestAction == LocalizationEditor.eTest_ActionType.Button_Assets_Delete ? (int)LocalizationEditor.mTestActionArg : -1; |
||||
|
||||
bool changed = GUITools.DrawObjectsArray( mProp_TranslatedObjects, false, false, true, testAddObj, testReplaceObj, testReplaceIndx, testDeleteIndx); |
||||
if (changed) |
||||
{ |
||||
serializedObject.ApplyModifiedProperties(); |
||||
foreach (var obj in serializedObject.targetObjects) |
||||
(obj as Localize).UpdateAssetDictionary(); |
||||
} |
||||
|
||||
GUITools.EndContents(); |
||||
} |
||||
} |
||||
|
||||
void RemoveUnusedReferences(Localize cmp) |
||||
{ |
||||
cmp.TranslatedObjects.RemoveAll(x => !IsUsingReference(LocalizationManager.GetTermData(cmp.Term), x) && !IsUsingReference(LocalizationManager.GetTermData(cmp.SecondaryTerm), x)); |
||||
if (cmp.TranslatedObjects.Count != cmp.mAssetDictionary.Count) |
||||
cmp.UpdateAssetDictionary(); |
||||
} |
||||
|
||||
bool IsUsingReference(TermData termData, Object obj ) |
||||
{ |
||||
if (obj == null || termData==null) return false; |
||||
|
||||
string objName = obj.name; |
||||
foreach (string translation in termData.Languages) |
||||
{ |
||||
if (translation != null && translation.Contains(objName)) |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
#endregion |
||||
|
||||
|
||||
#region Terms |
||||
|
||||
int GUI_SelectedTerm; |
||||
void OnGUI_Terms() |
||||
{ |
||||
if ((mLocalize.mGUI_ShowTems=GUITools.DrawHeader ("Terms", mLocalize.mGUI_ShowTems))) |
||||
{ |
||||
//--[ tabs: Main and Secondary Terms ]---------------- |
||||
int oldTab = GUI_SelectedTerm; |
||||
if (mLocalize.mLocalizeTarget!=null && mLocalize.mLocalizeTarget.CanUseSecondaryTerm()) |
||||
{ |
||||
GUI_SelectedTerm = GUITools.DrawTabs (GUI_SelectedTerm, new[]{"Main", "Secondary"}); |
||||
} |
||||
else |
||||
{ |
||||
GUI_SelectedTerm = 0; |
||||
GUITools.DrawTabs (GUI_SelectedTerm, new[]{"Main", ""}); |
||||
} |
||||
|
||||
GUITools.BeginContents(); |
||||
|
||||
TermData termData = null; |
||||
|
||||
if (GUI_SelectedTerm==0) termData = OnGUI_PrimaryTerm( oldTab!=GUI_SelectedTerm ); |
||||
else termData = OnGUI_SecondaryTerm(oldTab!=GUI_SelectedTerm); |
||||
|
||||
GUITools.EndContents(); |
||||
|
||||
//--[ Modifier ]------------- |
||||
if (mLocalize.Term != "-" && termData!=null && termData.TermType==eTermType.Text) |
||||
{ |
||||
EditorGUI.BeginChangeCheck(); |
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label("Prefix:"); |
||||
EditorGUILayout.PropertyField(mProp_TermPrefix, GUITools.EmptyContent); |
||||
GUILayout.Label("Suffix:"); |
||||
EditorGUILayout.PropertyField(mProp_TermSuffix, GUITools.EmptyContent); |
||||
GUILayout.EndHorizontal(); |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
EditorApplication.delayCall += () => |
||||
{ |
||||
if (targets != null) |
||||
{ |
||||
foreach (var t in targets) |
||||
if (t as Localize != null) |
||||
(t as Localize).OnLocalize(true); |
||||
} |
||||
}; |
||||
} |
||||
EditorGUI.BeginChangeCheck(); |
||||
int val = EditorGUILayout.Popup("Modifier", GUI_SelectedTerm == 0 ? (int)mLocalize.PrimaryTermModifier : (int)mLocalize.SecondaryTermModifier, Enum.GetNames(typeof(Localize.TermModification))); |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
serializedObject.FindProperty(GUI_SelectedTerm == 0 ? "PrimaryTermModifier" : "SecondaryTermModifier").enumValueIndex = val; |
||||
GUI.changed = false; |
||||
} |
||||
} |
||||
|
||||
OnGUI_Options(); |
||||
//--[ OnAwake vs OnEnable ]------------- |
||||
//GUILayout.BeginHorizontal(); |
||||
//mProp_LocalizeOnAwake.boolValue = GUILayout.Toggle(mProp_LocalizeOnAwake.boolValue, new GUIContent(" Pre-Localize on Awake", "Localizing on Awake could result in a lag when the level is loaded but faster later when objects are enabled. If false, it will Localize OnEnable, so will yield faster level load but could have a lag when screens are enabled")); |
||||
//GUILayout.FlexibleSpace(); |
||||
//if (mLocalize.HasCallback()) |
||||
//{ |
||||
// GUI.enabled = false; |
||||
// GUILayout.Toggle(true, new GUIContent(" Force Localize", "Enable this when the translations have parameters (e.g. Thew winner is {[WINNER}]) to prevent any optimization that could prevent updating the translation when the object is enabled")); |
||||
// GUI.enabled = true; |
||||
//} |
||||
//else |
||||
//{ |
||||
// mProp_AlwaysForceLocalize.boolValue = GUILayout.Toggle(mProp_AlwaysForceLocalize.boolValue, new GUIContent(" Force Localize", "Enable this when the translations have parameters (e.g. Thew winner is {[WINNER}]) to prevent any optimization that could prevent updating the translation when the object is enabled")); |
||||
//} |
||||
//GUILayout.EndHorizontal(); |
||||
|
||||
//--[ Right To Left ]------------- |
||||
if (!mLocalize.IgnoreRTL && mLocalize.Term!="-" && termData != null && termData.TermType == eTermType.Text) |
||||
{ |
||||
GUILayout.BeginVertical("Box"); |
||||
//GUILayout.BeginHorizontal(); |
||||
// mProp_IgnoreRTL.boolValue = GUILayout.Toggle(mProp_IgnoreRTL.boolValue, new GUIContent(" Ignore Right To Left", "Arabic and other RTL languages require processing them so they render correctly, this toogle allows ignoring that processing (in case you are doing it manually during a callback)")); |
||||
// GUILayout.FlexibleSpace(); |
||||
// mProp_SeparateWords.boolValue = GUILayout.Toggle(mProp_SeparateWords.boolValue, new GUIContent(" Separate Words", " Some languages (e.g. Chinese, Japanese and Thai) don't add spaces to their words (all characters are placed toguether), enabling this checkbox, will add spaces to all characters to allow wrapping long texts into multiple lines.")); |
||||
//GUILayout.EndHorizontal(); |
||||
{ |
||||
mProp_MaxCharactersInRTL.intValue = EditorGUILayout.IntField( new GUIContent("Max line length", "If the language is Right To Left, long lines will be split at this length and the RTL fix will be applied to each line, this should be set to the maximum number of characters that fit in this text width. 0 disables the per line fix"), mProp_MaxCharactersInRTL.intValue ); |
||||
GUILayout.BeginHorizontal(); |
||||
mProp_CorrectAlignmentForRTL.boolValue = GUILayout.Toggle(mProp_CorrectAlignmentForRTL.boolValue, new GUIContent(" Adjust Alignment", "Right-align when Right-To-Left Language, and Left-Align otherwise") ); |
||||
GUILayout.FlexibleSpace(); |
||||
mProp_IgnoreNumbersInRTL.boolValue = GUILayout.Toggle(mProp_IgnoreNumbersInRTL.boolValue, new GUIContent(" Ignore Numbers", "Preserve numbers as latin characters instead of converting them")); |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
GUILayout.EndVertical(); |
||||
} |
||||
|
||||
|
||||
////GUILayout.EndHorizontal(); |
||||
} |
||||
} |
||||
|
||||
void OnGUI_Options() |
||||
{ |
||||
int mask = 0; |
||||
if (mProp_LocalizeOnAwake.boolValue) mask |= 1 << 0; |
||||
if (mProp_AlwaysForceLocalize.boolValue) mask |= 1 << 1; |
||||
if (mProp_AllowParameters.boolValue) mask |= 1 << 2; |
||||
if (mProp_AllowLocalizedParameters.boolValue) mask |= 1 << 3; |
||||
if (mProp_SeparateWords.boolValue) mask |= 1 << 4; |
||||
if (mProp_IgnoreRTL.boolValue) mask |= 1 << 5; |
||||
|
||||
EditorGUI.BeginChangeCheck(); |
||||
mask = EditorGUILayout.MaskField(new GUIContent("Options"), mask, new []{ |
||||
"Localize On Awake", |
||||
"Force Localize", |
||||
"Allow Parameters", |
||||
"Allow Localized Parameters", |
||||
"Separate Words", |
||||
"Ignore RTL" |
||||
}); |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
mProp_LocalizeOnAwake.boolValue = (mask & (1 << 0))> 0; |
||||
mProp_AlwaysForceLocalize.boolValue = (mask & (1 << 1))> 0; |
||||
mProp_AllowParameters.boolValue = (mask & (1 << 2))> 0; |
||||
mProp_AllowLocalizedParameters.boolValue = (mask & (1 << 3))> 0; |
||||
mProp_SeparateWords.boolValue = (mask & (1 << 4))> 0; |
||||
mProp_IgnoreRTL.boolValue = (mask & (1 << 5))> 0; |
||||
} |
||||
} |
||||
|
||||
TermData OnGUI_PrimaryTerm( bool OnOpen ) |
||||
{ |
||||
string Key = mLocalize.mTerm; |
||||
if (string.IsNullOrEmpty(Key)) |
||||
{ |
||||
string SecondaryTerm; |
||||
mLocalize.GetFinalTerms( out Key, out SecondaryTerm ); |
||||
} |
||||
|
||||
if (OnOpen) mNewKeyName = Key; |
||||
if ( OnGUI_SelectKey( ref Key, string.IsNullOrEmpty(mLocalize.mTerm))) |
||||
mProp_mTerm.stringValue = Key; |
||||
return LocalizationEditor.OnGUI_Keys_Languages( Key, mLocalize ); |
||||
} |
||||
|
||||
TermData OnGUI_SecondaryTerm( bool OnOpen ) |
||||
{ |
||||
string Key = mLocalize.mTermSecondary; |
||||
|
||||
if (string.IsNullOrEmpty(Key)) |
||||
{ |
||||
string ss; |
||||
mLocalize.GetFinalTerms( out ss, out Key ); |
||||
} |
||||
|
||||
if (OnOpen) mNewKeyName = Key; |
||||
if ( OnGUI_SelectKey( ref Key, string.IsNullOrEmpty(mLocalize.mTermSecondary))) |
||||
mProp_mTermSecondary.stringValue = Key; |
||||
return LocalizationEditor.OnGUI_Keys_Languages( Key, mLocalize, false ); |
||||
} |
||||
|
||||
bool OnGUI_SelectKey( ref string Term, bool Inherited ) // Inherited==true means that the mTerm is empty and we are using the Label.text instead |
||||
{ |
||||
GUILayout.Space (5); |
||||
GUILayout.BeginHorizontal(); |
||||
|
||||
GUI.changed = false; |
||||
mAllowEditKeyName = GUILayout.Toggle(mAllowEditKeyName, "Term:", EditorStyles.foldout, GUILayout.ExpandWidth(false)); |
||||
if (GUI.changed && mAllowEditKeyName) { |
||||
mNewKeyName = Term; |
||||
mTermsArray = null; |
||||
} |
||||
|
||||
bool bChanged = false; |
||||
|
||||
if (mTermsArray==null || Term!="-" && Array.IndexOf(mTermsArray, Term)<0) |
||||
UpdateTermsList(Term); |
||||
|
||||
if (Inherited) |
||||
GUI.contentColor = Color.Lerp (Color.gray, Color.yellow, 0.1f); |
||||
|
||||
int Index = Term=="-" || Term=="" ? mTermsArray.Length-1 : Array.IndexOf( mTermsArray, Term ); |
||||
|
||||
GUI.changed = false; |
||||
|
||||
int newIndex = EditorGUILayout.Popup( Index, mTermsArray); |
||||
|
||||
GUI.contentColor = Color.white; |
||||
if (/*newIndex != Index && newIndex>=0*/GUI.changed) |
||||
{ |
||||
GUI.changed = false; |
||||
if (mLocalize.Source != null && newIndex == mTermsArray.Length - 4) //< show terms from all sources > |
||||
{ |
||||
mLocalize.Source = null; |
||||
mTermsArray = null; |
||||
} |
||||
else |
||||
if (newIndex == mTermsArray.Length - 2) //<inferred from text> |
||||
mNewKeyName = Term = string.Empty; |
||||
else |
||||
if (newIndex == mTermsArray.Length - 1) //<none> |
||||
mNewKeyName = Term = "-"; |
||||
else |
||||
mNewKeyName = Term = mTermsArray[newIndex]; |
||||
|
||||
|
||||
if (GUI_SelectedTerm==0) |
||||
mLocalize.SetTerm (mNewKeyName); |
||||
else |
||||
mLocalize.SetTerm (null, mNewKeyName); |
||||
mAllowEditKeyName = false; |
||||
bChanged = true; |
||||
} |
||||
|
||||
LanguageSourceData source = LocalizationManager.GetSourceContaining(Term); |
||||
TermData termData = source.GetTermData(Term); |
||||
if (termData!=null) |
||||
{ |
||||
if (Inherited) |
||||
bChanged = true; // if the term its inferred and a matching term its found, then use that |
||||
eTermType NewType = (eTermType)EditorGUILayout.EnumPopup(termData.TermType, GUILayout.Width(90)); |
||||
if (termData.TermType != NewType) |
||||
termData.TermType = NewType; |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
|
||||
if (mAllowEditKeyName) |
||||
{ |
||||
GUILayout.BeginHorizontal(GUILayout.Height (1)); |
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
if(mNewKeyName==null) mNewKeyName = string.Empty; |
||||
|
||||
GUI.changed = false; |
||||
mNewKeyName = EditorGUILayout.TextField(mNewKeyName, new GUIStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true)); |
||||
if (GUI.changed) |
||||
{ |
||||
mTermsArray = null; // regenerate this array to apply filtering |
||||
GUI.changed = false; |
||||
} |
||||
|
||||
if (GUILayout.Button (string.Empty, string.IsNullOrEmpty(mNewKeyName) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth(false))) |
||||
{ |
||||
mTermsArray = null; // regenerate this array to apply filtering |
||||
mNewKeyName = string.Empty; |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
|
||||
string ValidatedName = mNewKeyName; |
||||
LanguageSourceData.ValidateFullTerm( ref ValidatedName ); |
||||
|
||||
bool CanUseNewName = source.GetTermData(ValidatedName)==null; |
||||
GUI.enabled = !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName; |
||||
if (GUILayout.Button ("Create", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
mNewKeyName = ValidatedName; |
||||
mTermsArray=null; // this recreates that terms array |
||||
|
||||
LanguageSourceData Source = null; |
||||
#if UNITY_EDITOR |
||||
if (mLocalize.Source!=null) |
||||
Source = mLocalize.Source.SourceData; |
||||
#endif |
||||
|
||||
if (Source==null) |
||||
Source = LocalizationManager.Sources[0]; |
||||
Term = mNewKeyName; |
||||
var data = Source.AddTerm( mNewKeyName, eTermType.Text, false ); |
||||
if (data.Languages.Length > 0) |
||||
data.Languages[0] = mLocalize.GetMainTargetsText(); |
||||
Source.Editor_SetDirty(); |
||||
AssetDatabase.SaveAssets(); |
||||
mAllowEditKeyName = false; |
||||
bChanged = true; |
||||
GUIUtility.keyboardControl = 0; |
||||
} |
||||
GUI.enabled = termData!=null && !string.IsNullOrEmpty(mNewKeyName) && CanUseNewName; |
||||
if (GUILayout.Button (new GUIContent("Rename","Renames the term in the source and updates every object using it in the current scene"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
mNewKeyName = ValidatedName; |
||||
Term = mNewKeyName; |
||||
mTermsArray=null; // this recreates that terms array |
||||
mAllowEditKeyName = false; |
||||
bChanged = true; |
||||
LocalizationEditor.TermReplacements = new Dictionary<string, string>(StringComparer.Ordinal); |
||||
LocalizationEditor.TermReplacements[ termData.Term ] = mNewKeyName; |
||||
termData.Term = mNewKeyName; |
||||
source.UpdateDictionary(true); |
||||
LocalizationEditor.ReplaceTermsInCurrentScene(); |
||||
GUIUtility.keyboardControl = 0; |
||||
EditorApplication.update += LocalizationEditor.DoParseTermsInCurrentScene; |
||||
} |
||||
GUI.enabled = true; |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
bChanged |= OnGUI_SelectKey_PreviewTerms ( ref Term); |
||||
} |
||||
|
||||
GUILayout.Space (5); |
||||
return bChanged; |
||||
} |
||||
|
||||
void UpdateTermsList( string currentTerm ) |
||||
{ |
||||
List<string> Terms = mLocalize.Source==null ? LocalizationManager.GetTermsList() : mLocalize.Source.SourceData.GetTermsList(); |
||||
|
||||
// If there is a filter, remove all terms not matching that filter |
||||
if (mAllowEditKeyName && !string.IsNullOrEmpty(mNewKeyName)) |
||||
{ |
||||
string Filter = mNewKeyName.ToUpper(); |
||||
for (int i=Terms.Count-1; i>=0; --i) |
||||
if (!Terms[i].ToUpper().Contains(Filter) && Terms[i]!=currentTerm) |
||||
Terms.RemoveAt(i); |
||||
|
||||
} |
||||
|
||||
if (!string.IsNullOrEmpty(currentTerm) && currentTerm!="-" && !Terms.Contains(currentTerm)) |
||||
Terms.Add (currentTerm); |
||||
|
||||
Terms.Sort(StringComparer.OrdinalIgnoreCase); |
||||
Terms.Add(""); |
||||
if (mLocalize.Source != null) |
||||
{ |
||||
Terms.Add("< Show Terms from all sources >"); |
||||
Terms.Add(""); |
||||
} |
||||
Terms.Add("<inferred from text>"); |
||||
Terms.Add("<none>"); |
||||
|
||||
mTermsArray = Terms.ToArray(); |
||||
} |
||||
|
||||
bool OnGUI_SelectKey_PreviewTerms ( ref string Term) |
||||
{ |
||||
if (mTermsArray==null) |
||||
UpdateTermsList(Term); |
||||
|
||||
int nTerms = mTermsArray.Length; |
||||
if (nTerms<=0) |
||||
return false; |
||||
|
||||
if (nTerms==1 && mTermsArray[0]==Term) |
||||
return false; |
||||
|
||||
bool bChanged = false; |
||||
GUI.backgroundColor = Color.gray; |
||||
GUILayout.BeginVertical (GUIStyle_OldTextArea); |
||||
for (int i = 0, imax = Mathf.Min (nTerms, 3); i < imax; ++i) |
||||
{ |
||||
ParsedTerm parsedTerm; |
||||
int nUses = -1; |
||||
if (LocalizationEditor.mParsedTerms.TryGetValue (mTermsArray [i], out parsedTerm)) |
||||
nUses = parsedTerm.Usage; |
||||
|
||||
string FoundText = mTermsArray [i]; |
||||
if (nUses > 0) |
||||
FoundText = string.Concat ("(", nUses, ") ", FoundText); |
||||
|
||||
if (GUILayout.Button (FoundText, EditorStyles.miniLabel, GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth - 70))) |
||||
{ |
||||
if (mTermsArray[i] == "<inferred from text>") |
||||
mNewKeyName = Term = string.Empty; |
||||
else |
||||
if (mTermsArray[i] == "<none>") |
||||
mNewKeyName = Term = "-"; |
||||
else |
||||
if (mTermsArray[i] != "< Show Terms from all sources >") |
||||
mNewKeyName = Term = mTermsArray[i]; |
||||
|
||||
//mNewKeyName = Term = (mTermsArray [i]=="<inferred from text>" ? string.Empty : mTermsArray [i]); |
||||
GUIUtility.keyboardControl = 0; |
||||
mAllowEditKeyName = false; |
||||
bChanged = true; |
||||
} |
||||
} |
||||
if (nTerms > 3) |
||||
GUILayout.Label ("..."); |
||||
GUILayout.EndVertical (); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
return bChanged; |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Target |
||||
|
||||
void OnGUI_Target() |
||||
{ |
||||
List<string> TargetTypes = new List<string>(); |
||||
int CurrentTarget = -1; |
||||
|
||||
mLocalize.FindTarget(); |
||||
|
||||
foreach (var desc in LocalizationManager.mLocalizeTargets) |
||||
{ |
||||
if (desc.CanLocalize(mLocalize)) |
||||
{ |
||||
TargetTypes.Add(desc.Name); |
||||
|
||||
if (mLocalize.mLocalizeTarget!=null && desc.GetTargetType() == mLocalize.mLocalizeTarget.GetType()) |
||||
CurrentTarget = TargetTypes.Count - 1; |
||||
} |
||||
} |
||||
|
||||
if (CurrentTarget==-1) |
||||
{ |
||||
CurrentTarget = TargetTypes.Count; |
||||
TargetTypes.Add("None"); |
||||
} |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label ("Target:", GUILayout.Width (60)); |
||||
EditorGUI.BeginChangeCheck(); |
||||
int index = EditorGUILayout.Popup(CurrentTarget, TargetTypes.ToArray()); |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
serializedObject.ApplyModifiedProperties(); |
||||
foreach (var obj in serializedObject.targetObjects) |
||||
{ |
||||
var cmp = obj as Localize; |
||||
if (cmp == null) |
||||
continue; |
||||
|
||||
if (cmp.mLocalizeTarget != null) |
||||
DestroyImmediate(cmp.mLocalizeTarget); |
||||
cmp.mLocalizeTarget = null; |
||||
|
||||
foreach (var desc in LocalizationManager.mLocalizeTargets) |
||||
{ |
||||
if (desc.Name == TargetTypes[index]) |
||||
{ |
||||
cmp.mLocalizeTarget = desc.CreateTarget(cmp); |
||||
cmp.mLocalizeTargetName = desc.GetTargetType().ToString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
serializedObject.Update(); |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Source |
||||
|
||||
void OnGUI_Source() |
||||
{ |
||||
GUILayout.BeginHorizontal(); |
||||
|
||||
ILanguageSource currentSource = mLocalize.Source; |
||||
if (currentSource==null) |
||||
{ |
||||
LanguageSourceData source = LocalizationManager.GetSourceContaining(mLocalize.Term); |
||||
currentSource = source==null ? null : source.owner; |
||||
} |
||||
|
||||
if (GUILayout.Button("Open Source", EditorStyles.toolbarButton, GUILayout.Width (100))) |
||||
{ |
||||
Selection.activeObject = currentSource as Object; |
||||
|
||||
string sTerm, sSecondary; |
||||
mLocalize.GetFinalTerms( out sTerm, out sSecondary ); |
||||
if (GUI_SelectedTerm==1) sTerm = sSecondary; |
||||
LocalizationEditor.mKeyToExplore = sTerm; |
||||
} |
||||
|
||||
GUILayout.Space (2); |
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
EditorGUI.BeginChangeCheck (); |
||||
if (mLocalize.Source == null) |
||||
{ |
||||
GUI.contentColor = Color.Lerp (Color.gray, Color.yellow, 0.1f); |
||||
} |
||||
Object obj = EditorGUILayout.ObjectField(currentSource as Object, typeof(Object), true); |
||||
GUI.contentColor = Color.white; |
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
ILanguageSource NewSource = obj as ILanguageSource; |
||||
if (NewSource == null && obj as GameObject != null) |
||||
{ |
||||
NewSource = (obj as GameObject).GetComponent<LanguageSource>(); |
||||
} |
||||
|
||||
mLocalize.Source = NewSource; |
||||
string sTerm, sSecondary; |
||||
mLocalize.GetFinalTerms(out sTerm, out sSecondary); |
||||
if (GUI_SelectedTerm == 1) sTerm = sSecondary; |
||||
UpdateTermsList(sTerm); |
||||
} |
||||
|
||||
if (GUILayout.Button(new GUIContent("Detect", "Finds the LanguageSource containing the selected term, the term list will now only show terms inside that source."), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
string sTerm, sSecondary; |
||||
mLocalize.GetFinalTerms(out sTerm, out sSecondary); |
||||
if (GUI_SelectedTerm == 1) sTerm = sSecondary; |
||||
|
||||
var data = LocalizationManager.GetSourceContaining(sTerm, false); |
||||
mLocalize.Source = data==null ? null : data.owner; |
||||
mTermsArray = null; |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
|
||||
#region Event CallBack |
||||
|
||||
//public void DrawEventCallBack( EventCallback CallBack, Localize loc ) |
||||
//{ |
||||
//if (CallBack==null) |
||||
// return; |
||||
|
||||
//GUI.changed = false; |
||||
|
||||
//GUILayout.BeginHorizontal(); |
||||
//GUILayout.Label("Target:", GUILayout.ExpandWidth(false)); |
||||
//CallBack.Target = EditorGUILayout.ObjectField( CallBack.Target, typeof(MonoBehaviour), true) as MonoBehaviour; |
||||
//GUILayout.EndHorizontal(); |
||||
|
||||
//if (CallBack.Target!=null) |
||||
//{ |
||||
// GameObject GO = CallBack.Target.gameObject; |
||||
// List<MethodInfo> Infos = new List<MethodInfo>(); |
||||
|
||||
// var targets = GO.GetComponents(typeof(MonoBehaviour)); |
||||
// foreach (var behavior in targets) |
||||
// Infos.AddRange( behavior.GetType().GetMethods() ); |
||||
|
||||
// List<string> Methods = new List<string>(); |
||||
|
||||
// for (int i = 0, imax=Infos.Count; i<imax; ++i) |
||||
// { |
||||
// MethodInfo mi = Infos[i]; |
||||
|
||||
// if (IsValidMethod(mi)) |
||||
// Methods.Add (mi.Name); |
||||
// } |
||||
|
||||
// int Index = Methods.IndexOf(CallBack.MethodName); |
||||
|
||||
// int NewIndex = EditorGUILayout.Popup(Index, Methods.ToArray(), GUILayout.ExpandWidth(true)); |
||||
// if (NewIndex!=Index) |
||||
// CallBack.MethodName = Methods[ NewIndex ]; |
||||
//} |
||||
//if (GUI.changed) |
||||
//{ |
||||
// GUI.changed = false; |
||||
// EditorUtility.SetDirty(loc); |
||||
// //UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty() EditorApplication.MakeSceneDirty(); |
||||
//} |
||||
//} |
||||
|
||||
static bool IsValidMethod( MethodInfo mi ) |
||||
{ |
||||
if (mi.DeclaringType == typeof(MonoBehaviour) || mi.ReturnType != typeof(void)) |
||||
return false; |
||||
|
||||
ParameterInfo[] Params = mi.GetParameters (); |
||||
if (Params.Length == 0) return true; |
||||
if (Params.Length > 1) return false; |
||||
|
||||
if (Params [0].ParameterType.IsSubclassOf (typeof(Object))) return true; |
||||
if (Params [0].ParameterType == typeof(Object)) return true; |
||||
return false; |
||||
} |
||||
|
||||
|
||||
#endregion |
||||
|
||||
#region Styles |
||||
|
||||
public static GUIStyle GUIStyle_Header { |
||||
get{ |
||||
if (mGUIStyle_Header==null) |
||||
{ |
||||
mGUIStyle_Header = new GUIStyle("HeaderLabel"); |
||||
mGUIStyle_Header.fontSize = 25; |
||||
mGUIStyle_Header.normal.textColor = Color.Lerp(Color.white, Color.gray, 0.5f); |
||||
mGUIStyle_Header.fontStyle = FontStyle.BoldAndItalic; |
||||
mGUIStyle_Header.alignment = TextAnchor.UpperCenter; |
||||
} |
||||
return mGUIStyle_Header; |
||||
} |
||||
} |
||||
static GUIStyle mGUIStyle_Header; |
||||
|
||||
public static GUIStyle GUIStyle_SubHeader { |
||||
get{ |
||||
if (mGUIStyle_SubHeader==null) |
||||
{ |
||||
mGUIStyle_SubHeader = new GUIStyle("HeaderLabel"); |
||||
mGUIStyle_SubHeader.fontSize = 13; |
||||
mGUIStyle_SubHeader.fontStyle = FontStyle.Normal; |
||||
mGUIStyle_SubHeader.margin.top = -50; |
||||
mGUIStyle_SubHeader.alignment = TextAnchor.UpperCenter; |
||||
} |
||||
return mGUIStyle_SubHeader; |
||||
} |
||||
} |
||||
static GUIStyle mGUIStyle_SubHeader; |
||||
|
||||
public static GUIStyle GUIStyle_Background { |
||||
get{ |
||||
if (mGUIStyle_Background==null) |
||||
{ |
||||
mGUIStyle_Background = new GUIStyle(EditorStyles.textArea); |
||||
mGUIStyle_Background.fixedHeight = 0; |
||||
mGUIStyle_Background.overflow.left = 50; |
||||
mGUIStyle_Background.overflow.right = 50; |
||||
mGUIStyle_Background.overflow.top = -5; |
||||
mGUIStyle_Background.overflow.bottom = 0; |
||||
} |
||||
return mGUIStyle_Background; |
||||
} |
||||
} |
||||
static GUIStyle mGUIStyle_Background; |
||||
|
||||
public static GUIStyle GUIStyle_OldTextArea |
||||
{ |
||||
get |
||||
{ |
||||
if (mGUIStyle_OldTextArea == null) |
||||
{ |
||||
mGUIStyle_OldTextArea = new GUIStyle(EditorStyles.textArea); |
||||
mGUIStyle_OldTextArea.fixedHeight = 0; |
||||
} |
||||
return mGUIStyle_OldTextArea; |
||||
} |
||||
} |
||||
static GUIStyle mGUIStyle_OldTextArea; |
||||
|
||||
#endregion |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 675119279b2a30245801272112cfbe38 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: ba2fdf8face79dd4f9e1ed80448db843 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 7af58b4da44670e47a509c59754e8c2b |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,164 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
[CustomPropertyDrawer (typeof (TermsPopup))] |
||||
public class TermsPopup_Drawer : PropertyDrawer |
||||
{ |
||||
GUIContent[] mTerms_Context; |
||||
int nFramesLeftBeforeUpdate; |
||||
string mPrevFilter; |
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
||||
{ |
||||
var filter = ((TermsPopup)attribute).Filter; |
||||
ShowGUICached(position, property, label, null, filter, ref mTerms_Context, ref nFramesLeftBeforeUpdate, ref mPrevFilter); |
||||
} |
||||
|
||||
public static bool ShowGUI(Rect position, SerializedProperty property, GUIContent label, LanguageSourceData source, string filter = "") |
||||
{ |
||||
GUIContent[] terms=null; |
||||
int framesLeftBeforeUpdate=0; |
||||
string prevFilter = null; |
||||
|
||||
return ShowGUICached(position, property, label, source, filter, ref terms, ref framesLeftBeforeUpdate, ref prevFilter); |
||||
} |
||||
|
||||
public static bool ShowGUICached(Rect position, SerializedProperty property, GUIContent label, LanguageSourceData source, string filter, ref GUIContent[] terms_Contexts, ref int framesBeforeUpdating, ref string prevFilter) |
||||
{ |
||||
UpdateTermsCache(source, filter, ref terms_Contexts, ref framesBeforeUpdating, ref prevFilter); |
||||
|
||||
label = EditorGUI.BeginProperty(position, label, property); |
||||
|
||||
EditorGUI.BeginChangeCheck (); |
||||
|
||||
var index = property.stringValue == "-" || property.stringValue == "" ? terms_Contexts.Length - 1 : |
||||
property.stringValue == " " ? terms_Contexts.Length - 2 : |
||||
GetTermIndex(terms_Contexts, property.stringValue); |
||||
var newIndex = EditorGUI.Popup(position, label, index, terms_Contexts); |
||||
|
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
property.stringValue = newIndex < 0 || newIndex == terms_Contexts.Length - 1 ? string.Empty : terms_Contexts[newIndex].text; |
||||
if (newIndex == terms_Contexts.Length - 1) |
||||
property.stringValue = "-"; |
||||
else |
||||
if (newIndex < 0 || newIndex == terms_Contexts.Length - 2) |
||||
property.stringValue = string.Empty; |
||||
else |
||||
property.stringValue = terms_Contexts[newIndex].text; |
||||
|
||||
EditorGUI.EndProperty(); |
||||
return true; |
||||
} |
||||
|
||||
EditorGUI.EndProperty(); |
||||
return false; |
||||
} |
||||
|
||||
static int GetTermIndex(GUIContent[] terms_Contexts, string term ) |
||||
{ |
||||
for (int i = 0; i < terms_Contexts.Length; ++i) |
||||
if (terms_Contexts[i].text == term) |
||||
return i; |
||||
return -1; |
||||
} |
||||
|
||||
|
||||
static void UpdateTermsCache(LanguageSourceData source, string filter, ref GUIContent[] terms_Contexts, ref int framesBeforeUpdating, ref string prevFilter) |
||||
{ |
||||
framesBeforeUpdating--; |
||||
if (terms_Contexts!=null && framesBeforeUpdating>0 && filter==prevFilter) |
||||
{ |
||||
return; |
||||
} |
||||
framesBeforeUpdating = 60; |
||||
prevFilter = filter; |
||||
|
||||
var Terms = source == null ? LocalizationManager.GetTermsList() : source.GetTermsList(); |
||||
|
||||
if (string.IsNullOrEmpty(filter) == false) |
||||
{ |
||||
Terms = Filter(Terms, filter); |
||||
} |
||||
|
||||
Terms.Sort(StringComparer.OrdinalIgnoreCase); |
||||
Terms.Add(""); |
||||
Terms.Add("<inferred from text>"); |
||||
Terms.Add("<none>"); |
||||
|
||||
terms_Contexts = DisplayOptions(Terms); |
||||
} |
||||
|
||||
private static List<string> Filter(List<string> terms, string filter) |
||||
{ |
||||
var filtered = new List<string>(); |
||||
for (var i = 0; i < terms.Count; i++) |
||||
{ |
||||
var term = terms[i]; |
||||
if (term.Contains(filter)) |
||||
{ |
||||
filtered.Add(term); |
||||
} |
||||
} |
||||
|
||||
return filtered; |
||||
} |
||||
|
||||
private static GUIContent[] DisplayOptions(IList<string> terms) |
||||
{ |
||||
var options = new GUIContent[terms.Count]; |
||||
for (var i = 0; i < terms.Count; i++) |
||||
{ |
||||
options[i] = new GUIContent(terms[i]); |
||||
} |
||||
|
||||
return options; |
||||
} |
||||
} |
||||
|
||||
[CustomPropertyDrawer(typeof(LocalizedString))] |
||||
public class LocalizedStringDrawer : PropertyDrawer |
||||
{ |
||||
GUIContent[] mTerms_Context; |
||||
int nFramesLeftBeforeUpdate; |
||||
string mPrevFilter; |
||||
|
||||
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) |
||||
{ |
||||
var termRect = rect; termRect.xMax -= 50; |
||||
var termProp = property.FindPropertyRelative("mTerm"); |
||||
TermsPopup_Drawer.ShowGUICached(termRect, termProp, label, null, "", ref mTerms_Context, ref nFramesLeftBeforeUpdate, ref mPrevFilter); |
||||
|
||||
var maskRect = rect; maskRect.xMin = maskRect.xMax - 30; |
||||
var termIgnoreRTL = property.FindPropertyRelative("mRTL_IgnoreArabicFix"); |
||||
var termConvertNumbers = property.FindPropertyRelative("mRTL_ConvertNumbers"); |
||||
var termDontLocalizeParams = property.FindPropertyRelative("m_DontLocalizeParameters"); |
||||
int mask = (termIgnoreRTL.boolValue ? 0 : 1) + |
||||
(termConvertNumbers.boolValue ? 0 : 2) + |
||||
(termDontLocalizeParams.boolValue ? 0 : 4); |
||||
|
||||
int newMask = EditorGUI.MaskField(maskRect, mask, new[] { "Arabic Fix", "Ignore Numbers in RTL", "Localize Parameters" }); |
||||
if (newMask != mask) |
||||
{ |
||||
termIgnoreRTL.boolValue = (newMask & 1) == 0; |
||||
termConvertNumbers.boolValue = (newMask & 2) == 0; |
||||
termDontLocalizeParams.boolValue = (newMask & 4) == 0; |
||||
} |
||||
|
||||
var showRect = rect; showRect.xMin = termRect.xMax; showRect.xMax=maskRect.xMin; |
||||
bool enabled = GUI.enabled; |
||||
GUI.enabled = enabled & (!string.IsNullOrEmpty (termProp.stringValue) && termProp.stringValue!="-"); |
||||
if (GUI.Button (showRect, "?")) |
||||
{ |
||||
var source = LocalizationManager.GetSourceContaining(termProp.stringValue); |
||||
LocalizationEditor.mKeyToExplore = termProp.stringValue; |
||||
Selection.activeObject = source.ownerObject; |
||||
} |
||||
GUI.enabled = enabled; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 51c22a426b92fa84cb6ca7b75176da8a |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,9 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 8ad136296e8e6e14eaa2726ac1992b6c |
||||
folderAsset: yes |
||||
timeCreated: 1461137613 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: ffd53aaaf6936407d8b087583b0626e9 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,477 @@ |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public partial class LocalizationEditor |
||||
{ |
||||
#region Variables |
||||
private List<string> mTranslationTerms = new List<string>(); |
||||
private Dictionary<string, TranslationQuery> mTranslationRequests = new Dictionary<string, TranslationQuery> (); |
||||
private bool mAppNameTerm_Expanded; |
||||
|
||||
private List<string> mLanguageCodePopupList; |
||||
|
||||
#endregion |
||||
|
||||
void OnGUI_Languages() |
||||
{ |
||||
//GUILayout.Space(5); |
||||
|
||||
OnGUI_ShowMsg(); |
||||
|
||||
OnGUI_LanguageList(); |
||||
|
||||
OnGUI_StoreIntegration(); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label(new GUIContent("On Missing Translation:", "What should happen IN-GAME when a term is not yet translated to the current language?"), EditorStyles.boldLabel, GUILayout.Width(200)); |
||||
GUILayout.BeginVertical(); |
||||
GUILayout.Space(7); |
||||
EditorGUILayout.PropertyField(mProp_OnMissingTranslation, GUITools.EmptyContent, GUILayout.Width(165)); |
||||
GUILayout.EndVertical(); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label(new GUIContent("Unload Languages At Runtime:", "When playing the game, the plugin will unload all unused languages and only load them when needed"), EditorStyles.boldLabel, GUILayout.Width(200)); |
||||
GUILayout.BeginVertical(); |
||||
GUILayout.Space(7); |
||||
EditorGUILayout.PropertyField(mProp_AllowUnloadingLanguages, GUITools.EmptyContent, GUILayout.Width(165)); |
||||
GUILayout.EndVertical(); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
|
||||
|
||||
|
||||
string firstLanguage = ""; |
||||
if (mLanguageSource.mLanguages.Count > 0) |
||||
firstLanguage = " (" + mLanguageSource.mLanguages [0].Name + ")"; |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label(new GUIContent("Default Language:", "When the game starts this is the language that will be used until the player manually selects a language"), EditorStyles.boldLabel, GUILayout.Width(160)); |
||||
GUILayout.BeginVertical(); |
||||
GUILayout.Space(7); |
||||
|
||||
mProp_IgnoreDeviceLanguage.boolValue = EditorGUILayout.Popup(mProp_IgnoreDeviceLanguage.boolValue?1:0, new[]{"Device Language", "First in List"+firstLanguage}, GUILayout.ExpandWidth(true))==1; |
||||
GUILayout.EndVertical(); |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
#region GUI Languages |
||||
|
||||
void OnGUI_LanguageList() |
||||
{ |
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
GUILayout.FlexibleSpace(); |
||||
GUILayout.Label ("Languages:", EditorStyles.miniLabel, GUILayout.ExpandWidth(false)); |
||||
GUILayout.FlexibleSpace(); |
||||
GUILayout.Label ("Code:", EditorStyles.miniLabel); |
||||
GUILayout.Space(170); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
//--[ Language List ]-------------------------- |
||||
|
||||
int IndexLanguageToDelete = -1; |
||||
int LanguageToMoveUp = -1; |
||||
int LanguageToMoveDown = -1; |
||||
GUI.backgroundColor = Color.Lerp(GUITools.LightGray, Color.white, 0.5f); |
||||
mScrollPos_Languages = GUILayout.BeginScrollView( mScrollPos_Languages, LocalizeInspector.GUIStyle_OldTextArea, GUILayout.MinHeight (200), /*GUILayout.MaxHeight(Screen.height),*/ GUILayout.ExpandHeight(false)); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
if (mLanguageCodePopupList == null || mLanguageCodePopupList.Count==0) |
||||
{ |
||||
mLanguageCodePopupList = GoogleLanguages.GetLanguagesForDropdown("", ""); |
||||
mLanguageCodePopupList.Sort(); |
||||
mLanguageCodePopupList.Insert(0, string.Empty); |
||||
} |
||||
|
||||
for (int i=0, imax=mProp_Languages.arraySize; i<imax; ++i) |
||||
{ |
||||
SerializedProperty Prop_Lang = mProp_Languages.GetArrayElementAtIndex(i); |
||||
SerializedProperty Prop_LangName = Prop_Lang.FindPropertyRelative("Name"); |
||||
SerializedProperty Prop_LangCode = Prop_Lang.FindPropertyRelative("Code"); |
||||
SerializedProperty Prop_Flags = Prop_Lang.FindPropertyRelative("Flags"); |
||||
bool isLanguageEnabled = (Prop_Flags.intValue & (int)eLanguageDataFlags.DISABLED)==0; |
||||
|
||||
GUI.color = isLanguageEnabled ? Color.white : new Color(1, 1, 1, 0.3f); |
||||
GUILayout.BeginHorizontal(); |
||||
|
||||
if (GUILayout.Button ("X", "toolbarbutton", GUILayout.ExpandWidth(false))) |
||||
{ |
||||
IndexLanguageToDelete = i; |
||||
} |
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
|
||||
EditorGUI.BeginChangeCheck(); |
||||
string LanName = EditorGUILayout.TextField(Prop_LangName.stringValue, GUILayout.ExpandWidth(true)); |
||||
if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(LanName)) |
||||
{ |
||||
Prop_LangName.stringValue = LanName; |
||||
} |
||||
|
||||
var currentCode = "[" + Prop_LangCode.stringValue + "]"; |
||||
|
||||
if (isLanguageEnabled) |
||||
{ |
||||
int Index = Mathf.Max(0, mLanguageCodePopupList.FindIndex(c => c.Contains(currentCode))); |
||||
EditorGUI.BeginChangeCheck(); |
||||
Index = EditorGUILayout.Popup(Index, mLanguageCodePopupList.ToArray(), EditorStyles.toolbarPopup, GUILayout.Width(60)); |
||||
if (EditorGUI.EndChangeCheck() && Index >= 0) |
||||
{ |
||||
currentCode = mLanguageCodePopupList[Index]; |
||||
int i0 = currentCode.IndexOf("["); |
||||
int i1 = currentCode.IndexOf("]"); |
||||
if (i0 >= 0 && i1 > i0) |
||||
Prop_LangCode.stringValue = currentCode.Substring(i0 + 1, i1 - i0 - 1); |
||||
else |
||||
Prop_LangCode.stringValue = string.Empty; |
||||
} |
||||
var rect = GUILayoutUtility.GetLastRect(); |
||||
GUI.Label(rect, Prop_LangCode.stringValue, EditorStyles.toolbarPopup); |
||||
} |
||||
else |
||||
{ |
||||
GUILayout.Label(Prop_LangCode.stringValue, EditorStyles.toolbarPopup, GUILayout.Width(60)); |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUI.enabled = i<imax-1; |
||||
if (GUILayout.Button( "\u25BC", EditorStyles.toolbarButton, GUILayout.Width(18))) LanguageToMoveDown = i; |
||||
GUI.enabled = i>0; |
||||
if (GUILayout.Button( "\u25B2", EditorStyles.toolbarButton, GUILayout.Width(18))) LanguageToMoveUp = i; |
||||
|
||||
GUI.enabled = true; |
||||
if (GUILayout.Button( new GUIContent("Show", "Preview all localizations into this language"), EditorStyles.toolbarButton, GUILayout.Width(35))) |
||||
{ |
||||
LocalizationManager.SetLanguageAndCode( LanName, Prop_LangCode.stringValue, false, true); |
||||
} |
||||
|
||||
if (TestButtonArg( eTest_ActionType.Button_Languages_TranslateAll, i, new GUIContent("Translate", "Translate all empty terms"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
GUITools.DelayedCall( () => TranslateAllToLanguage(LanName)); |
||||
} |
||||
GUI.enabled = true; |
||||
GUI.color = Color.white; |
||||
|
||||
EditorGUI.BeginChangeCheck(); |
||||
isLanguageEnabled = EditorGUILayout.Toggle(isLanguageEnabled, GUILayout.Width(15)); |
||||
|
||||
var r = GUILayoutUtility.GetLastRect(); |
||||
GUI.Label(r, new GUIContent("", "Enable/Disable the language.\nDisabled languages can be used to store data values or to avoid showing Languages that are stil under development")); |
||||
|
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
Prop_Flags.intValue = (Prop_Flags.intValue & ~(int)eLanguageDataFlags.DISABLED) | (isLanguageEnabled ? 0 : (int)eLanguageDataFlags.DISABLED); |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
GUILayout.EndScrollView(); |
||||
|
||||
OnGUI_AddLanguage( mProp_Languages ); |
||||
|
||||
if (mConnection_WWW!=null || mConnection_Text.Contains("Translating")) |
||||
{ |
||||
// Connection Status Bar |
||||
int time = (int)(Time.realtimeSinceStartup % 2 * 2.5); |
||||
string Loading = mConnection_Text + ".....".Substring(0, time); |
||||
GUI.color = Color.gray; |
||||
GUILayout.BeginHorizontal(LocalizeInspector.GUIStyle_OldTextArea); |
||||
GUILayout.Label (Loading, EditorStyles.miniLabel); |
||||
GUI.color = Color.white; |
||||
if (GUILayout.Button("Cancel", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
GoogleTranslation.CancelCurrentGoogleTranslations (); |
||||
StopConnectionWWW(); |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
Repaint(); |
||||
} |
||||
|
||||
if (IndexLanguageToDelete>=0) |
||||
{ |
||||
if (EditorUtility.DisplayDialog ("Confirm delete", "Are you sure you want to delete the selected language", "Yes", "Cancel")) |
||||
{ |
||||
mLanguageSource.RemoveLanguage (mLanguageSource.mLanguages [IndexLanguageToDelete].Name); |
||||
serializedObject.Update (); |
||||
ParseTerms (true, false, false); |
||||
} |
||||
} |
||||
|
||||
if (LanguageToMoveUp>=0) SwapLanguages( LanguageToMoveUp, LanguageToMoveUp-1 ); |
||||
if (LanguageToMoveDown>=0) SwapLanguages( LanguageToMoveDown, LanguageToMoveDown+1 ); |
||||
} |
||||
|
||||
void SwapLanguages( int iFirst, int iSecond ) |
||||
{ |
||||
serializedObject.ApplyModifiedProperties(); |
||||
LanguageSourceData Source = mLanguageSource; |
||||
|
||||
SwapValues( Source.mLanguages, iFirst, iSecond ); |
||||
foreach (TermData termData in Source.mTerms) |
||||
{ |
||||
SwapValues ( termData.Languages, iFirst, iSecond ); |
||||
SwapValues ( termData.Flags, iFirst, iSecond ); |
||||
} |
||||
serializedObject.Update(); |
||||
} |
||||
|
||||
void SwapValues( List<LanguageData> mList, int Index1, int Index2 ) |
||||
{ |
||||
LanguageData temp = mList[Index1]; |
||||
mList[Index1] = mList[Index2]; |
||||
mList[Index2] = temp; |
||||
} |
||||
void SwapValues( string[] mList, int Index1, int Index2 ) |
||||
{ |
||||
string temp = mList[Index1]; |
||||
mList[Index1] = mList[Index2]; |
||||
mList[Index2] = temp; |
||||
} |
||||
void SwapValues( byte[] mList, int Index1, int Index2 ) |
||||
{ |
||||
byte temp = mList[Index1]; |
||||
mList[Index1] = mList[Index2]; |
||||
mList[Index2] = temp; |
||||
} |
||||
|
||||
|
||||
void OnGUI_AddLanguage( SerializedProperty Prop_Languages) |
||||
{ |
||||
//--[ Add Language Upper Toolbar ]----------------- |
||||
|
||||
GUILayout.BeginVertical(); |
||||
GUILayout.BeginHorizontal(); |
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
mLanguages_NewLanguage = EditorGUILayout.TextField("", mLanguages_NewLanguage, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true)); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUI.enabled = !string.IsNullOrEmpty (mLanguages_NewLanguage); |
||||
if (TestButton(eTest_ActionType.Button_AddLanguageManual,"Add", EditorStyles.toolbarButton, GUILayout.Width(50))) |
||||
{ |
||||
Prop_Languages.serializedObject.ApplyModifiedProperties(); |
||||
mLanguageSource.AddLanguage( mLanguages_NewLanguage, GoogleLanguages.GetLanguageCode(mLanguages_NewLanguage) ); |
||||
Prop_Languages.serializedObject.Update(); |
||||
mLanguages_NewLanguage = ""; |
||||
GUI.FocusControl(string.Empty); |
||||
} |
||||
GUI.enabled = true; |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
|
||||
|
||||
//--[ Add Language Bottom Toolbar ]----------------- |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
|
||||
//-- Language Dropdown ----------------- |
||||
string CodesToExclude = string.Empty; |
||||
foreach (var LanData in mLanguageSource.mLanguages) |
||||
CodesToExclude = string.Concat(CodesToExclude, "[", LanData.Code, "]"); |
||||
|
||||
List<string> Languages = GoogleLanguages.GetLanguagesForDropdown(mLanguages_NewLanguage, CodesToExclude); |
||||
|
||||
GUI.changed = false; |
||||
int index = EditorGUILayout.Popup(0, Languages.ToArray(), EditorStyles.toolbarDropDown); |
||||
|
||||
if (GUI.changed && index>=0) |
||||
{ |
||||
mLanguages_NewLanguage = GoogleLanguages.GetFormatedLanguageName( Languages[index] ); |
||||
} |
||||
|
||||
|
||||
if (TestButton(eTest_ActionType.Button_AddLanguageFromPopup, "Add", EditorStyles.toolbarButton, GUILayout.Width(50)) && index>=0) |
||||
{ |
||||
Prop_Languages.serializedObject.ApplyModifiedProperties(); |
||||
mLanguages_NewLanguage = GoogleLanguages.GetFormatedLanguageName(Languages[index]); |
||||
|
||||
if (!string.IsNullOrEmpty(mLanguages_NewLanguage)) |
||||
mLanguageSource.AddLanguage(mLanguages_NewLanguage, GoogleLanguages.GetLanguageCode(mLanguages_NewLanguage)); |
||||
Prop_Languages.serializedObject.Update(); |
||||
|
||||
mLanguages_NewLanguage = ""; |
||||
GUI.FocusControl(string.Empty); |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
GUILayout.EndVertical(); |
||||
GUI.color = Color.white; |
||||
} |
||||
|
||||
|
||||
void TranslateAllToLanguage (string lanName) |
||||
{ |
||||
if (!GoogleTranslation.CanTranslate ()) |
||||
{ |
||||
ShowError ("WebService is not set correctly or needs to be reinstalled"); |
||||
return; |
||||
} |
||||
ClearErrors(); |
||||
int LanIndex = mLanguageSource.GetLanguageIndex (lanName); |
||||
string code = mLanguageSource.mLanguages [LanIndex].Code; |
||||
string googleCode = GoogleLanguages.GetGoogleLanguageCode(code); |
||||
if (string.IsNullOrEmpty(googleCode)) |
||||
{ |
||||
ShowError("Language '" + code + "' is not supported by google translate"); |
||||
return; |
||||
} |
||||
googleCode = code; |
||||
|
||||
mTranslationTerms.Clear (); |
||||
mTranslationRequests.Clear (); |
||||
foreach (var termData in mLanguageSource.mTerms) |
||||
{ |
||||
if (termData.TermType != eTermType.Text) |
||||
continue; |
||||
|
||||
if (!string.IsNullOrEmpty(termData.Languages[LanIndex])) |
||||
continue; |
||||
|
||||
string sourceCode, sourceText; |
||||
FindTranslationSource( LanguageSourceData.GetKeyFromFullTerm(termData.Term), termData, code, null, out sourceText, out sourceCode ); |
||||
|
||||
mTranslationTerms.Add (termData.Term); |
||||
|
||||
GoogleTranslation.CreateQueries(sourceText, sourceCode, googleCode, mTranslationRequests); // can split plurals into several queries |
||||
} |
||||
|
||||
if (mTranslationRequests.Count == 0) |
||||
{ |
||||
StopConnectionWWW (); |
||||
return; |
||||
} |
||||
|
||||
mConnection_WWW = null; |
||||
mConnection_Text = "Translating"; if (mTranslationRequests.Count > 1) mConnection_Text += " (" + mTranslationRequests.Count + ")"; |
||||
mConnection_Callback = null; |
||||
//EditorApplication.update += CheckForConnection; |
||||
|
||||
GoogleTranslation.Translate (mTranslationRequests, OnLanguageTranslated); |
||||
} |
||||
|
||||
void OnLanguageTranslated( Dictionary<string, TranslationQuery> requests, string Error ) |
||||
{ |
||||
//Debug.Log (Result); |
||||
|
||||
//if (Result.Contains("Service invoked too many times")) |
||||
//{ |
||||
// TimeStartTranslation = EditorApplication.timeSinceStartup + 1; |
||||
// EditorApplication.update += DelayedStartTranslation; |
||||
// mConnection_Text = "Translating (" + mTranslationRequests.Count + ")"; |
||||
// return; |
||||
//} |
||||
|
||||
//if (!string.IsNullOrEmpty(Error))/* || !Result.Contains("<i2>")*/ |
||||
//{ |
||||
// Debug.LogError("WEB ERROR: " + Error); |
||||
// ShowError ("Unable to access Google or not valid request"); |
||||
// return; |
||||
//} |
||||
|
||||
ClearErrors(); |
||||
StopConnectionWWW(); |
||||
|
||||
if (!string.IsNullOrEmpty(Error)) |
||||
{ |
||||
ShowError (Error); |
||||
return; |
||||
} |
||||
|
||||
if (requests.Values.Count == 0) |
||||
return; |
||||
|
||||
var langCode = requests.Values.First().TargetLanguagesCode [0]; |
||||
//langCode = GoogleLanguages.GetGoogleLanguageCode(langCode); |
||||
int langIndex = mLanguageSource.GetLanguageIndexFromCode (langCode, false); |
||||
//if (langIndex >= 0) |
||||
{ |
||||
foreach (var term in mTranslationTerms) |
||||
{ |
||||
var termData = mLanguageSource.GetTermData(term); |
||||
if (termData == null) |
||||
continue; |
||||
if (termData.TermType != eTermType.Text) |
||||
continue; |
||||
//if (termData.Languages.Length <= langIndex) |
||||
// continue; |
||||
|
||||
string sourceCode, sourceText; |
||||
FindTranslationSource(LanguageSourceData.GetKeyFromFullTerm(termData.Term), termData, langCode, null, out sourceText, out sourceCode); |
||||
|
||||
string result = GoogleTranslation.RebuildTranslation(sourceText, mTranslationRequests, langCode); // gets the result from google and rebuilds the text from multiple queries if its is plurals |
||||
|
||||
termData.Languages[langIndex] = result; |
||||
} |
||||
} |
||||
|
||||
mTranslationTerms.Clear (); |
||||
mTranslationRequests.Clear (); |
||||
StopConnectionWWW (); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Store Integration |
||||
|
||||
void OnGUI_StoreIntegration() |
||||
{ |
||||
GUIStyle lstyle = new GUIStyle (EditorStyles.label); |
||||
lstyle.richText = true; |
||||
|
||||
GUILayout.BeginHorizontal (); |
||||
GUILayout.Label (new GUIContent("Store Integration:", "Setups the stores to detect that the game has localization, Android adds strings.xml for each language. IOS modifies the Info.plist"), EditorStyles.boldLabel, GUILayout.Width(160)); |
||||
GUILayout.FlexibleSpace(); |
||||
|
||||
GUILayout.Label( new GUIContent( "<color=green><size=16>\u2713</size></color> IOS", "Setups the stores to show in iTunes and the Appstore all the languages that this app supports, also localizes the app name if available" ), lstyle, GUILayout.Width( 90 ) ); |
||||
GUILayout.Label( new GUIContent( "<color=green><size=16>\u2713</size></color> Android", "Setups the stores to show in GooglePlay all the languages this app supports, also localizes the app name if available" ), lstyle, GUILayout.Width( 90 ) ); |
||||
GUILayout.EndHorizontal (); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
mAppNameTerm_Expanded = GUILayout.Toggle(mAppNameTerm_Expanded, new GUIContent( "App Name translations:", "How should the game be named in the devices based on their language" ), EditorStyles.foldout, GUILayout.Width( 160 ) ); |
||||
|
||||
GUILayout.Label("", GUILayout.ExpandWidth(true)); |
||||
var rect = GUILayoutUtility.GetLastRect(); |
||||
TermsPopup_Drawer.ShowGUI( rect, mProp_AppNameTerm, GUITools.EmptyContent, mLanguageSource); |
||||
|
||||
if (GUILayout.Button("New Term", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
AddLocalTerm("App_Name"); |
||||
mProp_AppNameTerm.stringValue = "App_Name"; |
||||
mAppNameTerm_Expanded = true; |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
if (mAppNameTerm_Expanded) |
||||
{ |
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Space(10); |
||||
|
||||
GUILayout.BeginVertical("Box"); |
||||
var termName = mProp_AppNameTerm.stringValue; |
||||
if (!string.IsNullOrEmpty(termName)) |
||||
{ |
||||
var termData = LocalizationManager.GetTermData(termName); |
||||
if (termData != null) |
||||
OnGUI_Keys_Languages(mProp_AppNameTerm.stringValue, ref termData, null, true, mLanguageSource); |
||||
} |
||||
GUILayout.Space(10); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.Label("<b>Default App Name:</b>", lstyle, GUITools.DontExpandWidth); |
||||
GUILayout.Label(Application.productName); |
||||
GUILayout.EndHorizontal(); |
||||
GUILayout.EndVertical(); |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
} |
||||
|
||||
#endregion |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 304783c1e95d94a598aecd17728c8556 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 800caf7e364ec2947be099b4f9ed976d |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: fdca66efafe784661b464934cacff065 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,820 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public partial class LocalizationEditor |
||||
{ |
||||
#region Variables |
||||
|
||||
Vector2 mScrollPos_Keys = Vector2.zero; |
||||
|
||||
public static string mKeyToExplore; // Key that should show all the language details |
||||
static string KeyList_Filter = ""; |
||||
float mRowSize=-1; |
||||
float ScrollHeight; |
||||
float mTermList_MaxWidth = -1; |
||||
|
||||
public static List<string> mSelectedKeys = new List<string>(); // Selected Keys in the list of mParsedKeys |
||||
public static List<string> mSelectedCategories = new List<string>(); |
||||
|
||||
|
||||
public enum eFlagsViewKeys |
||||
{ |
||||
Used = 1<<1, |
||||
Missing = 1<<2, |
||||
NotUsed = 1<<3 |
||||
} |
||||
public static int mFlagsViewKeys = (int)eFlagsViewKeys.Used | (int)eFlagsViewKeys.NotUsed; |
||||
|
||||
public static string mTermsList_NewTerm; |
||||
Rect mKeyListFilterRect; |
||||
|
||||
#endregion |
||||
|
||||
#region GUI Key List |
||||
|
||||
float ExpandedViewHeight; |
||||
float TermsListHeight; |
||||
|
||||
void OnGUI_KeysList(bool AllowExpandKey = true, float Height = 300.0f, bool ShowTools=true) |
||||
{ |
||||
///if (mTermList_MaxWidth<=0) |
||||
CalculateTermsListMaxWidth(); |
||||
|
||||
//--[ List Filters ]-------------------------------------- |
||||
|
||||
// The ID of this control is registered here to avoid losing focus when the terms list grows in the scrollbox |
||||
// This control is drawn later on |
||||
int KeyListFilterID = GUIUtility.GetControlID( FocusType.Keyboard ); |
||||
|
||||
OnGUI_ShowMsg(); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUIStyle bstyle = new GUIStyle ("toolbarbutton"); |
||||
bstyle.fontSize = 15; |
||||
if (GUILayout.Button (new GUIContent("\u21bb", "Parse Scene and update terms list with missing and unused terms"), bstyle, GUILayout.Width(25))) |
||||
EditorApplication.update += DoParseTermsInCurrentSceneAndScripts; |
||||
if (GUILayout.Button(new GUIContent("\u21ea", "Refresh the translation of all Localize objects"), bstyle, GUILayout.Width(25))) |
||||
CallLocalizeAll(); |
||||
|
||||
GUILayout.Space (1); |
||||
|
||||
var oldFlags = mFlagsViewKeys; |
||||
mFlagsViewKeys = OnGUI_FlagToogle("Used","Shows All Terms referenced in the parsed scenes", mFlagsViewKeys, (int)eFlagsViewKeys.Used); |
||||
mFlagsViewKeys = OnGUI_FlagToogle("Not Used", "Shows all Terms from the Source that are not been used", mFlagsViewKeys, (int)eFlagsViewKeys.NotUsed); |
||||
mFlagsViewKeys = OnGUI_FlagToogle("Missing","Shows all Terms Used but not defined in the Source", mFlagsViewKeys, (int)eFlagsViewKeys.Missing); |
||||
if (oldFlags!=mFlagsViewKeys) |
||||
ScheduleUpdateTermsToShowInList(); |
||||
|
||||
OnGUI_SelectedCategories(); |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
|
||||
/*//if (Event.current.type == EventType.Repaint) |
||||
TermsListHeight = Screen.height - 400; |
||||
Debug.Log(Event.current.type + " " + TermsListHeight + " " + Screen.height + " " + GUILayoutUtility.GetLastRect().yMax); |
||||
|
||||
//TermsListHeight = Mathf.Min(Screen.height*0.5f, TermsListHeight); |
||||
mScrollPos_Keys = GUILayout.BeginScrollView(mScrollPos_Keys, false, false, "horizontalScrollbar", "verticalScrollbar", LocalizeInspector.GUIStyle_OldTextArea, GUILayout.Height(TermsListHeight)); |
||||
for (int i = 0; i < 1000; ++i) |
||||
GUILayout.Label("ahhh" + i); |
||||
GUILayout.EndScrollView(); |
||||
|
||||
return;*/ |
||||
TermsListHeight = Mathf.Min(Screen.height*0.5f, TermsListHeight); |
||||
|
||||
//--[ Keys List ]----------------------------------------- |
||||
GUI.backgroundColor = Color.Lerp(GUITools.LightGray, Color.white, 0.5f); |
||||
mScrollPos_Keys = GUILayout.BeginScrollView( mScrollPos_Keys, false, false, "horizontalScrollbar", "verticalScrollbar", LocalizeInspector.GUIStyle_OldTextArea ,GUILayout.Height(TermsListHeight)/*GUILayout.MinHeight(Height), GUILayout.MaxHeight(Screen.height), GUILayout.ExpandHeight(true)*/); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
bool bAnyValidUsage = false; |
||||
|
||||
mRowSize = EditorStyles.toolbar.fixedHeight; |
||||
if (Event.current!=null && Event.current.type == EventType.Layout) |
||||
ScrollHeight = mScrollPos_Keys.y; |
||||
|
||||
float YPosMin = -ScrollHeight; |
||||
int nSkip = 0; |
||||
int nDraw = 0; |
||||
|
||||
if (mShowableTerms.Count == 0 && Event.current.type == EventType.Layout) |
||||
UpdateTermsToShownInList (); |
||||
|
||||
float SkipSize = 0; |
||||
foreach (var parsedTerm in mShowableTerms) |
||||
{ |
||||
string sKey = parsedTerm.Term; |
||||
string sCategory = parsedTerm.Category; |
||||
string FullKey = parsedTerm.FullTerm; |
||||
|
||||
int nUses = parsedTerm.Usage; |
||||
bAnyValidUsage = bAnyValidUsage | (nUses>=0); |
||||
|
||||
ShowTerm_termData = parsedTerm.termData; |
||||
|
||||
// Skip lines outside the view ----------------------- |
||||
YPosMin += mRowSize; |
||||
SkipSize += mRowSize; |
||||
float YPosMax = YPosMin + mRowSize; |
||||
bool isExpanded = AllowExpandKey && mKeyToExplore==FullKey; |
||||
if (!isExpanded && (YPosMax<-2*mRowSize || YPosMin>/*Screen.height*/TermsListHeight+mRowSize)) |
||||
{ |
||||
if (YPosMin>TermsListHeight+mRowSize) |
||||
break; |
||||
|
||||
nSkip++; |
||||
continue; |
||||
} |
||||
nDraw++; |
||||
|
||||
//------------------------------------------------------ |
||||
|
||||
OnGUI_KeyHeader (sKey, sCategory, FullKey, nUses, YPosMin-mRowSize+mScrollPos_Keys.y); |
||||
|
||||
//--[ Key Details ]------------------------------- |
||||
|
||||
if (isExpanded) |
||||
{ |
||||
GUILayout.Space(SkipSize); |
||||
SkipSize = 0; |
||||
OnGUI_KeyList_ShowKeyDetails(); |
||||
Rect rect = GUILayoutUtility.GetLastRect(); |
||||
if (rect.height>5) |
||||
ExpandedViewHeight = rect.height; |
||||
YPosMin += ExpandedViewHeight; |
||||
} |
||||
} |
||||
SkipSize += (mShowableTerms.Count - nDraw-nSkip) * mRowSize; |
||||
GUILayout.Space(SkipSize+2); |
||||
if (mSelectedCategories.Count < mParsedCategories.Count) |
||||
{ |
||||
SkipSize += 25; |
||||
if (GUILayout.Button ("...", EditorStyles.label)) |
||||
{ |
||||
mSelectedCategories.Clear (); |
||||
mSelectedCategories.AddRange (mParsedCategories); |
||||
} |
||||
} |
||||
OnGUI_KeysList_AddKey(); |
||||
|
||||
GUILayout.Label("", GUILayout.Width(mTermList_MaxWidth+10+30), GUILayout.Height(1)); |
||||
|
||||
GUILayout.EndScrollView(); |
||||
|
||||
TermsListHeight = YPosMin + mRowSize + 25;//SkipSize+25; |
||||
|
||||
//Rect ListRect = GUILayoutUtility.GetLastRect(); |
||||
//if (ListRect.height>5) |
||||
// TermsListHeight = ListRect.height; |
||||
//Debug.Log(nDraw + " " + nSkip + " " + Screen.height + " " + TermsListHeight); |
||||
|
||||
OnGUI_Keys_ListSelection( KeyListFilterID ); // Selection Buttons |
||||
|
||||
// if (!bAnyValidUsage) |
||||
// EditorGUILayout.HelpBox("Use (Tools\\Parse Terms) to find how many times each of the Terms are used", UnityEditor.MessageType.Info); |
||||
|
||||
if (ShowTools) |
||||
{ |
||||
GUILayout.BeginHorizontal(); |
||||
GUI.enabled = mSelectedKeys.Count>0 || !string.IsNullOrEmpty(mKeyToExplore); |
||||
if (TestButton (eTest_ActionType.Button_AddSelectedTerms, new GUIContent("Add Terms", "Add terms to Source"), "Button", GUITools.DontExpandWidth)) AddTermsToSource(); |
||||
if (TestButton (eTest_ActionType.Button_RemoveSelectedTerms, new GUIContent("Remove Terms", "Remove Terms from Source"), "Button", GUITools.DontExpandWidth)) RemoveTermsFromSource(); |
||||
|
||||
GUILayout.FlexibleSpace (); |
||||
|
||||
if (GUILayout.Button ("Change Category")) OpenTool_ChangeCategoryOfSelectedTerms(); |
||||
GUI.enabled = true; |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.FlexibleSpace (); |
||||
bool newBool = GUILayout.Toggle(mLanguageSource.CaseInsensitiveTerms, "Case Insensitive Terms"); |
||||
if (newBool != mLanguageSource.CaseInsensitiveTerms) |
||||
{ |
||||
mProp_CaseInsensitiveTerms.boolValue = newBool; |
||||
} |
||||
GUILayout.FlexibleSpace (); |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
//Debug.Log ("Draw: " + nDraw + " Skip: " + nSkip); |
||||
} |
||||
|
||||
static void ScheduleUpdateTermsToShowInList() |
||||
{ |
||||
if (!mUpdateShowTermIsScheduled) |
||||
{ |
||||
EditorApplication.update += UpdateTermsToShownInList; |
||||
mUpdateShowTermIsScheduled = true; |
||||
} |
||||
} |
||||
static bool mUpdateShowTermIsScheduled; |
||||
static void UpdateTermsToShownInList() |
||||
{ |
||||
EditorApplication.update -= UpdateTermsToShownInList; |
||||
mUpdateShowTermIsScheduled = false; |
||||
|
||||
mShowableTerms.Clear (); |
||||
mSelectedCategories.Sort(); |
||||
foreach (KeyValuePair<string, ParsedTerm> kvp in mParsedTerms) |
||||
{ |
||||
ParsedTerm parsedTerm = kvp.Value; |
||||
if (ShouldShowTerm (parsedTerm.Term, parsedTerm.Category, parsedTerm.Usage, parsedTerm)) |
||||
mShowableTerms.Add(parsedTerm); |
||||
} |
||||
GUITools.RepaintInspectors(); |
||||
GUITools.ScheduleRepaintInspectors(); |
||||
} |
||||
|
||||
void OnGUI_KeyHeader (string sKey, string sCategory, string FullKey, int nUses, float YPosMin) |
||||
{ |
||||
//--[ Toggle ]--------------------- |
||||
GUI.Box(new Rect(2, YPosMin+2, 18, mRowSize), "", "Toolbar"); |
||||
OnGUI_SelectableToogleListItem (new Rect(2, YPosMin+3, 15, mRowSize), FullKey, ref mSelectedKeys, "OL Toggle"); |
||||
|
||||
bool bEnabled = mSelectedKeys.Contains (FullKey); |
||||
//--[ Number of Objects using this key ]--------------------- |
||||
if (nUses >= 0) |
||||
{ |
||||
if (nUses == 0) |
||||
{ |
||||
GUI.color = Color.Lerp (Color.gray, Color.white, 0.5f); |
||||
GUI.Label (new Rect(20, YPosMin+2, 30, mRowSize), nUses.ToString (), "toolbarbutton"); |
||||
} |
||||
else |
||||
{ |
||||
if (GUI.Button(new Rect(20, YPosMin + 2, 30, mRowSize), nUses.ToString(), "toolbarbutton")) |
||||
{ |
||||
List<string> selection = new List<string>(mSelectedKeys); |
||||
if (!selection.Contains(FullKey)) |
||||
selection.Add(FullKey); |
||||
|
||||
List<GameObject> selGOs = new List<GameObject>(); |
||||
for (int i=0; i<selection.Count; ++i) |
||||
selGOs.AddRange( FindObjectsUsingKey(selection[i]) ); |
||||
|
||||
|
||||
if (selGOs.Count > 0) |
||||
Selection.objects = selGOs.ToArray(); |
||||
else |
||||
ShowWarning("The selected Terms are not used in this Scene. Try opening other scenes"); |
||||
} |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
GUI.color = Color.Lerp (Color.red, Color.white, 0.6f); |
||||
if (GUI.Button (new Rect(20, YPosMin+2, 30, mRowSize), "", "toolbarbutton")) |
||||
{ |
||||
mCurrentToolsMode = eToolsMode.Parse; |
||||
mCurrentViewMode = eViewMode.Tools; |
||||
} |
||||
} |
||||
GUI.color = Color.white; |
||||
|
||||
TermData termData = ShowTerm_termData!=null ? ShowTerm_termData : mLanguageSource.GetTermData (FullKey); |
||||
bool bKeyIsMissing = termData == null; |
||||
float MinX = 50; |
||||
if (bKeyIsMissing) |
||||
{ |
||||
Rect rect = new Rect(50, YPosMin+2, mRowSize, mRowSize+2); |
||||
GUITools.DrawSkinIcon(rect, "CN EntryWarnIcon", "CN EntryWarn"); |
||||
GUI.Label (rect, new GUIContent ("", "This term is used in the scene, but its not localized in the Language Source")); |
||||
MinX += rect.width; |
||||
} |
||||
else MinX += 3; |
||||
|
||||
float listWidth = Mathf.Max(EditorGUIUtility.currentViewWidth / EditorGUIUtility.pixelsPerPoint, mTermList_MaxWidth); |
||||
Rect rectKey = new Rect(MinX, YPosMin+2, listWidth-MinX, mRowSize); |
||||
if (sCategory != LanguageSourceData.EmptyCategory) |
||||
rectKey.width -= 130; |
||||
if (mKeyToExplore == FullKey) |
||||
{ |
||||
GUI.backgroundColor = Color.Lerp (Color.blue, Color.white, 0.8f); |
||||
if (GUI.Button (rectKey, new GUIContent (sKey, EditorStyles.foldout.onNormal.background), LocalizeInspector.GUIStyle_OldTextArea)) |
||||
{ |
||||
mKeyToExplore = string.Empty; |
||||
ScheduleUpdateTermsToShowInList(); |
||||
ClearErrors (); |
||||
} |
||||
GUI.backgroundColor = Color.white; |
||||
} |
||||
else |
||||
{ |
||||
GUIStyle LabelStyle = EditorStyles.label; |
||||
if (!bKeyIsMissing && !TermHasAllTranslations (mLanguageSource, termData)) |
||||
{ |
||||
LabelStyle = new GUIStyle (EditorStyles.label); |
||||
LabelStyle.fontStyle = FontStyle.Italic; |
||||
GUI.color = Color.Lerp (Color.white, Color.yellow, 0.5f); |
||||
} |
||||
if (!bEnabled) |
||||
GUI.contentColor = Color.Lerp (Color.gray, Color.white, 0.3f); |
||||
if (GUI.Button (rectKey, sKey, LabelStyle)) |
||||
{ |
||||
SelectTerm (FullKey); |
||||
ClearErrors (); |
||||
} |
||||
if (!bEnabled) |
||||
GUI.contentColor = Color.white; |
||||
GUI.color = Color.white; |
||||
} |
||||
//--[ Category ]-------------------------- |
||||
if (sCategory != LanguageSourceData.EmptyCategory) |
||||
{ |
||||
if (mKeyToExplore == FullKey) |
||||
{ |
||||
rectKey.x = listWidth - 100-38-20; |
||||
rectKey.width = 130; |
||||
if (GUI.Button (rectKey, sCategory, EditorStyles.toolbarButton)) |
||||
OpenTool_ChangeCategoryOfSelectedTerms (); |
||||
} |
||||
else |
||||
{ |
||||
GUIStyle stl = new GUIStyle(EditorStyles.miniLabel); |
||||
stl.alignment = TextAnchor.MiddleRight; |
||||
rectKey.width = 130;//EditorStyles.miniLabel.CalcSize(new GUIContent(sCategory)).x; |
||||
rectKey.x = listWidth - rectKey.width - 38-20; |
||||
|
||||
if (GUI.Button (rectKey, sCategory, stl)) |
||||
{ |
||||
SelectTerm (FullKey); |
||||
ClearErrors (); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void CalculateTermsListMaxWidth() |
||||
{ |
||||
mTermList_MaxWidth = EditorGUIUtility.currentViewWidth / EditorGUIUtility.pixelsPerPoint - 120; |
||||
/*float maxWidth = Screen.width / 18; |
||||
foreach (KeyValuePair<string, ParsedTerm> kvp in mParsedTerms) |
||||
{ |
||||
var txt = kvp.Key; |
||||
if (txt.Length > 100) |
||||
txt = txt.Substring(0, 100); |
||||
var size = EditorStyles.label.CalcSize(new GUIContent(txt)); |
||||
mTermList_MaxWidth = Mathf.Max (mTermList_MaxWidth, size.x); |
||||
}*/ |
||||
} |
||||
|
||||
bool TermHasAllTranslations( LanguageSourceData source, TermData data ) |
||||
{ |
||||
if (source==null) source = LocalizationManager.Sources[0]; |
||||
for (int i=0, imax=data.Languages.Length; i<imax; ++i) |
||||
{ |
||||
bool isLangEnabled = source.mLanguages.Count>i ? source.mLanguages[i].IsEnabled() : true; |
||||
if (string.IsNullOrEmpty(data.Languages[i]) && isLangEnabled) |
||||
return false; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void OnGUI_KeysList_AddKey() |
||||
{ |
||||
GUILayout.BeginHorizontal(); |
||||
GUI.color = Color.Lerp(Color.gray, Color.white, 0.5f); |
||||
bool bWasEnabled = mTermsList_NewTerm!=null; |
||||
bool bEnabled = !GUILayout.Toggle (!bWasEnabled, "+", EditorStyles.toolbarButton, GUILayout.Width(30)); |
||||
GUI.color = Color.white; |
||||
|
||||
if (bWasEnabled && !bEnabled) mTermsList_NewTerm = null; |
||||
if (!bWasEnabled && bEnabled) mTermsList_NewTerm = string.Empty; |
||||
|
||||
if (bEnabled) |
||||
{ |
||||
GUILayout.BeginHorizontal(EditorStyles.toolbar); |
||||
mTermsList_NewTerm = EditorGUILayout.TextField(mTermsList_NewTerm, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true)); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
LanguageSourceData.ValidateFullTerm( ref mTermsList_NewTerm ); |
||||
if (string.IsNullOrEmpty(mTermsList_NewTerm) || mLanguageSource.ContainsTerm(mTermsList_NewTerm) || mTermsList_NewTerm=="-") |
||||
GUI.enabled = false; |
||||
|
||||
if (TestButton (eTest_ActionType.Button_AddTerm_InTermsList, "Create Key", "toolbarbutton", GUILayout.ExpandWidth(false))) |
||||
{ |
||||
AddLocalTerm(mTermsList_NewTerm); |
||||
SelectTerm( mTermsList_NewTerm ); |
||||
ClearErrors(); |
||||
mTermsList_NewTerm = null; |
||||
SetAllTerms_When_InferredTerms_IsInSource (); |
||||
} |
||||
GUI.enabled = true; |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
void OpenTool_ChangeCategoryOfSelectedTerms() |
||||
{ |
||||
mCurrentViewMode = eViewMode.Tools; |
||||
mCurrentToolsMode = eToolsMode.Categorize; |
||||
if (!string.IsNullOrEmpty(mKeyToExplore) && !mSelectedKeys.Contains(mKeyToExplore)) |
||||
mSelectedKeys.Add(mKeyToExplore); |
||||
mSelectedKeys.Sort(); |
||||
} |
||||
|
||||
void OnGUI_SelectedCategories() |
||||
{ |
||||
if (mParsedCategories.Count == 0) |
||||
return; |
||||
|
||||
string text = "Categories"; |
||||
if (mSelectedCategories.Count() == 0) |
||||
text = "Nothing"; |
||||
else |
||||
if (mSelectedCategories.Count() == mParsedCategories.Count) |
||||
text = "Everything"; |
||||
else |
||||
text = mSelectedCategories.Count + " categories"; |
||||
|
||||
if (GUILayout.Button(new GUIContent(text), "toolbarbutton", GUILayout.Width(100))) |
||||
{ |
||||
var menu = new GenericMenu(); |
||||
|
||||
menu.AddItem(new GUIContent("Everything"), false, () => |
||||
{ |
||||
mSelectedCategories.Clear(); |
||||
mSelectedCategories.AddRange(mParsedCategories); |
||||
ScheduleUpdateTermsToShowInList(); |
||||
}); |
||||
menu.AddItem(new GUIContent("Nothing"), false, () => |
||||
{ |
||||
mSelectedCategories.Clear(); |
||||
ScheduleUpdateTermsToShowInList(); |
||||
}); |
||||
menu.AddSeparator(""); |
||||
|
||||
var parsedList = mParsedCategories.OrderBy(x=>x).ToList(); |
||||
for (int i=0, imax=parsedList.Count; i<imax ; ++i) |
||||
{ |
||||
var category = parsedList[i]; |
||||
var nextCategory = i + 1 < imax ? parsedList[i + 1] : null; |
||||
|
||||
bool isHeader = nextCategory != null && nextCategory.StartsWith(category + "/"); |
||||
|
||||
var displayName = category; |
||||
var categoryRoot = category; |
||||
if (isHeader) |
||||
{ |
||||
categoryRoot += "/"; |
||||
var newCateg = !category.Contains('/') ? category : category.Substring(category.LastIndexOf('/') + 1); |
||||
displayName = categoryRoot + newCateg; |
||||
} |
||||
|
||||
menu.AddItem(new GUIContent(displayName), !string.IsNullOrEmpty(mSelectedCategories.FirstOrDefault(x=>x.StartsWith(categoryRoot))), () => |
||||
{ |
||||
var CatHeader = category + "/"; |
||||
if (mSelectedCategories.Contains(category)) |
||||
{ |
||||
mSelectedCategories.Remove(category); |
||||
|
||||
if (isHeader) |
||||
{ |
||||
mSelectedCategories.RemoveAll(x => x.StartsWith(CatHeader)); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
mSelectedCategories.Add(category); |
||||
if (isHeader) |
||||
{ |
||||
mSelectedCategories.AddRange( parsedList.Where(x=>x.StartsWith(CatHeader))); |
||||
} |
||||
} |
||||
ScheduleUpdateTermsToShowInList(); |
||||
}); |
||||
if (isHeader) |
||||
{ |
||||
menu.AddSeparator(category+"/"); |
||||
} |
||||
} |
||||
|
||||
menu.ShowAsContext(); |
||||
} |
||||
} |
||||
|
||||
void SaveSelectedCategories() |
||||
{ |
||||
if (mSelectedCategories.Count == 0) { |
||||
EditorPrefs.DeleteKey ("I2 CategoryFilter"); |
||||
} else { |
||||
var data = string.Join(",", mSelectedCategories.ToArray()); |
||||
EditorPrefs.SetString ("I2 CategoryFilter", data); |
||||
} |
||||
} |
||||
|
||||
void LoadSelectedCategories() |
||||
{ |
||||
var data = EditorPrefs.GetString ("I2 CategoryFilter", null); |
||||
if (!string.IsNullOrEmpty(data)) |
||||
{ |
||||
mSelectedCategories.Clear (); |
||||
mSelectedCategories.AddRange( data.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); |
||||
} |
||||
} |
||||
|
||||
|
||||
// Bottom part of the Key list (buttons: All, None, Used,... to select the keys) |
||||
void OnGUI_Keys_ListSelection ( int KeyListFilterID ) |
||||
{ |
||||
GUILayout.BeginHorizontal( "toolbarbutton" ); |
||||
|
||||
if (TestButton( eTest_ActionType.Button_SelectTerms_All, new GUIContent( "All", "Selects All Terms in the list" ), "toolbarbutton", GUILayout.ExpandWidth( false ) )) |
||||
{ |
||||
mSelectedKeys.Clear(); |
||||
foreach (var kvp in mParsedTerms) |
||||
if (ShouldShowTerm( kvp.Value.Term, kvp.Value.Category, kvp.Value.Usage )) |
||||
mSelectedKeys.Add( kvp.Key ); |
||||
} |
||||
if (GUILayout.Button( new GUIContent( "None", "Clears the selection" ), "toolbarbutton", GUILayout.ExpandWidth( false ) )) { mSelectedKeys.Clear(); } |
||||
GUILayout.Space( 5 ); |
||||
|
||||
GUI.enabled = (mFlagsViewKeys & (int)eFlagsViewKeys.Used)>1; |
||||
if (TestButton(eTest_ActionType.Button_SelectTerms_Used, new GUIContent( "Used", "Selects All Terms referenced in the parsed scenes" ), "toolbarbutton", GUILayout.ExpandWidth( false ) )) |
||||
{ |
||||
mSelectedKeys.Clear(); |
||||
foreach (var kvp in mParsedTerms) |
||||
if (kvp.Value.Usage > 0 && ShouldShowTerm( kvp.Value.Term, kvp.Value.Category, kvp.Value.Usage )) |
||||
mSelectedKeys.Add( kvp.Key ); |
||||
} |
||||
GUI.enabled = (mFlagsViewKeys & (int)eFlagsViewKeys.NotUsed)>1; |
||||
if (GUILayout.Button( new GUIContent( "Not Used", "Selects all Terms from the Source that are not been used" ), "toolbarbutton", GUILayout.ExpandWidth( false ) )) |
||||
{ |
||||
mSelectedKeys.Clear(); |
||||
foreach (var kvp in mParsedTerms) |
||||
if (kvp.Value.Usage == 0 && ShouldShowTerm( kvp.Value.Term, kvp.Value.Category, kvp.Value.Usage )) |
||||
mSelectedKeys.Add( kvp.Key ); |
||||
} |
||||
|
||||
GUI.enabled = (mFlagsViewKeys & (int)eFlagsViewKeys.Missing)>1; |
||||
if (TestButton(eTest_ActionType.Button_SelectTerms_Missing, new GUIContent( "Missing", "Selects all Terms Used but not defined in the Source" ), "toolbarbutton", GUILayout.ExpandWidth( false ) )) |
||||
{ |
||||
mSelectedKeys.Clear(); |
||||
foreach (var kvp in mParsedTerms) |
||||
if (!mLanguageSource.ContainsTerm( kvp.Key ) && ShouldShowTerm( kvp.Value.Term, kvp.Value.Category, kvp.Value.Usage )) |
||||
mSelectedKeys.Add( kvp.Key ); |
||||
} |
||||
GUI.enabled = true; |
||||
EditorGUI.BeginChangeCheck(); |
||||
|
||||
// Terms Filter |
||||
{ |
||||
//KeyList_Filter = EditorGUILayout.TextField(KeyList_Filter, GUI.skin.GetStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true)); |
||||
GUILayout.Label( "", GUILayout.ExpandWidth( true ) ); |
||||
mKeyListFilterRect = GUILayoutUtility.GetLastRect(); |
||||
mKeyListFilterRect.xMax += 4; |
||||
|
||||
KeyList_Filter = GUITools.TextField( mKeyListFilterRect, KeyList_Filter, 255, GUI.skin.GetStyle( "ToolbarSeachTextField" ), KeyListFilterID ); |
||||
} |
||||
|
||||
|
||||
|
||||
if (GUILayout.Button( string.Empty, string.IsNullOrEmpty( KeyList_Filter ) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton", GUILayout.ExpandWidth( false ) )) |
||||
{ |
||||
KeyList_Filter = string.Empty; |
||||
EditorApplication.update += RepaintScene; |
||||
GUI.FocusControl( "" ); |
||||
} |
||||
|
||||
string filterHelp = "Fiter Options:\ntext - shows all key/categories matching text\nc text - shows all terms of the text category\nf text - show terms having 'text' in their translations"; |
||||
GUILayout.Space(-5); |
||||
GUI.contentColor = new Color(1, 1, 1, 0.5f); |
||||
GUILayout.Label(new GUIContent(GUITools.Icon_Help.image, filterHelp), GUITools.DontExpandWidth); |
||||
GUI.contentColor = GUITools.White; |
||||
GUILayout.Space(-5); |
||||
|
||||
|
||||
|
||||
|
||||
if (EditorGUI.EndChangeCheck()) |
||||
{ |
||||
mShowableTerms.Clear(); |
||||
GUI.changed = false; |
||||
} |
||||
|
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
|
||||
#endregion |
||||
|
||||
#region Filtering |
||||
|
||||
public bool ShouldShowTerm (string FullTerm) |
||||
{ |
||||
ParsedTerm termData; |
||||
if (!mParsedTerms.TryGetValue(FullTerm, out termData)) |
||||
return false; |
||||
|
||||
return ShouldShowTerm (termData.Term, termData.Category, termData.Usage, termData); |
||||
} |
||||
|
||||
private static TermData ShowTerm_termData; |
||||
public static bool ShouldShowTerm (string Term, string Category, int nUses, ParsedTerm parsedTerm=null ) |
||||
{ |
||||
if (!string.IsNullOrEmpty(Category) && !mSelectedCategories.Contains(Category)) |
||||
return false; |
||||
if (Term == "-") |
||||
return false; |
||||
|
||||
|
||||
var fullTerm = Term; |
||||
if (!string.IsNullOrEmpty(Category) && Category != LanguageSourceData.EmptyCategory) |
||||
fullTerm = Category + "/" + Term; |
||||
|
||||
if (parsedTerm != null && parsedTerm.termData != null) |
||||
ShowTerm_termData = parsedTerm.termData; |
||||
else |
||||
{ |
||||
ShowTerm_termData = mLanguageSource.GetTermData (fullTerm); |
||||
if (parsedTerm!=null) |
||||
parsedTerm.termData = ShowTerm_termData; |
||||
} |
||||
|
||||
|
||||
var filter = KeyList_Filter.Trim(); |
||||
bool useTranslation = filter.StartsWith("f ", StringComparison.OrdinalIgnoreCase); |
||||
if (useTranslation) |
||||
{ |
||||
if (ShowTerm_termData == null) |
||||
return false; |
||||
|
||||
filter = filter.Substring(2).Trim(); |
||||
if (!string.IsNullOrEmpty(filter)) |
||||
{ |
||||
bool hasFilter = false; |
||||
for (int i = 0; i < ShowTerm_termData.Languages.Length; ++i) |
||||
{ |
||||
if (!string.IsNullOrEmpty(ShowTerm_termData.Languages[i]) && StringContainsFilter(ShowTerm_termData.Languages[i], filter)) |
||||
{ |
||||
hasFilter = true; |
||||
break; |
||||
} |
||||
} |
||||
if (!hasFilter) |
||||
return false; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
bool onlyCategory = filter.StartsWith("c ", StringComparison.OrdinalIgnoreCase); |
||||
if (onlyCategory) |
||||
filter = filter.Substring(2).Trim(); |
||||
|
||||
if (!string.IsNullOrEmpty(filter)) |
||||
{ |
||||
bool matchesCategory = StringContainsFilter(Category, filter); |
||||
bool matchesName = !onlyCategory && StringContainsFilter(Term, filter); |
||||
|
||||
if (!matchesCategory && !matchesName) |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
|
||||
bool bIsMissing = ShowTerm_termData == null; |
||||
if (nUses<0) return true; |
||||
|
||||
if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing)>0 && bIsMissing) return true; |
||||
if ((mFlagsViewKeys & (int)eFlagsViewKeys.Missing)==0 && bIsMissing) return false; |
||||
|
||||
if ((mFlagsViewKeys & (int)eFlagsViewKeys.Used)>0 && nUses>0) return true; |
||||
if ((mFlagsViewKeys & (int)eFlagsViewKeys.NotUsed)>0 && nUses==0) return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
static bool StringContainsFilter( string Term, string Filter ) |
||||
{ |
||||
if (string.IsNullOrEmpty(Filter) || string.IsNullOrEmpty(Term)) |
||||
return true; |
||||
if (Term == "-") |
||||
return false; |
||||
Term = Term.ToLower(); |
||||
string[] Filters = Filter.ToLower().Split(";, ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); |
||||
for (int i = 0, imax = Filters.Length; i < imax; ++i) |
||||
if (Term.Contains(Filters[i])) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Add/Remove Keys to DB |
||||
|
||||
void AddTermsToSource() |
||||
{ |
||||
if (!string.IsNullOrEmpty (mKeyToExplore) && !mSelectedKeys.Contains(mKeyToExplore)) |
||||
mSelectedKeys.Add (mKeyToExplore); |
||||
|
||||
for (int i=mSelectedKeys.Count-1; i>=0; --i) |
||||
{ |
||||
string key = mSelectedKeys[i]; |
||||
|
||||
if (!ShouldShowTerm(key)) |
||||
continue; |
||||
|
||||
AddLocalTerm(key); |
||||
mSelectedKeys.RemoveAt(i); |
||||
} |
||||
SetAllTerms_When_InferredTerms_IsInSource (); |
||||
} |
||||
|
||||
void RemoveTermsFromSource() |
||||
{ |
||||
if (mTestAction==eTest_ActionType.None && !EditorUtility.DisplayDialog("Confirm delete", "Are you sure you want to delete the selected terms", "Yes", "Cancel")) |
||||
return; |
||||
|
||||
if (!string.IsNullOrEmpty (mKeyToExplore) && !mSelectedKeys.Contains(mKeyToExplore)) |
||||
mSelectedKeys.Add (mKeyToExplore); |
||||
|
||||
for (int i=mSelectedKeys.Count-1; i>=0; --i) |
||||
{ |
||||
string key = mSelectedKeys[i]; |
||||
|
||||
if (!ShouldShowTerm(key)) |
||||
continue; |
||||
|
||||
mLanguageSource.RemoveTerm(key); |
||||
RemoveParsedTerm(key); |
||||
mSelectedKeys.Remove(key); |
||||
} |
||||
|
||||
mKeyToExplore = string.Empty; |
||||
mTermList_MaxWidth = -1; |
||||
serializedObject.ApplyModifiedProperties(); |
||||
mLanguageSource.Editor_SetDirty(); |
||||
|
||||
EditorApplication.update += DoParseTermsInCurrentScene; |
||||
EditorApplication.update += RepaintScene; |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Select Objects in Current Scene |
||||
|
||||
|
||||
public static void SelectTerm( string Key, bool SwitchToKeysTab=false ) |
||||
{ |
||||
GUI.FocusControl(null); |
||||
mKeyToExplore = Key; |
||||
mKeysDesc_AllowEdit = false; |
||||
if (SwitchToKeysTab) |
||||
mCurrentViewMode = eViewMode.Keys; |
||||
} |
||||
|
||||
|
||||
void SelectObjectsUsingKey( string Key ) |
||||
{ |
||||
List<GameObject> SelectedObjs = FindObjectsUsingKey(Key); |
||||
|
||||
if (SelectedObjs.Count>0) |
||||
Selection.objects = SelectedObjs.ToArray(); |
||||
else |
||||
ShowWarning("The selected Terms are not used in this Scene. Try opening other scenes"); |
||||
} |
||||
|
||||
List<GameObject> FindObjectsUsingKey(string Key) |
||||
{ |
||||
List<GameObject> SelectedObjs = new List<GameObject>(); |
||||
|
||||
Localize[] Locals = (Localize[])Resources.FindObjectsOfTypeAll(typeof(Localize)); |
||||
|
||||
if (Locals == null) |
||||
return SelectedObjs; |
||||
|
||||
for (int i = 0, imax = Locals.Length; i < imax; ++i) |
||||
{ |
||||
Localize localize = Locals[i]; |
||||
if (localize == null || localize.gameObject == null || !GUITools.ObjectExistInScene(localize.gameObject)) |
||||
continue; |
||||
|
||||
string Term, SecondaryTerm; |
||||
localize.GetFinalTerms(out Term, out SecondaryTerm); |
||||
|
||||
if (Key == Term || Key == SecondaryTerm) |
||||
SelectedObjs.Add(localize.gameObject); |
||||
} |
||||
|
||||
return SelectedObjs; |
||||
} |
||||
|
||||
|
||||
#endregion |
||||
|
||||
|
||||
[MenuItem("Tools/I2 Localization/Refresh Localizations", false, 16)] |
||||
public static void CallLocalizeAll() |
||||
{ |
||||
LocalizationManager.LocalizeAll(true); |
||||
HandleUtility.Repaint(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 9f0230a94fc864d5bb1f2261de16edce |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 3efc8937ee2fcab49a6b6c1c9a1ed051 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 3fa4621ebd4134e1989b73eb3f7b864f |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 690f28955e250544a9bfaf741e4cced7 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,190 @@ |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public partial class LocalizationEditor |
||||
{ |
||||
#region Variables |
||||
|
||||
List<string> mCharSetTool_Languages = new List<string>(); |
||||
string mCharSet = string.Empty; |
||||
bool mCharSetTool_CaseSensitive; |
||||
|
||||
#endregion |
||||
|
||||
#region GUI Generate Script |
||||
|
||||
void OnGUI_Tools_CharSet() |
||||
{ |
||||
bool computeSet = false; |
||||
|
||||
// remove missing languages |
||||
for (int i=mCharSetTool_Languages.Count-1; i>=0; --i) |
||||
{ |
||||
if (mLanguageSource.GetLanguageIndex(mCharSetTool_Languages[i])<0) |
||||
mCharSetTool_Languages.RemoveAt(i); |
||||
} |
||||
|
||||
GUILayout.BeginHorizontal (EditorStyles.toolbar); |
||||
GUILayout.Label ("Languages:", EditorStyles.miniLabel, GUILayout.ExpandWidth(true)); |
||||
if (GUILayout.Button ("All", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
mCharSetTool_Languages.Clear (); |
||||
mCharSetTool_Languages.AddRange (mLanguageSource.mLanguages.Select(x=>x.Name)); |
||||
computeSet = true; |
||||
} |
||||
if (GUILayout.Button ("None", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
mCharSetTool_Languages.Clear (); |
||||
computeSet = true; |
||||
} |
||||
if (GUILayout.Button ("Invert", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) |
||||
{ |
||||
var current = mCharSetTool_Languages.ToList (); |
||||
mCharSetTool_Languages.Clear (); |
||||
mCharSetTool_Languages.AddRange (mLanguageSource.mLanguages.Select(x=>x.Name).Where(j=>!current.Contains(j))); |
||||
computeSet = true; |
||||
} |
||||
|
||||
|
||||
GUILayout.EndHorizontal (); |
||||
|
||||
//--[ Language List ]-------------------------- |
||||
|
||||
GUI.backgroundColor = Color.Lerp(GUITools.LightGray, Color.white, 0.5f); |
||||
mScrollPos_Languages = GUILayout.BeginScrollView( mScrollPos_Languages, LocalizeInspector.GUIStyle_OldTextArea, GUILayout.MinHeight (100), GUILayout.MaxHeight(Screen.height), GUILayout.ExpandHeight(false)); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
for (int i=0, imax=mLanguageSource.mLanguages.Count; i<imax; ++i) |
||||
{ |
||||
GUILayout.BeginHorizontal(); |
||||
var language = mLanguageSource.mLanguages[i].Name; |
||||
bool hasLanguage = mCharSetTool_Languages.Contains(language); |
||||
bool newValue = GUILayout.Toggle (hasLanguage, "", "OL Toggle", GUILayout.ExpandWidth(false)); |
||||
GUILayout.Label(language); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
if (hasLanguage != newValue) |
||||
{ |
||||
if (newValue) |
||||
mCharSetTool_Languages.Add(language); |
||||
else |
||||
mCharSetTool_Languages.Remove(language); |
||||
|
||||
computeSet = true; |
||||
} |
||||
} |
||||
|
||||
GUILayout.EndScrollView(); |
||||
|
||||
//GUILayout.Space (5); |
||||
|
||||
GUI.backgroundColor = Color.Lerp (Color.gray, Color.white, 0.2f); |
||||
GUILayout.BeginVertical(LocalizeInspector.GUIStyle_OldTextArea, GUILayout.Height(1)); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
EditorGUILayout.HelpBox("This tool shows all characters used in the selected languages", MessageType.Info); |
||||
|
||||
GUILayout.Space (5); |
||||
GUILayout.BeginHorizontal(); |
||||
GUILayout.FlexibleSpace(); |
||||
GUI.changed = false; |
||||
mCharSetTool_CaseSensitive = GUILayout.Toggle(mCharSetTool_CaseSensitive, "Case-Sensitive", GUILayout.ExpandWidth(false)); |
||||
if (GUI.changed) |
||||
computeSet = true; |
||||
GUILayout.FlexibleSpace(); |
||||
GUILayout.EndHorizontal(); |
||||
GUILayout.Space (5); |
||||
|
||||
if (computeSet) |
||||
UpdateCharSets(); |
||||
|
||||
int numUsedChars = string.IsNullOrEmpty (mCharSet) ? 0 : mCharSet.Length; |
||||
GUILayout.Label ("Used Characters: (" + numUsedChars+")"); |
||||
EditorGUILayout.TextArea (mCharSet ?? ""); |
||||
GUILayout.BeginHorizontal (); |
||||
GUILayout.FlexibleSpace (); |
||||
if (GUILayout.Button ("Copy To Clipboard", GUITools.DontExpandWidth)) |
||||
EditorGUIUtility.systemCopyBuffer = mCharSet; |
||||
GUILayout.EndHorizontal (); |
||||
GUILayout.EndVertical (); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Generate Char Set |
||||
|
||||
void UpdateCharSets () |
||||
{ |
||||
mCharSet = ""; |
||||
var sb = new HashSet<char> (); |
||||
var LanIndexes = new List<int> (); |
||||
for (int i=0; i<mLanguageSource.mLanguages.Count; ++i) |
||||
if (mCharSetTool_Languages.Contains(mLanguageSource.mLanguages[i].Name)) |
||||
LanIndexes.Add(i); |
||||
|
||||
foreach (var termData in mLanguageSource.mTerms) |
||||
{ |
||||
for (int i=0; i<LanIndexes.Count; ++i) |
||||
{ |
||||
int iLanguage = LanIndexes[i]; |
||||
bool isRTL = LocalizationManager.IsRTL( mLanguageSource.mLanguages[iLanguage].Code ); |
||||
AppendToCharSet( sb, termData.Languages[iLanguage], isRTL ); |
||||
} |
||||
} |
||||
var bytes = Encoding.UTF8.GetBytes( sb.ToArray().OrderBy(c => c).ToArray() ); |
||||
mCharSet = Encoding.UTF8.GetString(bytes); |
||||
} |
||||
|
||||
void AppendToCharSet( HashSet<char> sb, string text, bool isRTL ) |
||||
{ |
||||
if (string.IsNullOrEmpty (text)) |
||||
return; |
||||
|
||||
text = RemoveTagsPrefix(text, "[i2p_"); |
||||
text = RemoveTagsPrefix(text, "[i2s_"); |
||||
|
||||
if (isRTL) |
||||
text = RTLFixer.Fix( text ); |
||||
|
||||
foreach (char c in text) |
||||
{ |
||||
if (!mCharSetTool_CaseSensitive) |
||||
{ |
||||
sb.Add(char.ToLowerInvariant(c)); |
||||
sb.Add(char.ToUpperInvariant(c)); |
||||
} |
||||
else |
||||
sb.Add(c); |
||||
} |
||||
} |
||||
|
||||
// Given "[i2p_" it removes all tags that start with that (e.g. [i2p_Zero] [i2p_One], etc) |
||||
string RemoveTagsPrefix(string text, string tagPrefix) |
||||
{ |
||||
int idx = 0; |
||||
while (idx < text.Length) |
||||
{ |
||||
idx = text.IndexOf(tagPrefix); |
||||
if (idx < 0) |
||||
break; |
||||
|
||||
int idx2 = text.IndexOf(']', idx); |
||||
if (idx2 < 0) |
||||
break; |
||||
|
||||
text = text.Remove(idx, idx2 - idx+1); |
||||
} |
||||
return text; |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
#endregion |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 104713279df05ac4b96f5a76ab621c8a |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,157 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public partial class LocalizationEditor |
||||
{ |
||||
#region Variables |
||||
|
||||
#endregion |
||||
|
||||
#region GUI |
||||
|
||||
void OnGUI_Tools_MergeTerms() |
||||
{ |
||||
OnGUI_ScenesList(true); |
||||
|
||||
GUI.backgroundColor = Color.Lerp (Color.gray, Color.white, 0.2f); |
||||
GUILayout.BeginVertical(LocalizeInspector.GUIStyle_OldTextArea, GUILayout.Height(1)); |
||||
GUI.backgroundColor = Color.white; |
||||
GUILayout.Space (5); |
||||
|
||||
EditorGUILayout.HelpBox("This option replace all occurrences of this key in the selected scenes", MessageType.Info); |
||||
|
||||
GUILayout.Space (5); |
||||
GUITools.CloseHeader(); |
||||
|
||||
OnGUI_Tools_Categorize_Terms(); |
||||
OnGUI_NewOrExistingTerm(); |
||||
} |
||||
|
||||
void OnGUI_NewOrExistingTerm() |
||||
{ |
||||
if (mKeyToExplore==null) |
||||
mKeyToExplore = string.Empty; |
||||
|
||||
GUI.backgroundColor = Color.Lerp (Color.gray, Color.white, 0.2f); |
||||
GUILayout.BeginVertical(LocalizeInspector.GUIStyle_OldTextArea, GUILayout.Height(1)); |
||||
GUI.backgroundColor = Color.white; |
||||
GUILayout.Space(5); |
||||
GUILayout.Label("Replace By:"); |
||||
GUILayout.EndVertical(); |
||||
|
||||
//--[ Create Term ]------------------------ |
||||
GUILayout.BeginHorizontal(); |
||||
mKeyToExplore = GUILayout.TextField(mKeyToExplore, EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true)); |
||||
if (GUILayout.Button("Create", "toolbarbutton", GUILayout.Width(60))) |
||||
{ |
||||
LanguageSourceData.ValidateFullTerm( ref mKeyToExplore ); |
||||
EditorApplication.update += ReplaceSelectedTerms; |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
//--[ Existing Term ]------------------------ |
||||
int Index = 0; |
||||
List<string> Terms = mLanguageSource.GetTermsList(); |
||||
|
||||
for (int i=0, imax=Terms.Count; i<imax; ++i) |
||||
if (Terms[i].ToLower().Contains(mKeyToExplore.ToLower())) |
||||
{ |
||||
Index = i; |
||||
break; |
||||
} |
||||
|
||||
GUILayout.BeginHorizontal(); |
||||
int NewIndex = EditorGUILayout.Popup(Index, Terms.ToArray(), EditorStyles.toolbarPopup, GUILayout.ExpandWidth(true)); |
||||
if (NewIndex != Index) |
||||
{ |
||||
SelectTerm (Terms [NewIndex]); |
||||
ClearErrors(); |
||||
} |
||||
if (GUILayout.Button("Use", "toolbarbutton", GUILayout.Width(60))) |
||||
{ |
||||
SelectTerm( Terms[ NewIndex ] ); |
||||
EditorApplication.update += ReplaceSelectedTerms; |
||||
} |
||||
GUILayout.EndHorizontal(); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Merge Terms |
||||
|
||||
void ReplaceSelectedTerms() |
||||
{ |
||||
EditorApplication.update -= ReplaceSelectedTerms; |
||||
if (string.IsNullOrEmpty(mKeyToExplore)) |
||||
return; |
||||
|
||||
mIsParsing = true; |
||||
string sNewKey = mKeyToExplore; |
||||
|
||||
//--[ Create new Term ]----------------------- |
||||
if (mLanguageSource.GetTermData(sNewKey)==null) |
||||
{ |
||||
TermData termData = AddLocalTerm(sNewKey); |
||||
|
||||
//--[ Copy the values from any existing term if the target is a new term |
||||
TermData oldTerm = null; |
||||
for (int i=0, imax=mSelectedKeys.Count; i<imax; ++i) |
||||
{ |
||||
oldTerm = mLanguageSource.GetTermData(mSelectedKeys[i]); |
||||
if (oldTerm!=null) break; |
||||
} |
||||
|
||||
if (oldTerm!=null) |
||||
{ |
||||
termData.TermType = oldTerm.TermType; |
||||
termData.Description = oldTerm.Description; |
||||
Array.Copy(oldTerm.Languages, termData.Languages, oldTerm.Languages.Length); |
||||
} |
||||
} |
||||
|
||||
//--[ Delete the selected Terms from the source ]----------------- |
||||
TermReplacements = new Dictionary<string, string>(StringComparer.Ordinal); |
||||
for (int i=mSelectedKeys.Count-1; i>=0; --i) |
||||
{ |
||||
string OldTerm = mSelectedKeys[i]; |
||||
if (OldTerm == sNewKey) |
||||
continue; |
||||
|
||||
TermReplacements[ OldTerm ] = mKeyToExplore; |
||||
DeleteTerm(OldTerm); |
||||
} |
||||
ExecuteActionOnSelectedScenes( ReplaceTermsInCurrentScene ); |
||||
DoParseTermsInCurrentScene(); |
||||
|
||||
//--[ Update Selected Categories ]------------- |
||||
string mNewCategory = LanguageSourceData.GetCategoryFromFullTerm(sNewKey); |
||||
if (mNewCategory == string.Empty) |
||||
mNewCategory = LanguageSourceData.EmptyCategory; |
||||
if (!mSelectedCategories.Contains(mNewCategory)) |
||||
mSelectedCategories.Add (mNewCategory); |
||||
//RemoveUnusedCategoriesFromSelected(); |
||||
ScheduleUpdateTermsToShowInList(); |
||||
TermReplacements = null; |
||||
mIsParsing = false; |
||||
} |
||||
|
||||
void RemoveUnusedCategoriesFromSelected() |
||||
{ |
||||
List<string> Categories = LocalizationManager.GetCategories(); |
||||
for (int i=mSelectedCategories.Count-1; i>=0; --i) |
||||
if (!Categories.Contains( mSelectedCategories[i] )) |
||||
mSelectedCategories.RemoveAt(i); |
||||
|
||||
if (mSelectedCategories.Count == 0) |
||||
mSelectedCategories.AddRange(Categories); |
||||
|
||||
ScheduleUpdateTermsToShowInList(); |
||||
} |
||||
|
||||
#endregion |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: d59fa53e0df75a34693c4673bba5ed94 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 18d48e525beac1e4baff73e509fc246d |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 697e1bc5d373845df927c0da625b7cad |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 26e06d7fb9cef5341a791b25339444e0 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,281 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using UnityEngineInternal; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
public partial class LocalizationEditor |
||||
{ |
||||
#region Variables |
||||
|
||||
int Script_Tool_MaxVariableLength = 50; |
||||
|
||||
#endregion |
||||
|
||||
#region GUI Generate Script |
||||
|
||||
void OnGUI_Tools_Script() |
||||
{ |
||||
OnGUI_KeysList (false, 200, false); |
||||
|
||||
//GUILayout.Space (5); |
||||
|
||||
GUI.backgroundColor = Color.Lerp (Color.gray, Color.white, 0.2f); |
||||
GUILayout.BeginVertical(LocalizeInspector.GUIStyle_OldTextArea, GUILayout.Height(1)); |
||||
GUI.backgroundColor = Color.white; |
||||
|
||||
EditorGUILayout.HelpBox("This tool creates the ScriptLocalization.cs with the selected terms.\nThis allows for Compile Time Checking on the used Terms referenced in scripts", MessageType.Info); |
||||
|
||||
GUILayout.Space (5); |
||||
|
||||
GUILayout.BeginHorizontal (); |
||||
GUILayout.FlexibleSpace(); |
||||
EditorGUIUtility.labelWidth = 240; |
||||
EditorGUILayout.IntField("Max Length of the Generated Term IDs:", Script_Tool_MaxVariableLength); |
||||
EditorGUIUtility.labelWidth = 0; |
||||
GUILayout.FlexibleSpace(); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUILayout.Space (10); |
||||
|
||||
GUILayout.BeginHorizontal (); |
||||
GUILayout.FlexibleSpace(); |
||||
if (GUILayout.Button(new GUIContent("Select Baked Terms", "Selects all the terms previously built in ScriptLocalization.cs"))) |
||||
SelectTermsFromScriptLocalization(); |
||||
|
||||
if (GUILayout.Button("Build Script with Selected Terms")) |
||||
EditorApplication.update += BuildScriptWithSelectedTerms; |
||||
GUILayout.FlexibleSpace(); |
||||
GUILayout.EndHorizontal(); |
||||
|
||||
GUILayout.EndVertical(); |
||||
} |
||||
|
||||
void SelectTermsFromScriptLocalization() |
||||
{ |
||||
var ScriptFile = GetPathToGeneratedScriptLocalization(); |
||||
|
||||
try |
||||
{ |
||||
var text = File.ReadAllText(ScriptFile, Encoding.UTF8); |
||||
|
||||
mSelectedKeys.Clear(); |
||||
foreach (Match match in Regex.Matches(text, "\".+\"")) |
||||
{ |
||||
var term = match.Value.Substring(1, match.Value.Length - 2); |
||||
|
||||
if (!mSelectedKeys.Contains(term)) |
||||
{ |
||||
mSelectedKeys.Add(term); |
||||
} |
||||
} |
||||
} |
||||
catch(Exception) |
||||
{ } |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Generate Script File |
||||
|
||||
void BuildScriptWithSelectedTerms() |
||||
{ |
||||
EditorApplication.update -= BuildScriptWithSelectedTerms; |
||||
var sbTrans = new StringBuilder(); |
||||
var sbTerms = new StringBuilder(); |
||||
sbTrans.AppendLine( "using UnityEngine;" ); |
||||
sbTrans.AppendLine(); |
||||
sbTrans.AppendLine( "namespace I2.Loc" ); |
||||
sbTrans.AppendLine( "{" ); |
||||
sbTrans.AppendLine( " public static class ScriptLocalization" ); |
||||
sbTrans.AppendLine( " {" ); |
||||
|
||||
|
||||
sbTerms.AppendLine(); |
||||
sbTerms.AppendLine(" public static class ScriptTerms"); |
||||
sbTerms.AppendLine(" {"); |
||||
|
||||
|
||||
|
||||
BuildScriptWithSelectedTerms( sbTrans, sbTerms ); |
||||
sbTrans.AppendLine(" }"); // Closing both classes |
||||
sbTerms.AppendLine(" }"); |
||||
|
||||
|
||||
string ScriptFile = GetPathToGeneratedScriptLocalization (); |
||||
Debug.Log ("Generating: " + ScriptFile); |
||||
|
||||
var filePath = Application.dataPath + ScriptFile.Substring("Assets".Length); |
||||
string fileText = sbTrans + sbTerms.ToString() + "}"; |
||||
|
||||
File.WriteAllText(filePath, fileText, Encoding.UTF8); |
||||
|
||||
AssetDatabase.ImportAsset(ScriptFile); |
||||
} |
||||
|
||||
static string GetPathToGeneratedScriptLocalization() |
||||
{ |
||||
string[] assets = AssetDatabase.FindAssets("ScriptLocalization"); |
||||
if (assets.Length>0) |
||||
{ |
||||
try |
||||
{ |
||||
string FilePath = AssetDatabase.GUIDToAssetPath(assets[0]); |
||||
return FilePath; |
||||
} |
||||
catch(Exception) |
||||
{ } |
||||
} |
||||
|
||||
return "Assets/ScriptLocalization.cs"; |
||||
} |
||||
|
||||
void BuildScriptWithSelectedTerms( StringBuilder sbTrans, StringBuilder sbTerms ) |
||||
{ |
||||
List<string> Categories = LocalizationManager.GetCategories(); |
||||
foreach (string Category in Categories) |
||||
{ |
||||
List<string> CategoryTerms = ScriptTool_GetSelectedTermsInCategory(Category); |
||||
if (CategoryTerms.Count<=0) |
||||
continue; |
||||
|
||||
List<string> AdjustedCategoryTerms = new List<string>(CategoryTerms); |
||||
for (int i=0, imax=AdjustedCategoryTerms.Count; i<imax; ++i) |
||||
AdjustedCategoryTerms[i] = ScriptTool_AdjustTerm( AdjustedCategoryTerms[i] ); |
||||
ScriptTool_EnumerateDuplicatedTerms(AdjustedCategoryTerms); |
||||
|
||||
sbTrans.AppendLine(); |
||||
sbTerms.AppendLine(); |
||||
if (Category != LanguageSourceData.EmptyCategory) |
||||
{ |
||||
sbTrans.AppendLine(" public static class " + ScriptTool_AdjustTerm(Category,true)); |
||||
sbTrans.AppendLine(" {"); |
||||
|
||||
sbTerms.AppendLine(" public static class " + ScriptTool_AdjustTerm(Category, true)); |
||||
sbTerms.AppendLine(" {"); |
||||
} |
||||
|
||||
BuildScriptCategory( sbTrans, sbTerms, Category, AdjustedCategoryTerms, CategoryTerms ); |
||||
|
||||
if (Category != LanguageSourceData.EmptyCategory) |
||||
{ |
||||
sbTrans.AppendLine(" }"); |
||||
sbTerms.AppendLine(" }"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
List<string> ScriptTool_GetSelectedTermsInCategory( string Category ) |
||||
{ |
||||
List<string> list = new List<string>(); |
||||
foreach (string FullKey in mSelectedKeys) |
||||
{ |
||||
string categ = LanguageSourceData.GetCategoryFromFullTerm(FullKey); |
||||
if (categ == Category && ShouldShowTerm(FullKey)) |
||||
{ |
||||
list.Add( LanguageSourceData.GetKeyFromFullTerm(FullKey) ); |
||||
} |
||||
} |
||||
|
||||
return list; |
||||
} |
||||
|
||||
void BuildScriptCategory( StringBuilder sbTrans, StringBuilder sbTerms, string Category, List<string> AdjustedTerms, List<string> Terms ) |
||||
{ |
||||
if (Category==LanguageSourceData.EmptyCategory) |
||||
{ |
||||
for (int i = 0; i < Terms.Count; ++i) |
||||
{ |
||||
sbTrans.AppendLine( " public static string " + AdjustedTerms[i] + " \t\t{ get{ return LocalizationManager.GetTranslation (\"" + Terms[i] + "\"); } }"); |
||||
sbTerms.AppendLine(" public const string " + AdjustedTerms[i] + " = \"" + Terms[i] + "\";"); |
||||
} |
||||
} |
||||
else |
||||
for (int i=0; i<Terms.Count; ++i) |
||||
{ |
||||
sbTrans.AppendLine(" public static string "+AdjustedTerms[i]+ " \t\t{ get{ return LocalizationManager.GetTranslation (\"" + Category+"/"+Terms[i]+"\"); } }"); |
||||
sbTerms.AppendLine(" public const string " + AdjustedTerms[i] + " = \"" + Category + "/" + Terms[i] + "\";"); |
||||
} |
||||
} |
||||
|
||||
string ScriptTool_AdjustTerm( string Term, bool allowFullLength = false ) |
||||
{ |
||||
Term = I2Utils.GetValidTermName(Term); |
||||
|
||||
// C# IDs can't start with a number |
||||
if (I2Utils.NumberChars.IndexOf(Term[0])>=0) |
||||
Term = "_"+Term; |
||||
|
||||
if (!allowFullLength && Term.Length>Script_Tool_MaxVariableLength) |
||||
Term = Term.Substring(0, Script_Tool_MaxVariableLength); |
||||
|
||||
// Remove invalid characters |
||||
char[] chars = Term.ToCharArray(); |
||||
for (int i=0, imax=chars.Length; i<imax; ++i) |
||||
{ |
||||
if (!IsValidCharacter(chars[i])) |
||||
chars[i] = '_'; |
||||
} |
||||
|
||||
Term = new string(chars); |
||||
if (IsCSharpKeyword(Term)) return string.Concat('@', Term); |
||||
return Term; |
||||
|
||||
bool IsValidCharacter(char c) |
||||
{ |
||||
if (I2Utils.ValidChars.IndexOf(c)>=0) return true; |
||||
return c>='\u4e00' && c<='\u9fff'; // Chinese/Japanese characters |
||||
} |
||||
} |
||||
|
||||
void ScriptTool_EnumerateDuplicatedTerms(List<string> AdjustedTerms) |
||||
{ |
||||
string lastTerm = "$"; |
||||
int Counter = 1; |
||||
for (int i=0, imax=AdjustedTerms.Count; i<imax; ++i) |
||||
{ |
||||
string currentTerm = AdjustedTerms[i]; |
||||
if (lastTerm == currentTerm || i<imax-1 && currentTerm==AdjustedTerms[i+1]) |
||||
{ |
||||
AdjustedTerms[i] = AdjustedTerms[i] + "_" + Counter; |
||||
Counter++; |
||||
} |
||||
else |
||||
Counter = 1; |
||||
|
||||
lastTerm = currentTerm; |
||||
} |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
bool IsCSharpKeyword(string variableName) |
||||
{ |
||||
return variableName == "abstract" || variableName == "as" || variableName == "base" || variableName == "bool" || |
||||
variableName == "break" || variableName == "byte" || variableName == "" || variableName == "case" || |
||||
variableName == "catch" || variableName == "char" || variableName == "checked" || variableName == "class" || |
||||
variableName == "const" || variableName == "continue" || variableName == "decimal" || variableName == "default" || |
||||
variableName == "delegate" || variableName == "do" || variableName == "double" || variableName == "else" || |
||||
variableName == "enum" || variableName == "event" || variableName == "explicit" || variableName == "extern" || |
||||
variableName == "false" || variableName == "finally" || variableName == "fixed" || variableName == "float" || |
||||
variableName == "for" || variableName == "foreach" || variableName == "goto" || variableName == "if" || |
||||
variableName == "implicit" || variableName == "in" || variableName == "int" || variableName == "interface" || |
||||
variableName == "internal" || variableName == "is" || variableName == "lock" || variableName == "long" || |
||||
variableName == "namespace" || variableName == "new" || variableName == "null" || variableName == "object" || |
||||
variableName == "operator" || variableName == "out" || variableName == "override" || variableName == "params" || |
||||
variableName == "private" || variableName == "protected" || variableName == "public" || variableName == "readonly" || |
||||
variableName == "ref" || variableName == "return" || variableName == "sbyte" || variableName == "sealed" || |
||||
variableName == "short" || variableName == "sizeof" || variableName == "stackalloc" || variableName == "static" || |
||||
variableName == "string" || variableName == "struct" || variableName == "switch" || variableName == "this" || |
||||
variableName == "throw" || variableName == "true" || variableName == "try" || variableName == "typeof" || |
||||
variableName == "uint" || variableName == "ulong" || variableName == "unchecked" || variableName == "unsafe" || |
||||
variableName == "short" || variableName == "using" || variableName == "virtual" || variableName == "void" || |
||||
variableName == "volatile" || variableName == "while"; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 634a9cc818031dd4c8ddf451d36abe00 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 20e86d3a806624846bccd81bac9f935f |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,12 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 4c8d936531867014da228239d095833c |
||||
timeCreated: 1489354551 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,12 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 2bf71e767aaa5a245b9d74f326a39549 |
||||
timeCreated: 1489354551 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,12 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 68151af3db9fb734fb3823c020c9b8c0 |
||||
timeCreated: 1489354551 |
||||
licenseType: Store |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,9 @@ |
||||
fileFormatVersion: 2 |
||||
guid: d9276efd8270b104ea614946e5787aa1 |
||||
folderAsset: yes |
||||
timeCreated: 1489466610 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Binary file not shown.
@ -0,0 +1,24 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 6bcca352fcef3034fb01650308bf47c2 |
||||
timeCreated: 1496388333 |
||||
licenseType: Store |
||||
PluginImporter: |
||||
serializedVersion: 1 |
||||
iconMap: {} |
||||
executionOrder: {} |
||||
isPreloaded: 0 |
||||
platformData: |
||||
Any: |
||||
enabled: 0 |
||||
settings: {} |
||||
Editor: |
||||
enabled: 1 |
||||
settings: |
||||
DefaultValueInitialized: true |
||||
WindowsStoreApps: |
||||
enabled: 0 |
||||
settings: |
||||
CPU: AnyCPU |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,9 @@ |
||||
This is a copy of the Xcode Manipulation API |
||||
https://bitbucket.org/Unity-Technologies/xcodeapi/overview |
||||
|
||||
This is already packed inside Unity under the UnityEditor.IOS.XCode namespace, |
||||
but I'm including here as well because the version that comes with unity doesn't handle |
||||
localized files. |
||||
This copy includes the pullrequest #13 (https://bitbucket.org/Unity-Technologies/xcodeapi/pull-requests/13/creation-of-variantgroup-and/diff) |
||||
|
||||
Hopefully that will be integrated in Unity soon, but until then, I will be including this files here! |
||||
@ -0,0 +1,8 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 8f2eff1a75746804db6c0240420ebed9 |
||||
timeCreated: 1489466907 |
||||
licenseType: Store |
||||
TextScriptImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,303 @@ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using Object = UnityEngine.Object; |
||||
|
||||
namespace I2.Loc |
||||
{ |
||||
[InitializeOnLoad] |
||||
public class UpgradeManager |
||||
{ |
||||
static bool mAlreadyCheckedPlugins; |
||||
|
||||
static UpgradeManager() |
||||
{ |
||||
EditorApplication.update += AutoCheckPlugins; |
||||
} |
||||
|
||||
public static void AutoCheckPlugins() |
||||
{ |
||||
CheckPlugins (); |
||||
} |
||||
|
||||
public static void CheckPlugins( bool bForce = false ) |
||||
{ |
||||
EditorApplication.update -= AutoCheckPlugins; |
||||
|
||||
if (mAlreadyCheckedPlugins && !bForce) |
||||
return; |
||||
mAlreadyCheckedPlugins = true; |
||||
|
||||
EnablePlugins(bForce); |
||||
CreateLanguageSources(); |
||||
//CreateScriptLocalization(); |
||||
} |
||||
|
||||
const string EditorPrefs_AutoEnablePlugins = "I2Loc AutoEnablePlugins"; |
||||
|
||||
[MenuItem( "Tools/I2 Localization/Enable Plugins/Force Detection", false, 0 )] |
||||
public static void ForceCheckPlugins() |
||||
{ |
||||
CheckPlugins( true ); |
||||
} |
||||
|
||||
[MenuItem( "Tools/I2 Localization/Enable Plugins/Enable Auto Detection", false, 1 )] |
||||
public static void EnableAutoCheckPlugins() |
||||
{ |
||||
EditorPrefs.SetBool(EditorPrefs_AutoEnablePlugins, true); |
||||
} |
||||
[MenuItem( "Tools/I2 Localization/Enable Plugins/Enable Auto Detection", true)] |
||||
public static bool ValidEnableAutoCheckPlugins() |
||||
{ |
||||
return !EditorPrefs.GetBool(EditorPrefs_AutoEnablePlugins, true); |
||||
} |
||||
|
||||
|
||||
[MenuItem( "Tools/I2 Localization/Enable Plugins/Disable Auto Detection", false, 2 )] |
||||
public static void DisableAutoCheckPlugins() |
||||
{ |
||||
EditorPrefs.SetBool(EditorPrefs_AutoEnablePlugins, false); |
||||
} |
||||
[MenuItem( "Tools/I2 Localization/Enable Plugins/Disable Auto Detection", true)] |
||||
public static bool ValidDisableAutoCheckPlugins() |
||||
{ |
||||
return EditorPrefs.GetBool(EditorPrefs_AutoEnablePlugins, true); |
||||
} |
||||
|
||||
|
||||
[MenuItem("Tools/I2 Localization/Toggle Highlight Localized", false, 17)] |
||||
public static void ToogleH() |
||||
{ |
||||
LocalizationManager.HighlightLocalizedTargets = !LocalizationManager.HighlightLocalizedTargets; |
||||
LocalizationManager.LocalizeAll(true); |
||||
} |
||||
|
||||
|
||||
[MenuItem("Tools/I2 Localization/Create Temp")] |
||||
public static void CreateTemp() |
||||
{ |
||||
LanguageSourceData source = LocalizationManager.Sources[0]; |
||||
for (int i = 0; i < 1000; ++i) |
||||
source.AddTerm("Term " + i, eTermType.Text, false); |
||||
source.UpdateDictionary(true); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
public static void EnablePlugins( bool bForce = false ) |
||||
{ |
||||
if (!bForce) |
||||
{ |
||||
bool AutoEnablePlugins = EditorPrefs.GetBool(EditorPrefs_AutoEnablePlugins, true); |
||||
if (!AutoEnablePlugins) |
||||
return; |
||||
} |
||||
//var tar = System.Enum.GetValues(typeof(BuildTargetGroup)); |
||||
foreach (BuildTargetGroup target in Enum.GetValues(typeof(BuildTargetGroup))) |
||||
if (target!=BuildTargetGroup.Unknown && !target.HasAttributeOfType<ObsoleteAttribute>()) |
||||
{ |
||||
#if UNITY_5_6 |
||||
if (target == BuildTargetGroup.Switch) continue; // some releases of 5.6 defined BuildTargetGroup.Switch but didn't handled it correctly |
||||
#endif |
||||
EnablePluginsOnPlatform( target ); |
||||
} |
||||
|
||||
// Force these one (iPhone has the same # than iOS and iPhone is deprecated, so iOS was been skipped) |
||||
EnablePluginsOnPlatform(BuildTargetGroup.iOS); |
||||
} |
||||
|
||||
static void EnablePluginsOnPlatform( BuildTargetGroup Platform ) |
||||
{ |
||||
string Settings = PlayerSettings.GetScriptingDefineSymbolsForGroup(Platform ); |
||||
|
||||
bool HasChanged = false; |
||||
List<string> symbols = new List<string>( Settings.Split(';')); |
||||
|
||||
HasChanged |= UpdateSettings("NGUI", "NGUIDebug", "", ref symbols); |
||||
HasChanged |= UpdateSettings("DFGUI", "dfPanel", "", ref symbols); |
||||
HasChanged |= UpdateSettings("TK2D", "tk2dTextMesh", "", ref symbols); |
||||
HasChanged |= UpdateSettings( "TextMeshPro", "TMPro.TMP_FontAsset", "TextMeshPro", ref symbols ); |
||||
HasChanged |= UpdateSettings( "SVG", "SVGImporter.SVGAsset", "", ref symbols ); |
||||
|
||||
if (HasChanged) |
||||
{ |
||||
try |
||||
{ |
||||
Settings = string.Empty; |
||||
for (int i=0,imax=symbols.Count; i<imax; ++i) |
||||
{ |
||||
if (i>0) Settings += ";"; |
||||
Settings += symbols[i]; |
||||
} |
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(Platform, Settings ); |
||||
} |
||||
catch (Exception) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
|
||||
static bool UpdateSettings( string mPlugin, string mType, string AssemblyType, ref List<string> symbols) |
||||
{ |
||||
try |
||||
{ |
||||
bool hasPluginClass = false; |
||||
|
||||
if (!string.IsNullOrEmpty( AssemblyType )) |
||||
{ |
||||
var rtype = AppDomain.CurrentDomain.GetAssemblies() |
||||
.Where( assembly => assembly.FullName.Contains(AssemblyType) ) |
||||
.Select( assembly => assembly.GetType( mType, false ) ) |
||||
.Where( t => t!=null ) |
||||
.FirstOrDefault(); |
||||
if (rtype != null) |
||||
hasPluginClass = true; |
||||
} |
||||
|
||||
if (!hasPluginClass) |
||||
hasPluginClass = typeof( Localize ).Assembly.GetType( mType, false )!=null; |
||||
|
||||
|
||||
bool hasPluginDef = symbols.IndexOf(mPlugin)>=0; |
||||
|
||||
if (hasPluginClass != hasPluginDef) |
||||
{ |
||||
if (hasPluginClass) symbols.Add(mPlugin); |
||||
else symbols.Remove(mPlugin); |
||||
return true; |
||||
} |
||||
} |
||||
catch(Exception) |
||||
{ |
||||
} |
||||
return false; |
||||
|
||||
} |
||||
|
||||
//[MenuItem( "Tools/I2 Localization/Create I2Languages", false, 1)] |
||||
public static void CreateLanguageSources() |
||||
{ |
||||
if (LocalizationManager.GlobalSources==null || LocalizationManager.GlobalSources.Length==0) |
||||
return; |
||||
|
||||
Object GlobalSource = Resources.Load(LocalizationManager.GlobalSources[0]); |
||||
LanguageSourceData sourceData = null; |
||||
string sourcePath = null; |
||||
|
||||
if (GlobalSource != null) |
||||
{ |
||||
if (GlobalSource is GameObject) |
||||
{ |
||||
// I2Languages was a prefab before 2018.3, it should be converted to an ScriptableObject |
||||
sourcePath = AssetDatabase.GetAssetPath(GlobalSource); |
||||
LanguageSource langSourceObj = (GlobalSource as GameObject).GetComponent<LanguageSource>(); |
||||
sourceData = langSourceObj.mSource; |
||||
} |
||||
else |
||||
{ |
||||
return; |
||||
} |
||||
} |
||||
|
||||
LanguageSourceAsset asset = ScriptableObject.CreateInstance<LanguageSourceAsset>(); |
||||
if (sourceData != null) |
||||
{ |
||||
asset.mSource = sourceData; |
||||
AssetDatabase.DeleteAsset(sourcePath); |
||||
} |
||||
|
||||
if (string.IsNullOrEmpty(sourcePath)) |
||||
{ |
||||
//string PluginPath = GetI2LocalizationPath(); |
||||
string ResourcesFolder = "Assets/Resources";//PluginPath.Substring(0, PluginPath.Length-"/Localization".Length) + "/Resources"; |
||||
|
||||
string fullresFolder = Application.dataPath + ResourcesFolder.Replace("Assets", ""); |
||||
if (!Directory.Exists(fullresFolder)) |
||||
Directory.CreateDirectory(fullresFolder); |
||||
|
||||
sourcePath = ResourcesFolder + "/" + LocalizationManager.GlobalSources[0] + ".asset"; |
||||
} |
||||
else |
||||
{ |
||||
sourcePath = sourcePath.Replace(".prefab", ".asset"); |
||||
} |
||||
|
||||
AssetDatabase.CreateAsset(asset, sourcePath); |
||||
AssetDatabase.SaveAssets(); |
||||
AssetDatabase.Refresh(); |
||||
} |
||||
|
||||
[MenuItem("Tools/I2 Localization/Help", false, 30)] |
||||
[MenuItem("Help/I2 Localization")] |
||||
public static void MainHelp() |
||||
{ |
||||
Application.OpenURL(LocalizeInspector.HelpURL_Documentation); |
||||
} |
||||
|
||||
[MenuItem("Tools/I2 Localization/Open I2Languages.asset", false, 0)] |
||||
public static void OpenGlobalSource() |
||||
{ |
||||
CreateLanguageSources(); |
||||
LanguageSourceAsset GO = Resources.Load<LanguageSourceAsset>(LocalizationManager.GlobalSources[0]); |
||||
if (GO == null) |
||||
Debug.Log("Unable to find Global Language at Assets/Resources/" + LocalizationManager.GlobalSources[0] + ".asset"); |
||||
|
||||
Selection.activeObject = GO; |
||||
} |
||||
|
||||
|
||||
/*static void CreateScriptLocalization() |
||||
{ |
||||
string[] assets = AssetDatabase.FindAssets("ScriptLocalization"); |
||||
if (assets.Length>0) |
||||
return; |
||||
|
||||
string ScriptsFolder = "Assets"; |
||||
string ScriptText = LocalizationEditor.mScriptLocalizationHeader + " }\n}"; |
||||
|
||||
System.IO.File.WriteAllText(ScriptsFolder + "/ScriptLocalization.cs", ScriptText); |
||||
|
||||
AssetDatabase.SaveAssets(); |
||||
AssetDatabase.Refresh(); |
||||
}*/ |
||||
|
||||
public static string GetI2LocalizationPath() |
||||
{ |
||||
string[] assets = AssetDatabase.FindAssets("LocalizationManager"); |
||||
if (assets.Length==0) |
||||
return string.Empty; |
||||
|
||||
string PluginPath = AssetDatabase.GUIDToAssetPath(assets[0]); |
||||
PluginPath = PluginPath.Substring(0, PluginPath.Length - "/Scripts/LocalizationManager.cs".Length); |
||||
|
||||
return PluginPath; |
||||
} |
||||
|
||||
public static string GetI2Path() |
||||
{ |
||||
string pluginPath = GetI2LocalizationPath(); |
||||
return pluginPath.Substring(0, pluginPath.Length-"/Localization".Length); |
||||
} |
||||
|
||||
public static string GetI2CommonResourcesPath() |
||||
{ |
||||
string I2Path = GetI2Path(); |
||||
return I2Path + "/Resources"; |
||||
} |
||||
} |
||||
|
||||
public static class UpgradeManagerHelper |
||||
{ |
||||
public static bool HasAttributeOfType<T>(this Enum enumVal) where T:Attribute |
||||
{ |
||||
var type = enumVal.GetType(); |
||||
var memInfo = type.GetMember(enumVal.ToString()); |
||||
var attributes = memInfo[0].GetCustomAttributes(typeof(T), false); |
||||
return attributes.Length > 0; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 6e61480936111c54883dc051751e0a5f |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 79fbe85a671c1254880b1fc083a723e5 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,9 @@ |
||||
fileFormatVersion: 2 |
||||
guid: dda5008126b59ad4bad4c9d2626a2345 |
||||
folderAsset: yes |
||||
timeCreated: 1461137613 |
||||
licenseType: Store |
||||
DefaultImporter: |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 26e29b3e77176de4cbb64a3ec85beee6 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: cc4d0073f9e452047bd31b01de2bbd82 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 94b94d27ab6931c4abee1e4d3655b660 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 206e4bf72a490864e9bcb59edbdddaed |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: c6bd173cd8524b04daa3dabce666b456 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
@ -0,0 +1,10 @@ |
||||
fileFormatVersion: 2 |
||||
guid: 7dae211a5bb44db46a568fb70fca3296 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue