protected override TreeViewItem BuildRoot() { var root = new TreeViewItem(-1, -1); int id = 1; root.AddChild(new LocalizedAssetRefTreeViewItem(null, null, id++, 0) { displayName = "None" }); var tables = LocalizationPlayerSettings.GetAssetTables <StringTableBase>(); foreach (var table in tables) { var keys = table.GetKeys(); var tableNode = new TreeViewItem(id++, 0, table.TableName); tableNode.icon = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(table.Tables[0])) as Texture2D; root.AddChild(tableNode); foreach (var key in keys) { tableNode.AddChild(new LocalizedAssetRefTreeViewItem(table, key, id++, 1)); } } if (!root.hasChildren) { root.AddChild(new TreeViewItem(1, 0, "No String Tables Found.")); } return(root); }
static void LocalizeUIText(MenuCommand command) { var target = command.context as Text; var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeString)) as LocalizeString; var setStringMethod = target.GetType().GetProperty("text").GetSetMethod(); var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction <string>), target, setStringMethod) as UnityAction <string>; Events.UnityEventTools.AddPersistentListener(comp.UpdateString, methodDelegate); // Check if we can find a matching key to the text value var tables = LocalizationPlayerSettings.GetAssetTables <StringTableBase>(); foreach (var assetTableCollection in tables) { var keys = assetTableCollection.GetKeys(); if (keys.Contains(target.text)) { comp.StringReference.Key = target.text; comp.StringReference.TableName = assetTableCollection.TableName; return; } } }