private void AddCallbackToReordableList(ReorderableList reorderableList) { reorderableList.drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, $"{Strings.Dictionary} ({reorderableList.count})"); }; reorderableList.elementHeightCallback = (index) => { if (IndiceIsInShowingRange(index)) { return(EditorGUI.GetPropertyHeight(reorderableList.serializedProperty.GetArrayElementAtIndex(index))); } return(0); }; reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (IndiceIsInShowingRange(index)) { currentKey = reorderableList.serializedProperty.GetArrayElementAtIndex(index); error = CodeGenerationUtils.CheckIdentifier(currentKey.stringValue); EditorGUI.PropertyField(rect, currentKey, GUIContent.none); var show = !string.IsNullOrEmpty(error) && error != CodeGenerationUtils.EMPTY_FIELD_NAME_ERROR; EditorUtils.ShowMessage(string.Format(Strings.InvalidKeyName, currentKey.stringValue), MessageType.Error, show); } }; }
private bool HasErrorInKeys(List <string> keys) { var result = false; for (int i = 0; i < keys.Count; i++) { if (script.StringKeys.Count(it => it == keys[i]) > 1) { Debugger.LogError(string.Format(Strings.KeyDuplication, keys[i])); result = true; continue; } if (!string.IsNullOrEmpty(CodeGenerationUtils.CheckIdentifier(keys[i]))) { Debugger.LogError(string.Format(Strings.InvalidKeyName, keys[i])); result = true; } } return(result); }
private string Load() { var type = PrefabUtility.GetPrefabType(script.gameObject); if (type != PrefabType.None && type != PrefabType.PrefabInstance) { return(Strings.ImportError); } XmlDocument doc = null; XmlNode resourceNode = null; string path = string.Empty; string key = string.Empty; string value = string.Empty; bool hasError = false; bool isFirstFile = true; List <string> keyList = new List <string>(); List <LocalizedLanguage> existingLanguages = new List <LocalizedLanguage>(); List <StringKV> keyValues; LocalizedLanguage currentLoadedLanguage; foreach (var language in LanguageEnumNames) { path = Path.Combine(Application.dataPath, string.Format(ISILocalization.LanguagePaths, language)); if (File.Exists(path)) { keyValues = new List <StringKV>(); doc = new XmlDocument(); using (var stream = new FileStream(path, FileMode.Open)) { doc.Load(stream); stream.Close(); } // get all xml nodes child of the node 'resources' resourceNode = doc["resources"]; var index = 1; // remove xml comments var children = resourceNode.ChildNodes.Cast <XmlNode>().Where(n => n.NodeType != XmlNodeType.Comment); foreach (XmlNode node in children) { key = node.Attributes[0].Value; value = node.FirstChild == null ? "" : node.FirstChild.Value; keyValues.Add(new StringKV(key, value)); if (isFirstFile) { keyList.Add(key); } error = CodeGenerationUtils.CheckIdentifier(key); if (error != null) { hasError = true; Debugger.LogError(string.Format(Strings.InvalidKeyName, key)); } index++; } isFirstFile = false; currentLoadedLanguage = new LocalizedLanguage(keyValues); currentLoadedLanguage.Language = (Language)Enum.Parse(typeof(Language), language); existingLanguages.Add(currentLoadedLanguage); } } if (keyList.Any()) { if (!hasError) { script.StringKeys.Clear(); foreach (var k in keyList) { script.StringKeys.Add(k); } foreach (var language in existingLanguages) { script.ReplaceLocalizedLanguage(language); } Generate(); PrefabUtility.CreatePrefab(ISILocalization.PrefabPath, script.gameObject); AssetDatabase.Refresh(); return(Strings.Updated); } else { return(Strings.CheckErrors); } } else { return(Strings.MissingLanguage); } }