LocalizationEditor.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace I2.Loc
  4. {
  5. public abstract partial class LocalizationEditor : Editor
  6. {
  7. #region Variables
  8. SerializedProperty mProp_Assets, mProp_Languages,
  9. mProp_Google_WebServiceURL, mProp_GoogleUpdateFrequency, mProp_GoogleUpdateDelay, mProp_Google_SpreadsheetKey, mProp_Google_SpreadsheetName, mProp_Google_Password,
  10. mProp_Spreadsheet_LocalFileName, mProp_Spreadsheet_LocalCSVSeparator, mProp_CaseInsensitiveTerms, mProp_Spreadsheet_LocalCSVEncoding,
  11. mProp_OnMissingTranslation, mProp_AppNameTerm, mProp_IgnoreDeviceLanguage, mProp_Spreadsheet_SpecializationAsRows, mProp_GoogleInEditorCheckFrequency,
  12. mProp_HighlightLocalizedTargets, mProp_GoogleLiveSyncIsUptoDate, mProp_AllowUnloadingLanguages, mProp_GoogleUpdateSynchronization;
  13. public static LanguageSourceData mLanguageSource;
  14. public static Object mLanguageSourceObject;
  15. public static LocalizationEditor mLanguageSourceEditor;
  16. public static Editor mCurrentInspector;
  17. static bool mIsParsing; // This is true when the editor is opening several scenes to avoid reparsing objects
  18. #endregion
  19. #region Variables GUI
  20. GUIStyle Style_ToolBar_Big, Style_ToolBarButton_Big;
  21. public GUISkin CustomSkin;
  22. static Vector3 mScrollPos_Languages;
  23. public static string mLanguages_NewLanguage = "";
  24. #endregion
  25. #region Styles
  26. public static GUIStyle Style_WrapTextField {
  27. get{
  28. if (mStyle_WrapTextField==null)
  29. {
  30. mStyle_WrapTextField = new GUIStyle(EditorStyles.textArea);
  31. mStyle_WrapTextField.wordWrap = true;
  32. mStyle_WrapTextField.fixedHeight = 0;
  33. }
  34. return mStyle_WrapTextField;
  35. }
  36. }
  37. static GUIStyle mStyle_WrapTextField;
  38. #endregion
  39. #region Inspector
  40. public void Custom_OnEnable( LanguageSourceData sourceData, SerializedProperty propSource)
  41. {
  42. bool ForceParse = mLanguageSource != sourceData;
  43. mLanguageSource = sourceData;
  44. mLanguageSourceEditor = this;
  45. mCurrentInspector = this;
  46. if (!LocalizationManager.Sources.Contains(mLanguageSource))
  47. LocalizationManager.UpdateSources();
  48. mProp_Assets = propSource.FindPropertyRelative("Assets");
  49. mProp_Languages = propSource.FindPropertyRelative("mLanguages");
  50. mProp_Google_WebServiceURL = propSource.FindPropertyRelative("Google_WebServiceURL");
  51. mProp_GoogleUpdateFrequency = propSource.FindPropertyRelative("GoogleUpdateFrequency");
  52. mProp_GoogleUpdateSynchronization = propSource.FindPropertyRelative("GoogleUpdateSynchronization");
  53. mProp_GoogleInEditorCheckFrequency = propSource.FindPropertyRelative("GoogleInEditorCheckFrequency");
  54. mProp_GoogleUpdateDelay = propSource.FindPropertyRelative("GoogleUpdateDelay");
  55. mProp_Google_SpreadsheetKey = propSource.FindPropertyRelative("Google_SpreadsheetKey");
  56. mProp_Google_SpreadsheetName = propSource.FindPropertyRelative("Google_SpreadsheetName");
  57. mProp_Google_Password = propSource.FindPropertyRelative("Google_Password");
  58. mProp_CaseInsensitiveTerms = propSource.FindPropertyRelative("CaseInsensitiveTerms");
  59. mProp_Spreadsheet_LocalFileName = propSource.FindPropertyRelative("Spreadsheet_LocalFileName");
  60. mProp_Spreadsheet_LocalCSVSeparator = propSource.FindPropertyRelative("Spreadsheet_LocalCSVSeparator");
  61. mProp_Spreadsheet_LocalCSVEncoding = propSource.FindPropertyRelative("Spreadsheet_LocalCSVEncoding");
  62. mProp_Spreadsheet_SpecializationAsRows = propSource.FindPropertyRelative("Spreadsheet_SpecializationAsRows");
  63. mProp_OnMissingTranslation = propSource.FindPropertyRelative("OnMissingTranslation");
  64. mProp_AppNameTerm = propSource.FindPropertyRelative("mTerm_AppName");
  65. mProp_IgnoreDeviceLanguage = propSource.FindPropertyRelative("IgnoreDeviceLanguage");
  66. mProp_GoogleLiveSyncIsUptoDate = propSource.FindPropertyRelative("GoogleLiveSyncIsUptoDate");
  67. mProp_AllowUnloadingLanguages = propSource.FindPropertyRelative("_AllowUnloadingLanguages");
  68. if (!mIsParsing)
  69. {
  70. if (string.IsNullOrEmpty(mLanguageSource.Google_SpreadsheetKey))
  71. mSpreadsheetMode = eSpreadsheetMode.Local;
  72. else
  73. mSpreadsheetMode = eSpreadsheetMode.Google;
  74. mCurrentViewMode = mLanguageSource.mLanguages.Count>0 ? eViewMode.Keys : eViewMode.Languages;
  75. UpdateSelectedKeys();
  76. if (ForceParse || mParsedTerms.Count < mLanguageSource.mTerms.Count)
  77. {
  78. mSelectedCategories.Clear();
  79. ParseTerms(true, false, true);
  80. }
  81. }
  82. ScheduleUpdateTermsToShowInList();
  83. LoadSelectedCategories();
  84. //UpgradeManager.EnablePlugins();
  85. }
  86. void OnDisable()
  87. {
  88. //LocalizationManager.LocalizeAll();
  89. SaveSelectedCategories();
  90. mLanguageSourceEditor = null;
  91. if (mCurrentInspector==this) mCurrentInspector = null;
  92. }
  93. void UpdateSelectedKeys()
  94. {
  95. // Remove all keys that are not in this source
  96. string trans;
  97. for (int i=mSelectedKeys.Count-1; i>=0; --i)
  98. if (!mLanguageSource.TryGetTranslation(mSelectedKeys[i], out trans))
  99. mSelectedKeys.RemoveAt(i);
  100. // Remove all Categories that are not in this source
  101. /*var mCateg = mLanguageSource.GetCategories();
  102. for (int i=mSelectedCategories.Count-1; i>=0; --i)
  103. if (!mCateg.Contains(mSelectedCategories[i]))
  104. mSelectedCategories.RemoveAt(i);
  105. if (mSelectedCategories.Count==0)
  106. mSelectedCategories = mCateg;*/
  107. if (mSelectedScenes.Count==0)
  108. mSelectedScenes.Add (Editor_GetCurrentScene());
  109. }
  110. public override void OnInspectorGUI()
  111. {
  112. // Load Test:
  113. /*if (mLanguageSource.mTerms.Count<40000)
  114. {
  115. mLanguageSource.mTerms.Clear();
  116. for (int i=0; i<40020; ++i)
  117. mLanguageSource.AddTerm("ahh"+i.ToString("00000"), eTermType.Text, false);
  118. mLanguageSource.UpdateDictionary();
  119. }*/
  120. //Profiler.maxNumberOfSamplesPerFrame = -1; // REMOVE ---------------------------------------------------
  121. mIsParsing = false;
  122. //#if UNITY_5_6_OR_NEWER
  123. // serializedObject.UpdateIfRequiredOrScript();
  124. //#else
  125. // serializedObject.UpdateIfDirtyOrScript();
  126. //#endif
  127. if (mLanguageSource.mTerms.Count<1000)
  128. Undo.RecordObject(target, "LanguageSource");
  129. //GUI.backgroundColor = Color.Lerp (Color.black, Color.gray, 1);
  130. //GUILayout.BeginVertical(LocalizeInspector.GUIStyle_Background);
  131. //GUI.backgroundColor = Color.white;
  132. if (GUILayout.Button("Language Source", LocalizeInspector.GUIStyle_Header))
  133. {
  134. Application.OpenURL(LocalizeInspector.HelpURL_Documentation);
  135. }
  136. InitializeStyles();
  137. GUILayout.Space(10);
  138. //GUI.backgroundColor = Color.Lerp(GUITools.LightGray, Color.white, 0.5f);
  139. //GUILayout.BeginVertical(LocalizeInspector.GUIStyle_Background);
  140. //GUI.backgroundColor = Color.white;
  141. OnGUI_Main();
  142. //GUILayout.EndVertical();
  143. GUILayout.Space (10);
  144. GUILayout.FlexibleSpace();
  145. GUITools.OnGUI_Footer("I2 Localization", LocalizationManager.GetVersion(), LocalizeInspector.HelpURL_forum, LocalizeInspector.HelpURL_Documentation, LocalizeInspector.HelpURL_AssetStore);
  146. //GUILayout.EndVertical();
  147. serializedObject.ApplyModifiedProperties();
  148. if (Event.current.type == EventType.Repaint)
  149. {
  150. mTestAction = eTest_ActionType.None;
  151. mTestActionArg = null;
  152. mTestActionArg2 = null;
  153. }
  154. }
  155. #endregion
  156. }
  157. }