void OnGUI_Tools_Categorize() { OnGUI_ScenesList(true); GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.2f); GUILayout.BeginVertical("AS TextArea", GUILayout.Height(1)); GUI.backgroundColor = Color.white; GUILayout.Space(5); EditorGUILayout.HelpBox("This tool changes the category of the selected Terms and updates the highlighted scenes", UnityEditor.MessageType.Info); GUILayout.Space(5); GUITools.CloseHeader(); OnGUI_Tools_Categorize_Terms(); OnGUI_NewOrExistingCategory(); }
private void OnGUI_ExportButtons() { eSpreadsheetUpdateMode Mode = SynchronizationButtons("Export"); if (Mode != eSpreadsheetUpdateMode.None || InTestAction(eTest_ActionType.Button_GoogleSpreadsheet_Export)) { if (mTestAction == eTest_ActionType.Button_GoogleSpreadsheet_Export) { Mode = (eSpreadsheetUpdateMode)mTestActionArg; } serializedObject.ApplyModifiedProperties(); var modeCopy = Mode; GUITools.DelayedCall(() => Export_Google(modeCopy)); } }
void OnGUI_Tools_MergeTerms() { OnGUI_ScenesList(true); GUI.backgroundColor = Color.Lerp(Color.gray, Color.white, 0.2f); GUILayout.BeginVertical(EditorStyles.textArea, 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(); }
static void UpdateTermsToShownInList() { EditorApplication.update -= UpdateTermsToShownInList; mUpdateShowTermIsScheduled = false; mShowableTerms.Clear(); 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(); }
static void OnGUI_Keys_Language_SpecializationsBar() { GUILayout.BeginHorizontal(); GUI_SelectedInputType = GUITools.DrawTabs(GUI_SelectedInputType, new string[] { "Normal|Transation for Non Touch devices.\nThis allows using 'click' instead of 'tap', etc", "Touch|Normal|Transation for Touch devices.\nThis allows using 'tap' instead of 'click', etc" }, null); GUI.enabled = false; GUI_SelectedPluralType = GUITools.DrawShadowedTabs(GUI_SelectedPluralType, new string[] { "Zero", "One", "Two", "Few", "Many", "Other" }, 18, false); GUI.enabled = true; GUI.Label(GUILayoutUtility.GetLastRect(), new GUIContent("", null, "Plurals are not enabled in this version.\nIt will be one of the new features for version 3")); GUI_ShowDisabledLanguagesTranslation = GUILayout.Toggle(GUI_ShowDisabledLanguagesTranslation, new GUIContent("L", "Show Disabled Languages"), "Button", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.Space(-1); //static public int DrawTabs( int Index, string[] Tabs, GUIStyle Style=null, int height=25, bool expand = true) /*GUIStyle MyStyle = new GUIStyle(Style!=null?Style:GUI.skin.FindStyle("dragtab")); * MyStyle.fixedHeight=0; * * GUILayout.BeginHorizontal(); * for (int i=0; i<Tabs.Length; ++i) * { * int idx = Tabs[i].IndexOf('|'); * if (idx>0) * { * string text = Tabs[i].Substring(0, idx); * string tooltip = Tabs[i].Substring(idx+1); * if ( GUILayout.Toggle(Index==i, new GUIContent(text, tooltip), MyStyle, GUILayout.Height(height), GUILayout.ExpandWidth(expand)) && Index!=i) * { * Index=i; * GUI.FocusControl(string.Empty); * } * } * else * { * if ( GUILayout.Toggle(Index==i, Tabs[i], MyStyle, GUILayout.Height(height), GUILayout.ExpandWidth(expand)) && Index!=i) * { * Index=i; * GUI.FocusControl(string.Empty); * } * } * } * GUILayout.EndHorizontal(); * return Index;*/ }
void OnGUI_ImportExport() { eSpreadsheetMode OldMode = mSpreadsheetMode; mSpreadsheetMode = (eSpreadsheetMode)GUITools.DrawShadowedTabs((int)mSpreadsheetMode, new string[] { "Local", "Google" }); if (mSpreadsheetMode != OldMode) { ClearErrors(); } GUITools.BeginContents(); switch (mSpreadsheetMode) { case eSpreadsheetMode.Local: OnGUI_Spreadsheet_Local(); break; case eSpreadsheetMode.Google: OnGUI_Spreadsheet_Google(); break; } GUITools.EndContents(false); }
void OnGUI_GoogleButtons_ImportExport(string SpreadsheetKey) { GUI.enabled = !string.IsNullOrEmpty(SpreadsheetKey) && mConnection_WWW == null; GUILayout.BeginHorizontal(); GUILayout.Space(10); eSpreadsheetUpdateMode Mode = SynchronizationButtons("Import"); if (Mode != eSpreadsheetUpdateMode.None || InTestAction(eTest_ActionType.Button_GoogleSpreadsheet_Import)) { if (mTestAction == eTest_ActionType.Button_GoogleSpreadsheet_Import) { Mode = (eSpreadsheetUpdateMode)mTestActionArg; } serializedObject.ApplyModifiedProperties(); var modeCopy = Mode; GUITools.DelayedCall(() => Import_Google(modeCopy)); } GUILayout.FlexibleSpace(); Mode = SynchronizationButtons("Export"); if (Mode != eSpreadsheetUpdateMode.None || InTestAction(eTest_ActionType.Button_GoogleSpreadsheet_Export)) { if (mTestAction == eTest_ActionType.Button_GoogleSpreadsheet_Export) { Mode = (eSpreadsheetUpdateMode)mTestActionArg; } serializedObject.ApplyModifiedProperties(); var modeCopy = Mode; GUITools.DelayedCall(() => Export_Google(modeCopy)); } GUILayout.Space(10); GUILayout.EndHorizontal(); GUI.enabled = true; }
void OnGUI_References() { EditorGUILayout.HelpBox("These are the assets that are referenced by the Terms and not in the Resources folder", MessageType.Info); 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_Assets, false, false, false, testAddObj, testReplaceObj, testReplaceIndx, testDeleteIndx); if (changed) { serializedObject.ApplyModifiedProperties(); foreach (var obj in serializedObject.targetObjects) { (obj as LanguageSource).mSource.UpdateAssetDictionary(); } } }
static void OnGUI_Keys_Languages(string Key, ref TermData termdata, Localize localizeCmp, bool IsPrimaryKey, LanguageSourceData source) { //--[ Languages ]--------------------------- GUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Height(1)); OnGUI_Keys_LanguageTranslations(Key, localizeCmp, IsPrimaryKey, ref termdata, source); if (termdata.TermType == eTermType.Text) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (TestButton(eTest_ActionType.Button_Term_TranslateAll, "Translate All", "Button", GUILayout.Width(85))) { var termData = termdata; GUITools.DelayedCall(() => TranslateLanguage(Key, termData, localizeCmp, source)); GUI.FocusControl(string.Empty); } GUILayout.EndHorizontal(); OnGUI_TranslatingMessage(); } GUILayout.EndVertical(); }
public static void ReplaceTermsInCurrentScene() { Localize[] Locals = (Localize[])Resources.FindObjectsOfTypeAll(typeof(Localize)); if (Locals == null) { return; } bool changed = false; 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 NewTerm; if (TermReplacements.TryGetValue(localize.Term, out NewTerm)) { localize.mTerm = NewTerm; changed = true; } if (TermReplacements.TryGetValue(localize.SecondaryTerm, out NewTerm)) { localize.mTermSecondary = NewTerm; changed = true; } } if (changed) { Editor_SaveScene(true); } }
void SelectObjectsUsingKey(string Key) { List <GameObject> SelectedObjs = new List <GameObject>(); Localize[] Locals = (Localize[])Resources.FindObjectsOfTypeAll(typeof(Localize)); if (Locals == null) { return; } 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); } } if (SelectedObjs.Count > 0) { Selection.objects = SelectedObjs.ToArray(); } else { ShowWarning("The selected Terms are not used in this Scene. Try opening other scenes"); } }
public override void OnInspectorGUI() { #if UNITY_5_6_OR_NEWER serializedObject.UpdateIfRequiredOrScript(); #else serializedObject.UpdateIfDirtyOrScript(); #endif terms = LocalizationManager.GetTermsList(); terms.Sort(System.StringComparer.OrdinalIgnoreCase); terms.Add(""); terms.Add("<inferred from text>"); terms.Add("<none>"); GUI.backgroundColor = Color.Lerp(Color.black, Color.gray, 1); GUILayout.BeginVertical(LocalizeInspector.GUIStyle_Background); GUI.backgroundColor = Color.white; if (GUILayout.Button("Localize DropDown", LocalizeInspector.GUIStyle_Header)) { Application.OpenURL(LocalizeInspector.HelpURL_Documentation); } GUILayout.Space(5); mList.DoLayoutList(); GUILayout.Space(10); GUITools.OnGUI_Footer("I2 Localization", LocalizationManager.GetVersion(), LocalizeInspector.HelpURL_forum, LocalizeInspector.HelpURL_Documentation, LocalizeInspector.HelpURL_AssetStore); EditorGUIUtility.labelWidth = 0; GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); terms = null; }
void OnGUI_GoogleCredentials() { GUI.enabled = mConnection_WWW == null; GUI.changed = false; string WebServiceHelp = "The web service is a script running on the google drive where the spreadsheet you want to use is located.\nThat script allows the game to synchronize the localization even after the game is published."; GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Web Service URL:", WebServiceHelp), GUILayout.Width(110)); GUI.SetNextControlName("WebServiceURL"); mProp_Google_WebServiceURL.stringValue = EditorGUILayout.TextField(mProp_Google_WebServiceURL.stringValue); if (!string.IsNullOrEmpty(mWebService_Status)) { if (mWebService_Status == "Online") { GUI.color = Color.green; GUILayout.Label("", GUILayout.Width(17)); Rect r = GUILayoutUtility.GetLastRect(); r.xMin += 3; r.yMin -= 3; r.xMax += 2; r.yMax += 2; GUI.Label(r, new GUIContent("\u2713", "Online"), EditorStyles.whiteLargeLabel); GUI.color = Color.white; } else if (mWebService_Status == "Offline") { GUI.color = Color.red; GUILayout.Label("", GUILayout.Width(17)); Rect r = GUILayoutUtility.GetLastRect(); r.xMin += 3; r.yMin -= 3; r.xMax += 2; r.yMax += 2; GUI.Label(r, new GUIContent("\u2717", mWebService_Status), EditorStyles.whiteLargeLabel); GUI.color = Color.white; } else if (mWebService_Status == "UnsupportedVersion") { Rect rect = GUILayoutUtility.GetLastRect(); float Width = 15; rect.xMin = rect.xMax + 1; rect.xMax = rect.xMin + rect.height; GUITools.DrawSkinIcon(rect, "CN EntryWarnIcon", "CN EntryWarn"); GUI.Label(rect, new GUIContent("\u2717", "The current Google WebService is not supported.\nPlease, delete the WebService from the Google Drive and Install the latest version.")); GUILayout.Space(Width); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(118); if (GUILayout.Button(new GUIContent("Install", "This opens the Web Service Script and shows you steps to install and authorize it on your Google Drive"), EditorStyles.toolbarButton)) { ClearErrors(); Application.OpenURL("https://script.google.com/d/1zcsLSmq3Oddd8AsLuoKNDG1Y0eYBOHzyvGT7v94u1oN6igmsZb_PJzEm/newcopy"); // V5 //Application.OpenURL("https://goo.gl/RBCO0o"); // V4:https://script.google.com/d/1T7e5_40NcgRyind-yeg4PAkHz9TNZJ22F4RcbOvCpAs03JNf1vKNNTZB/newcopy //Application.OpenURL("https://goo.gl/wFSbv2");// V3:https://script.google.com/d/1CxQDSXflsXRaH3M7xGfrIDrFwOIHWPsYTWi4mRZ_k77nyIInTgIk63Kd/newcopy"); } if (GUILayout.Button("Verify", EditorStyles.toolbarButton)) { ClearErrors(); VerifyGoogleService(mProp_Google_WebServiceURL.stringValue); GUI.changed = false; } GUILayout.EndHorizontal(); if (string.IsNullOrEmpty(mProp_Google_WebServiceURL.stringValue)) { EditorGUILayout.HelpBox(WebServiceHelp, MessageType.Info); } if (GUI.changed) { if (string.IsNullOrEmpty(mProp_Google_WebServiceURL.stringValue)) { mProp_Google_SpreadsheetKey.stringValue = string.Empty; mProp_Google_SpreadsheetName.stringValue = string.Empty; } // If the web service changed then clear the cached spreadsheet keys mGoogleSpreadsheets.Clear(); GUI.changed = false; ClearErrors(); } GUI.enabled = true; }
void SelectNoLocalizedLabels() { EditorPrefs.SetString("_Tools_NoLocalized_Include", _Tools_NoLocalized_Include); EditorPrefs.SetString("_Tools_NoLocalized_Exclude", _Tools_NoLocalized_Exclude); EditorApplication.update -= SelectNoLocalizedLabels; List <Component> labels = new List <Component>(); TextMesh[] textMeshes = (TextMesh[])Resources.FindObjectsOfTypeAll(typeof(TextMesh)); if (textMeshes != null && textMeshes.Length > 0) { labels.AddRange(textMeshes); } #if NGUI UILabel[] uiLabels = (UILabel[])Resources.FindObjectsOfTypeAll(typeof(UILabel)); if (uiLabels != null && uiLabels.Length > 0) { labels.AddRange(uiLabels); } #endif UnityEngine.UI.Text[] uiTexts = (UnityEngine.UI.Text[])Resources.FindObjectsOfTypeAll(typeof(UnityEngine.UI.Text)); if (uiTexts != null && uiTexts.Length > 0) { labels.AddRange(uiTexts); } #if TextMeshPro || TextMeshPro_Pre53 TMPro.TextMeshPro[] tmpText = (TMPro.TextMeshPro[])Resources.FindObjectsOfTypeAll(typeof(TMPro.TextMeshPro)); if (tmpText != null && tmpText.Length > 0) { labels.AddRange(tmpText); } TMPro.TextMeshProUGUI[] uiTextsUGUI = (TMPro.TextMeshProUGUI[])Resources.FindObjectsOfTypeAll(typeof(TMPro.TextMeshProUGUI)); if (uiTextsUGUI != null && uiTextsUGUI.Length > 0) { labels.AddRange(uiTextsUGUI); } #endif #if TK2D tk2dTextMesh[] tk2dTM = (tk2dTextMesh[])Resources.FindObjectsOfTypeAll(typeof(tk2dTextMesh)); if (tk2dTM != null && tk2dTM.Length > 0) { labels.AddRange(tk2dTM); } #endif if (labels.Count == 0) { return; } string[] Includes = null; string[] Excludes = null; if (!string.IsNullOrEmpty(_Tools_NoLocalized_Include)) { Includes = _Tools_NoLocalized_Include.ToLower().Split(new char[] { ',', ';' }); } if (!string.IsNullOrEmpty(_Tools_NoLocalized_Exclude)) { Excludes = _Tools_NoLocalized_Exclude.ToLower().Split(new char[] { ',', ';' }); } List <GameObject> Objs = new List <GameObject>(); for (int i = 0, imax = labels.Count; i < imax; ++i) { Component label = labels[i]; if (label == null || label.gameObject == null || !GUITools.ObjectExistInScene(label.gameObject)) { continue; } if (labels[i].GetComponent <Localize>() != null) { continue; } if (ShouldFilter(label.name.ToLower(), Includes, Excludes)) { continue; } Objs.Add(labels[i].gameObject); } if (Objs.Count > 0) { Selection.objects = Objs.ToArray(); } else { ShowWarning("All labels in this scene have a Localize component assigned"); } }
void OnGUI_Warning_SourceInScene() { if (mLanguageSource.UserAgreesToHaveItOnTheScene) { return; } LanguageSource source = (LanguageSource)target; if (source.IsGlobalSource() && !GUITools.ObjectExistInScene(source.gameObject)) { return; } string Text = @"Its advised to only use the source in I2\Localization\Resources\I2Languages.prefab That works as a GLOBAL source accessible in ALL scenes. That’s why its recommended to add all your translations there. You don't need to instantiate that prefab into the scene, just click the prefab and add the Data. Only use Sources in the scene when the localization is meant to be ONLY used there. However, that's not advised and is only used in the Examples to keep them separated from your project localization. Furthermore, having a source in the scene require that any Localize component get a reference to that source to work properly. By dragging the source into the field at the bottom of the Localize component."; EditorGUILayout.HelpBox(Text, MessageType.Warning); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Keep as is")) { SerializedProperty Agree = serializedObject.FindProperty("UserAgreesToHaveItOnTheScene"); Agree.boolValue = true; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Open the Global Source")) { GameObject Prefab = (Resources.Load(LocalizationManager.GlobalSources[0]) as GameObject); Selection.activeGameObject = Prefab; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Delete this and open the Global Source")) { EditorApplication.CallbackFunction Callback = null; EditorApplication.update += Callback = () => { EditorApplication.update -= Callback; if (source.GetComponents <Component>().Length <= 2) { Debug.Log("Deleting GameObject '" + source.name + "' and Openning the " + LocalizationManager.GlobalSources[0] + ".prefab"); DestroyImmediate(source.gameObject); } else { Debug.Log("Deleting the LanguageSource inside GameObject " + source.name + " and Openning the " + LocalizationManager.GlobalSources[0] + ".prefab"); DestroyImmediate(source); } GameObject Prefab = (Resources.Load(LocalizationManager.GlobalSources[0]) as GameObject); Selection.activeGameObject = Prefab; }; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(10); }
// Bottom part of the Key list (buttons: All, None, Used,... to select the keys) void OnGUI_Keys_ListSelection(int KeyListFilterID) { GUILayout.BeginHorizontal("toolbarbutton"); if (GUILayout.Button(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 (GUILayout.Button(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 (GUILayout.Button(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; GUI.FocusControl(""); } if (EditorGUI.EndChangeCheck()) { mShowableTerms.Clear(); GUI.changed = false; } GUILayout.EndHorizontal(); }
public static void SetAllTerms_When_InferredTerms_IsInSource() { var Locals = Resources.FindObjectsOfTypeAll(typeof(Localize)) as Localize[]; if (Locals == null) { return; } foreach (var localize in Locals) { if (localize == null || (localize.Source != null && localize.Source.SourceData != mLanguageSource) || localize.gameObject == null || !GUITools.ObjectExistInScene(localize.gameObject)) { continue; } if (!string.IsNullOrEmpty(localize.mTerm) && !string.IsNullOrEmpty(localize.SecondaryTerm)) { continue; } ApplyInferredTerm(localize); } ParseTerms(true, false, true); }
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 ]---------------------- 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); GUILayout.BeginHorizontal(); if (GUILayout.Button("v" + LocalizationManager.GetVersion(), EditorStyles.miniLabel)) { Application.OpenURL(LocalizeInspector.HelpURL_ReleaseNotes); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Tutorials", EditorStyles.miniLabel)) { Application.OpenURL(HelpURL_Tutorials); } GUILayout.Space(10); if (GUILayout.Button("Ask a Question", EditorStyles.miniLabel)) { Application.OpenURL(HelpURL_forum); } GUILayout.Space(10); if (GUILayout.Button("Documentation", EditorStyles.miniLabel)) { Application.OpenURL(HelpURL_Documentation); } GUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = 0; GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); }
void OnGUI_References() { EditorGUILayout.HelpBox("These are the assets that are referenced by the Terms and not in the Resources folder", MessageType.Info); GUITools.DrawObjectsArray(mProp_Assets); }
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, LocalizeInspector.HelpURL_AssetStore); //GUILayout.EndVertical(); serializedObject.ApplyModifiedProperties(); if (Event.current.type == EventType.Repaint) { LocalizationEditor.mTestAction = LocalizationEditor.eTest_ActionType.None; LocalizationEditor.mTestActionArg = null; LocalizationEditor.mTestActionArg2 = null; } }
void OnGUI_Terms() { if (mLocalize.mGUI_ShowTems = GUITools.DrawHeader("Terms", mLocalize.mGUI_ShowTems)) { //--[ tabs: Main and Secondary Terms ]---------------- int oldTab = GUI_SelectedTerm; if (mLocalize.CanUseSecondaryTerm) { GUI_SelectedTerm = GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "Main", "Secondary" }); } else { GUI_SelectedTerm = 0; GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "Main", "" }); } GUITools.BeginContents(); if (GUI_SelectedTerm == 0) { OnGUI_PrimaryTerm(oldTab != GUI_SelectedTerm); } else { OnGUI_SecondaryTerm(oldTab != GUI_SelectedTerm); } GUITools.EndContents(); //--[ Modifier ]------------- GUI.changed = false; int val = EditorGUILayout.Popup("Modifier", GUI_SelectedTerm == 0 ? (int)mLocalize.PrimaryTermModifier : (int)mLocalize.SecondaryTermModifier, System.Enum.GetNames(typeof(Localize.TermModification))); if (GUI.changed) { serializedObject.FindProperty(GUI_SelectedTerm == 0 ? "PrimaryTermModifier" : "SecondaryTermModifier").enumValueIndex = val; GUI.changed = false; } //--[ 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.LocalizeCallBack.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 ]------------- GUILayout.BeginVertical("Box"); mProp_IgnoreRTL.boolValue = GUILayout.Toggle(mProp_IgnoreRTL.boolValue, " Ignore Right To Left Languages"); if (!mLocalize.IgnoreRTL) { 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.EndHorizontal(); //GUILayout.EndHorizontal(); } }
// 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(); }
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(Screen.width / 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), EditorStyles.textArea)) { 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 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); } }
static void OnGUI_Keys_LanguageTranslations(string Key, Localize localizeCmp, bool IsPrimaryKey, ref TermData termdata, LanguageSourceData source) { bool IsSelect = Event.current.type == EventType.MouseUp; for (int i = 0; i < source.mLanguages.Count; ++i) { bool forcePreview = false; bool isEnabledLanguage = source.mLanguages[i].IsEnabled(); if (!isEnabledLanguage) { if (!GUI_ShowDisabledLanguagesTranslation) { continue; } GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.35f); } GUILayout.BeginHorizontal(); if (GUILayout.Button(source.mLanguages[i].Name, EditorStyles.label, GUILayout.Width(100))) { forcePreview = true; } string Translation = termdata.GetTranslation(i, GUI_SelectedSpecialization, editMode: true); if (Translation == null) { Translation = string.Empty; } // if (termdata.Languages[i] != termdata.Languages_Touch[i] && !string.IsNullOrEmpty(termdata.Languages[i]) && !string.IsNullOrEmpty(termdata.Languages_Touch[i])) // GUI.contentColor = GUITools.LightYellow; if (termdata.TermType == eTermType.Text || termdata.TermType == eTermType.Child) { EditorGUI.BeginChangeCheck(); string CtrName = "TranslatedText" + i; GUI.SetNextControlName(CtrName); EditPluralTranslations(ref Translation, i, source.mLanguages[i].Code); //Translation = EditorGUILayout.TextArea(Translation, Style_WrapTextField, GUILayout.Width(Screen.width - 260 - (autoTranslated ? 20 : 0))); if (EditorGUI.EndChangeCheck()) { termdata.SetTranslation(i, Translation, GUI_SelectedSpecialization); source.Editor_SetDirty(); forcePreview = true; } if (localizeCmp != null && (forcePreview || /*GUI.changed || */ (GUI.GetNameOfFocusedControl() == CtrName && IsSelect))) { if (IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.Term)) { localizeCmp.mTerm = Key; } if (!IsPrimaryKey && string.IsNullOrEmpty(localizeCmp.SecondaryTerm)) { localizeCmp.mTermSecondary = Key; } string PreviousLanguage = LocalizationManager.CurrentLanguage; LocalizationManager.PreviewLanguage(source.mLanguages[i].Name); if (forcePreview || IsSelect) { LocalizationManager.LocalizeAll(); } else { localizeCmp.OnLocalize(true); } LocalizationManager.PreviewLanguage(PreviousLanguage); EditorUtility.SetDirty(localizeCmp); } GUI.contentColor = Color.white; //if (autoTranslated) //{ // if (GUILayout.Button(new GUIContent("\u2713"/*"A"*/,"Translated by Google Translator\nClick the button to approve the translation"), EditorStyles.toolbarButton, GUILayout.Width(autoTranslated ? 20 : 0))) // { // termdata.Flags[i] &= (byte)(byte.MaxValue ^ (byte)(GUI_SelectedSpecialization==0 ? TranslationFlag.AutoTranslated_Normal : TranslationFlag.AutoTranslated_Touch)); // } //} if (termdata.TermType == eTermType.Text) { if (TestButtonArg(eTest_ActionType.Button_Term_Translate, i, new GUIContent("T", "Translate"), EditorStyles.toolbarButton, GUILayout.Width(20))) { var termData = termdata; var indx = i; var key = Key; GUITools.DelayedCall(() => TranslateTerm(key, termData, source, indx)); GUI.FocusControl(string.Empty); } } } else { string MultiSpriteName = string.Empty; if (termdata.TermType == eTermType.Sprite && Translation.EndsWith("]", StringComparison.Ordinal)) // Handle sprites of type (Multiple): "SpritePath[SpriteName]" { int idx = Translation.LastIndexOf("[", StringComparison.Ordinal); int len = Translation.Length - idx - 2; MultiSpriteName = Translation.Substring(idx + 1, len); Translation = Translation.Substring(0, idx); } Object Obj = null; // Try getting the asset from the References section if (localizeCmp != null) { Obj = localizeCmp.FindTranslatedObject <Object>(Translation); } if (Obj == null && source != null) { Obj = source.FindAsset(Translation); } // If it wasn't in the references, Load it from Resources if (Obj == null && localizeCmp == null) { Obj = ResourceManager.pInstance.LoadFromResources <Object>(Translation); } Type ObjType = typeof(Object); switch (termdata.TermType) { case eTermType.Font: ObjType = typeof(Font); break; case eTermType.Texture: ObjType = typeof(Texture); break; case eTermType.AudioClip: ObjType = typeof(AudioClip); break; case eTermType.GameObject: ObjType = typeof(GameObject); break; case eTermType.Sprite: ObjType = typeof(Sprite); break; case eTermType.Material: ObjType = typeof(Material); break; case eTermType.Mesh: ObjType = typeof(Mesh); break; #if NGUI case eTermType.UIAtlas: ObjType = typeof(UIAtlas); break; case eTermType.UIFont: ObjType = typeof(UIFont); break; #endif #if TK2D case eTermType.TK2dFont: ObjType = typeof(tk2dFont); break; case eTermType.TK2dCollection: ObjType = typeof(tk2dSpriteCollection); break; #endif #if TextMeshPro case eTermType.TextMeshPFont: ObjType = typeof(TMPro.TMP_FontAsset); break; #endif #if SVG case eTermType.SVGAsset: ObjType = typeof(SVGImporter.SVGAsset); break; #endif case eTermType.Object: ObjType = typeof(Object); break; } if (Obj != null && !string.IsNullOrEmpty(MultiSpriteName)) { string sPath = AssetDatabase.GetAssetPath(Obj); Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(sPath); Obj = null; for (int j = 0, jmax = objs.Length; j < jmax; ++j) { if (objs[j].name.Equals(MultiSpriteName)) { Obj = objs[j]; break; } } } bool bShowTranslationLabel = (Obj == null && !string.IsNullOrEmpty(Translation)); if (bShowTranslationLabel) { GUI.backgroundColor = GUITools.DarkGray; GUILayout.BeginVertical(EditorStyles.textArea, GUILayout.Height(1)); GUILayout.Space(2); GUI.backgroundColor = Color.white; } Object NewObj = EditorGUILayout.ObjectField(Obj, ObjType, true, GUILayout.ExpandWidth(true)); if (Obj != NewObj) { string sPath = null; if (NewObj != null) { sPath = AssetDatabase.GetAssetPath(NewObj); mCurrentInspector.serializedObject.ApplyModifiedProperties(); foreach (var cmp in mCurrentInspector.serializedObject.targetObjects) { AddObjectPath(ref sPath, cmp as Localize, NewObj); } mCurrentInspector.serializedObject.ApplyModifiedProperties(); if (HasObjectInReferences(NewObj, localizeCmp)) { sPath = NewObj.name; } else if (termdata.TermType == eTermType.Sprite) { sPath += "[" + NewObj.name + "]"; } } termdata.SetTranslation(i, sPath, GUI_SelectedSpecialization); source.Editor_SetDirty(); } if (bShowTranslationLabel) { GUILayout.BeginHorizontal(); GUI.color = Color.red; GUILayout.FlexibleSpace(); GUILayout.Label(Translation, EditorStyles.miniLabel); GUILayout.FlexibleSpace(); GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.EndVertical(); } } GUILayout.EndHorizontal(); GUI.color = Color.white; } }
void OnGUI_Terms() { if ((mLocalize.mGUI_ShowTems = GUITools.DrawHeader("Terms", mLocalize.mGUI_ShowTems)) == true) { //--[ tabs: Main and Secondary Terms ]---------------- int oldTab = GUI_SelectedTerm; if (mLocalize.mLocalizeTarget != null && mLocalize.mLocalizeTarget.CanUseSecondaryTerm()) { GUI_SelectedTerm = GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "Main", "Secondary" }); } else { GUI_SelectedTerm = 0; GUITools.DrawTabs(GUI_SelectedTerm, new string[] { "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, System.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(); } }
static void FindTermsInCurrentScene() { Localize[] Locals = (Localize[])Resources.FindObjectsOfTypeAll(typeof(Localize)); if (Locals == null) { return; } for (int i = 0, imax = Locals.Length; i < imax; ++i) { Localize localize = Locals[i]; if (localize == null || (localize.Source != null && localize.Source.SourceData != mLanguageSource) || localize.gameObject == null || !GUITools.ObjectExistInScene(localize.gameObject)) { continue; } string Term, SecondaryTerm; //Term = localize.Term; //SecondaryTerm = localize.SecondaryTerm; localize.GetFinalTerms(out Term, out SecondaryTerm); if (!string.IsNullOrEmpty(Term)) { GetParsedTerm(Term).Usage++; } if (!string.IsNullOrEmpty(SecondaryTerm)) { GetParsedTerm(SecondaryTerm).Usage++; } } }