public void SetData(string path, Encoding encoding) { FileInfo fileInfo = new FileInfo(path); // Instance = DataTableEditingWindow.CreateWindow<DataTableEditingWindow>(fileInfo.Name); #if UNITY_2019_1_OR_NEWER Instance = LauncherEditorWindow.CreateWindow <DataTableEditingWindow>(fileInfo.Name); #else Instance = EditorWindowUtility.CreateWindow <DataTableEditingWindow>(fileInfo.Name); #endif Instance.OpenWindow(path, encoding); Instance.Show(); }
// PUBLIC STATIC /// <summary> /// Determines whether this instance is AUMOM compatible manager mono script the specified aMonoScript. /// </summary> /// <returns> /// <c>true</c> if this instance is AUMOM compatible manager mono script the specified aMonoScript; otherwise, <c>false</c>. /// </returns> /// <param name='aMonoScript'> /// If set to <c>true</c> a mono script. /// </param> public static bool IsCompatibleManagerMonoScript(MonoScript aMonoScript) { Object[] allValidScriptableObjects = EditorWindowUtility.GetAllObjectsBySuperClassAndInterface(typeof(BaseManager)); // MonoScript scriptableObject_monoscript; //FIND THE SCRIPTABLE OBJECT THAT MATCHES THE MONOSCRIPT foreach (ScriptableObject scriptableObject in allValidScriptableObjects) { //Debug.Log (" valid: " + scriptableObject); scriptableObject_monoscript = MonoScript.FromScriptableObject(scriptableObject); //Debug.Log (" CHECKING2 : " + scriptableObject_monoscript.GetClass().FullName + " , " + aMonoScript.GetClass().FullName); if (scriptableObject_monoscript.GetClass().FullName == aMonoScript.GetClass().FullName) { // Debug.Log (" FOUND: " + aMonoScript); break; } } return(aMonoScript.name.StartsWith("M") == true); }
// PRIVATE STATIC //-------------------------------------- // Events //-------------------------------------- /// <summary> /// _ons the button click. /// </summary> /// <param name='buttonClickType'> /// Button click type. /// </param> private void _onButtonClick(ButtonClickType buttonClickType) { IEnumerator iEnumerator = _managersFromRAM_serializedproperty.GetEnumerator(); while (iEnumerator.MoveNext()) { Debug.Log("is : " + (iEnumerator.Current as SerializedProperty).objectReferenceValue); } switch (buttonClickType) { case ButtonClickType.ADD: _managersFromRAM_serializedproperty.InsertArrayElementAtIndex(0); _managersFromRAM_serializedproperty.GetArrayElementAtIndex(0).objectReferenceValue = _inUseFromAssets_scriptableobject; break; case ButtonClickType.REMOVE: // if (_hasManagerAlready(_monoScript.GetClass())) { Debug.Log("i: " + _getManagerIndex(_monoScript.GetClass())); _managersFromRAM_serializedproperty.DeleteArrayElementAtIndex(0); } break; case ButtonClickType.CONVERT: ScriptableObject scriptableObject = ScriptableObjectUtility.CreateAssetFromMonoScript(_monoScript); EditorWindowUtility.doSetThenUnsetProjectWindowSelectionTo(scriptableObject); break; } _managersFromRAM_serializedproperty.serializedObject.ApplyModifiedProperties(); _managersFromRAM_serializedproperty.serializedObject.SetIsDifferentCacheDirty(); _managersFromRAM_serializedproperty.serializedObject.UpdateIfDirtyOrScript(); }
// PRIVATE STATIC //-------------------------------------- // Events //-------------------------------------- /// <summary> /// Raises the enable event. /// </summary> public void OnEnable() { // tabIcon_texture2D = Resources.Load("UMOMEditorWindowTabIcon") as Texture2D; hierarchyItem_texture2D = Resources.Load("UMOMHierarchyItemIcon") as Texture2D; bannerImage_texture2D = Resources.Load("UMOMEditorWindowBannerImage") as Texture2D; //GRAB FRESH REFERENCES, NEEDED? _getTargetReferences(); //LOAD OBJECTS manually so they exist in needed 'FindObjectsOfTypeIncludingAssets' call, later EditorWindowUtility.LoadAllAssetsOfType(typeof(ScriptableObject)); // autoRepaintOnSceneChange = true; // EditorWindowUtility.SetEditorWindowTabIcon(this, tabIcon_texture2D); //listen EditorApplication.hierarchyWindowItemOnGUI += _onHierarchyWindowItemOnGUI; EditorApplication.hierarchyWindowChanged += _onHierarchyWindowChanged; EditorApplication.projectWindowItemOnGUI += _onProjectWindowItemOnGUI; }
void OnGUI() { if (EditorWindowUtility.ShowWindow()) { if (smartLocWindow == null || thisCultureInfo == null) { this.Close(); // Temp fix } else if (!rootFileChanged) { undoManager.CheckUndo(); GUILayout.Label("Language - " + thisLanguage, EditorStyles.boldLabel, GUILayout.Width(200)); //Copy all the Base Values GUILayout.Label("If you want to copy all the base values from the root file", EditorStyles.miniLabel); if (GUILayout.Button("Copy All Base Values", GUILayout.Width(150))) { int count = 0; foreach (KeyValuePair <string, LocalizedObject> rootValue in rootValues) { if (rootValue.Value.ObjectType == LocalizedObjectType.STRING) { thisLanguageValues[count].changedValue.TextValue = rootValue.Value.TextValue; } count++; } } GUILayout.Label("Microsoft Translator", EditorStyles.boldLabel); if (!smartLocWindow.MicrosoftTranslator.IsInitialized) { GUILayout.Label("Microsoft Translator is not authenticated", EditorStyles.miniLabel); } else { if (canLanguageBeTranslated) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Translate From:", GUILayout.Width(100)); translateFromLanguageValue = EditorGUILayout.Popup(translateFromLanguageValue, availableTranslateLangEnglishNames); EditorGUILayout.EndHorizontal(); if (oldTranslateFromLanguageValue != translateFromLanguageValue) { oldTranslateFromLanguageValue = translateFromLanguageValue; //The value have been changed, load the language file of the other language that you want to translate from //I load it like this to show the translate buttons only on the ones that can be translated i.e some values //in the "from" language could be an empty string - no use in translating that if (translateFromDictionary != null) { translateFromDictionary.Clear(); translateFromDictionary = null; } if (translateFromLanguageValue != 0) { string englishName = availableTranslateLangEnglishNames[translateFromLanguageValue]; foreach (CultureInfo info in availableTranslateFromLanguages) { if (info.EnglishName == englishName) { translateFromDictionary = LocFileUtility.LoadParsedLanguageFile(info.Name); translateFromLanguage = info.Name; break; } } } } //Translate all the available keys if (translateFromLanguageValue != 0 && GUILayout.Button("Translate all text", GUILayout.Width(150))) { List <string> keys = new List <string>(); List <string> textsToTranslate = new List <string>(); int characterCount = 0; foreach (KeyValuePair <string, LocalizedObject> stringPair in translateFromDictionary) { if (stringPair.Value.ObjectType == LocalizedObjectType.STRING && stringPair.Value.TextValue != null && stringPair.Value.TextValue != "") { int textLength = stringPair.Value.TextValue.Length; //Microsoft translator only support translations below 1000 character //I'll cap it to 700, which gives 300 extra if the translated value is longer if (textLength < 700) { characterCount += textLength; keys.Add(stringPair.Key); textsToTranslate.Add(stringPair.Value.TextValue); } } //Microsoft translator only support translations with 100 array values and a total // character cap of 10000, // I'll cap it to 7000, which gives 3000 extra if the translated value is longer if (keys.Count >= 99 || characterCount >= 7000) { //Create a new reference to the list with keys, because we need it non-cleared in the callback List <string> keysToSend = new List <string>(); keysToSend.AddRange(keysToSend.ToArray()); //Send the values smartLocWindow.MicrosoftTranslator.TranslateArray(textsToTranslate, translateFromLanguage, thisCultureInfo.Name, keysToSend, new TranslateCompleteArrayCallback(TranslatedTextArrayCompleted)); //Reset values characterCount = 0; keys.Clear(); textsToTranslate.Clear(); } } if (keys.Count != 0) { smartLocWindow.MicrosoftTranslator.TranslateArray(textsToTranslate, translateFromLanguage, thisCultureInfo.Name, keys, new TranslateCompleteArrayCallback(TranslatedTextArrayCompleted)); //Reset values characterCount = 0; keys.Clear(); textsToTranslate.Clear(); } } } else { GUILayout.Label(thisCultureInfo.EnglishName + " is not available for translation", EditorStyles.miniLabel); } } GUILayout.Label("Language Values", EditorStyles.boldLabel); //Search field EditorGUILayout.BeginHorizontal(); GUILayout.Label("Search for Key:", GUILayout.Width(100)); searchText = EditorGUILayout.TextField(searchText); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Key", EditorStyles.boldLabel, GUILayout.Width(120)); GUILayout.Label("Base Value", EditorStyles.boldLabel, GUILayout.Width(120)); GUILayout.Label("Copy Base", EditorStyles.miniLabel, GUILayout.Width(70)); if (canLanguageBeTranslated) { //TODO::Change to small picture GUILayout.Label("T", EditorStyles.miniLabel, GUILayout.Width(20)); } GUILayout.Label(thisLanguage + " Value", EditorStyles.boldLabel); EditorGUILayout.EndHorizontal(); //Check if the user searched for a value bool didSearch = false; if (searchText != "") { didSearch = true; GUILayout.Label("Search Results - \"" + searchText + "\":", EditorStyles.boldLabel); } //Start the scroll view scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); int iterationCount = 0; foreach (KeyValuePair <string, LocalizedObject> rootValue in rootValues) { if (didSearch) { //If the name of the key doesn't contain the search value, then skip a value if (!rootValue.Key.ToLower().Contains(searchText.ToLower())) { continue; } } if (rootValue.Value.ObjectType == LocalizedObjectType.STRING) { OnTextFieldGUI(rootValue, iterationCount); } else if (rootValue.Value.ObjectType == LocalizedObjectType.AUDIO) { OnAudioGUI(rootValue, iterationCount); } else if (rootValue.Value.ObjectType == LocalizedObjectType.GAME_OBJECT) { OnGameObjectGUI(rootValue, iterationCount); } else if (rootValue.Value.ObjectType == LocalizedObjectType.TEXTURE) { OnTextureGUI(rootValue, iterationCount); } iterationCount++; } //End the scroll view EditorGUILayout.EndScrollView(); if (guiChanged) { GUILayout.Label("- You have unsaved changes", EditorStyles.miniLabel); } //If any changes to the gui is made if (GUI.changed) { guiChanged = true; } GUILayout.Label("Save Changes", EditorStyles.boldLabel); GUILayout.Label("Remember to always press save when you have changed values", EditorStyles.miniLabel); if (GUILayout.Button("Save/Rebuild")) { //Copy everything into a dictionary Dictionary <string, string> newLanguageValues = new Dictionary <string, string>(); foreach (SerializableLocalizationObjectPair objectPair in this.thisLanguageValues) { if (objectPair.changedValue.ObjectType == LocalizedObjectType.STRING) { newLanguageValues.Add(objectPair.changedValue.GetFullKey(objectPair.keyValue), objectPair.changedValue.TextValue); } else { //Delete the file in case there was a file there previously LocFileUtility.DeleteFileFromResources(objectPair.changedValue.GetFullKey(objectPair.keyValue), thisCultureInfo); //Store the path to the file string pathValue = LocFileUtility.CopyFileIntoResources(objectPair, thisCultureInfo); newLanguageValues.Add(objectPair.changedValue.GetFullKey(objectPair.keyValue), pathValue); } } LocFileUtility.SaveLanguageFile(newLanguageValues, LocFileUtility.rootLanguageFilePath + "." + thisCultureInfo.Name + LocFileUtility.resXFileEnding); guiChanged = false; } undoManager.CheckDirty(); } else { //The root file did change, which means that you have to reload. A key might have changed //We can't have language files with different keys GUILayout.Label("The root file might have changed", EditorStyles.boldLabel); GUILayout.Label("The root file did save, which means that you have to reload. A key might have changed.", EditorStyles.miniLabel); GUILayout.Label("You can't have language files with different keys", EditorStyles.miniLabel); if (GUILayout.Button("Reload Language File")) { InitializeLanguage(thisCultureInfo, LocFileUtility.LoadParsedLanguageFile(null), LocFileUtility.LoadParsedLanguageFile(thisCultureInfo.Name)); } } } }
void OnGUI() { if (EditorWindowUtility.ShowWindow()) { GUILayout.Label("Settings", EditorStyles.boldLabel); if (!LocFileUtility.CheckIfRootLanguageFileExists()) { if (GUILayout.Button("Create New Localization System")) { LocFileUtility.CreateRootResourceFile(); } } else { undoManager.CheckUndo(); if (GUILayout.Button("Refresh")) { LocFileUtility.CheckAvailableLanguages(availableLanguages, notAvailableLanguages, notAvailableLanguagesEnglishNames); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Microsoft Translator Settings", EditorStyles.boldLabel, GUILayout.Width(200)); if (microsoftTranslator.IsInitialized) { GUILayout.Label(" - Authenticated!", EditorStyles.miniLabel); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Client ID:", GUILayout.Width(70)); mtCliendID = EditorGUILayout.TextField(mtCliendID); GUILayout.Label("Client Secret:", GUILayout.Width(100)); mtCliendSecret = EditorGUILayout.TextField(mtCliendSecret); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save", GUILayout.Width(50))) { SaveMicrosoftTranslatorSettings(); if (!microsoftTranslator.IsInitialized) { microsoftTranslator.GetAccessToken(mtCliendID, mtCliendSecret); } } if (!microsoftTranslator.IsInitialized) { if (GUILayout.Button("Authenticate!", GUILayout.Width(150))) { microsoftTranslator.GetAccessToken(mtCliendID, mtCliendSecret); } } keepTranslatorAuthenticated = EditorGUILayout.Toggle("Keep Authenticated", keepTranslatorAuthenticated); EditorGUILayout.EndHorizontal(); GUILayout.Label("Edit Root Language File", EditorStyles.boldLabel); if (GUILayout.Button("Edit")) { ShowRootEditWindow(LocFileUtility.LoadParsedLanguageFile(null)); } GUILayout.Label("Create new language", EditorStyles.boldLabel); chosenCreateNewCultureValue = EditorGUILayout.Popup(chosenCreateNewCultureValue, notAvailableLanguagesEnglishNames.ToArray()); if (GUILayout.Button("Create Language")) { CreateNewLanguage(notAvailableLanguagesEnglishNames[chosenCreateNewCultureValue]); } GUILayout.Label("Translate Languages", EditorStyles.boldLabel); //Start the scroll view scrollPosition = GUILayout.BeginScrollView(scrollPosition); bool languageDeleted = false; foreach (CultureInfo info in availableLanguages) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(info.EnglishName + " - " + info.Name)) { //Open language edit window ShowTranslateWindow(info); } if (GUILayout.Button("Delete", GUILayout.Width(60))) { LocFileUtility.DeleteLanguage(info); languageDeleted = true; break; } EditorGUILayout.EndHorizontal(); } if (languageDeleted) //Refresh { LocFileUtility.CheckAvailableLanguages(availableLanguages, notAvailableLanguages, notAvailableLanguagesEnglishNames); } //End the scroll view GUILayout.EndScrollView(); undoManager.CheckDirty(); } } }
public static void Select(Object asset) { EditorWindowUtility.ShowInspectorEditorWindow(); AssetDatabase.OpenAsset(asset); }
void OnGUI() { if (EditorWindowUtility.ShowWindow()) { undoManager.CheckUndo(); GUILayout.Label("Root Values", EditorStyles.boldLabel); //Search field EditorGUILayout.BeginHorizontal(); GUILayout.Label("Search for Key:", GUILayout.Width(100)); searchText = EditorGUILayout.TextField(searchText); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Key Type", GUILayout.Width(100)); GUILayout.Label("Key"); GUILayout.Label("Base Value/Comment"); GUILayout.Label("Delete", EditorStyles.miniLabel, GUILayout.Width(50)); EditorGUILayout.EndHorizontal(); //Create the scroll view scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); //Delete key information bool deleteKey = false; int indexToDelete = 0; //Check if the user searched for a value bool didSearch = false; if (searchText != "") { didSearch = true; GUILayout.Label("Search Results - \"" + searchText + "\":", EditorStyles.boldLabel); } for (int i = 0; i < changedRootKeys.Count; i++) { SerializableStringPair rootValue = changedRootKeys[i]; if (didSearch) { //If the name of the key doesn't contain the search value, then skip a value if (!rootValue.originalValue.ToLower().Contains(searchText.ToLower())) { continue; } } EditorGUILayout.BeginHorizontal(); //Popup of all the different key values changedRootValues[i].changedValue.ObjectType = (LocalizedObjectType)EditorGUILayout.Popup((int)changedRootValues[i].changedValue.ObjectType, keyTypes, GUILayout.Width(100)); rootValue.changedValue = EditorGUILayout.TextField(rootValue.changedValue); changedRootValues[i].changedValue.TextValue = EditorGUILayout.TextField(changedRootValues[i].changedValue.TextValue); if (GUILayout.Button("Delete", GUILayout.Width(50))) { deleteKey = true; indexToDelete = i; } EditorGUILayout.EndHorizontal(); } //End the scrollview EditorGUILayout.EndScrollView(); if (GUILayout.Button("Add New Key")) { AddNewKey(); } //Delete the key outside the foreach loop if (deleteKey) { DeleteKey(indexToDelete); } if (guiChanged) { GUILayout.Label("- You have unsaved changes", EditorStyles.miniLabel); } //If any changes to the gui is made if (GUI.changed) { guiChanged = true; } GUILayout.Label("Save Changes", EditorStyles.boldLabel); GUILayout.Label("Remember to always press save when you have changed values", EditorStyles.miniLabel); if (GUILayout.Button("Save Root Language File")) { Dictionary <string, string> changeNewRootKeys = new Dictionary <string, string>(); Dictionary <string, string> changeNewRootValues = new Dictionary <string, string>(); for (int i = 0; i < changedRootKeys.Count; i++) { SerializableStringPair rootKey = changedRootKeys[i]; SerializableLocalizationObjectPair rootValue = changedRootValues[i]; //Check for possible duplicates and rename them string newKeyValue = LocFileUtility.AddNewKeyPersistent(changeNewRootKeys, rootKey.originalValue, rootValue.changedValue.GetFullKey(rootKey.changedValue)); //Check for possible duplicates and rename them(same as above) LocFileUtility.AddNewKeyPersistent(changeNewRootValues, newKeyValue, rootValue.changedValue.TextValue); } //Add the full values before saving Dictionary <string, string> changeNewRootKeysToSave = new Dictionary <string, string>(); Dictionary <string, string> changeNewRootValuesToSave = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> rootKey in changeNewRootKeys) { LocalizedObject thisLocalizedObject = parsedRootValues[rootKey.Key]; changeNewRootKeysToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), rootKey.Value); changeNewRootValuesToSave.Add(thisLocalizedObject.GetFullKey(rootKey.Key), changeNewRootValues[rootKey.Key]); } LocFileUtility.SaveRootLanguageFile(changeNewRootKeysToSave, changeNewRootValuesToSave); //Fire the root language changed event if (OnRootFileChanged != null) { OnRootFileChanged(); } //Reload the window(in case of duplicate keys) SetRootValues(LocFileUtility.LoadParsedLanguageFile(null)); guiChanged = false; } undoManager.CheckDirty(); } }
public void _doLayoutScriptablesTable() { /////////////////////////////////////////////////////////////////// //MAKE THE TABLE ITEMS /////////////////////////////////////////////////////////////////// List <MonoScript> monoScriptsOfBaseManager = EditorWindowUtility.GetAllAssetMonoScriptsBySuperClassAndInterface(typeof(BaseManager)).ToList(); /* * Debug.Log ("ALL MONOSCRIPTS (MANY)" + monoScriptsOfBaseManager.Count); * foreach (MonoScript monoScript in monoScriptsOfBaseManager) { * * Debug.Log (" ms: " + monoScript.name); * * } */ List <ScriptableObject> scriptableObjectsOfBaseManager = EditorWindowUtility.GetAllObjectsBySuperClassAndInterface(typeof(BaseManager)).Cast <ScriptableObject>().ToList(); //Debug.Log ("ALL SCRIPTABLES (LESS) " + scriptableObjectsOfBaseManager.Count); foreach (ScriptableObject scriptableObject in scriptableObjectsOfBaseManager) { //Debug.Log (" so: " + scriptableObject); } //***************************************************** //***************************************************** //** HELP BOX //***************************************************** //***************************************************** //***************************************************** EditorGUI.indentLevel++; EditorGUILayout.HelpBox("Compatible? Your project has " + monoScriptsOfBaseManager.Count + " MonoScripts and " + scriptableObjectsOfBaseManager.Count + " ScriptableObjects", MessageType.Info); EditorGUI.indentLevel--; //EditorGUILayout.LabelField ("Scripts"); EditorGUI.indentLevel++; /////////////////////////////////////////////////////////////////// //MAKE THE TABLE HEADER /////////////////////////////////////////////////////////////////// // GUILayoutOption[] header1GUILayoutOptions = new GUILayoutOption[2]; header1GUILayoutOptions[0] = GUILayout.MaxWidth(250); header1GUILayoutOptions[1] = GUILayout.MinWidth(250); // GUILayoutOption[] header2GUILayoutOptions = new GUILayoutOption[2]; header2GUILayoutOptions[0] = GUILayout.MaxWidth(80); header2GUILayoutOptions[1] = GUILayout.MinWidth(80); // GUILayoutOption[] header3GUILayoutOptions = new GUILayoutOption[2]; header3GUILayoutOptions[0] = GUILayout.MaxWidth(80); header3GUILayoutOptions[1] = GUILayout.MinWidth(80); // GUILayoutOption[] header4GUILayoutOptions = new GUILayoutOption[2]; header4GUILayoutOptions[0] = GUILayout.MaxWidth(100); header4GUILayoutOptions[1] = GUILayout.MinWidth(100); // /// EditorGUILayout.BeginHorizontal(); EditorGUILayout.TextArea("NAME", EditorStyles.label, header1GUILayoutOptions); EditorGUILayout.TextArea("[STATUS]", EditorStyles.label, header2GUILayoutOptions); EditorGUILayout.TextArea("OPTION", EditorStyles.label, header3GUILayoutOptions); EditorGUILayout.TextArea("UPDATE()?", EditorStyles.label, header4GUILayoutOptions); EditorGUILayout.EndHorizontal(); //***************************************************** //***************************************************** //** LIST OF MANAGER CANDIDATES //***************************************************** //***************************************************** UMOMManagerCandidate managerCandidate; //SORT ALPHABETICALLY (MANUAL SORT NEEDED BECAUSE OUR LIST IS A GENERIC, I THINK) monoScriptsOfBaseManager.Sort ( delegate(MonoScript monoScript1, MonoScript monoScript2) { return(monoScript1.name.CompareTo(monoScript2.name)); } ); //LIST OUT foreach (MonoScript monoScript in monoScriptsOfBaseManager) { managerCandidate = UMOMManagerCandidate.FromMonoScriptAsset(monoScript, scriptableObjectsOfBaseManager, _managers_serializedproperty); managerCandidate.doLayoutGUI(); } //_getEditorPopupForIManagerScripts(); //EditorGUI.indentLevel --; // //EditorGUILayout.LabelField ("Assets"); //EditorGUI.indentLevel ++; //_getEditorPopupForIManagerAssets(); EditorGUI.indentLevel--; }