示例#1
0
        private static MonoBehaviour SetupForFontLocalization(TextMeshProUGUI target)
        {
            //Avoid adding the component multiple times
            if (target.GetComponent <LocalizeTMProFontEvent>() != null)
            {
                return(null);
            }

            var comp           = Undo.AddComponent(target.gameObject, typeof(LocalizeTMProFontEvent)) as LocalizeTMProFontEvent;
            var setFontMethod  = target.GetType().GetProperty("font").GetSetMethod();
            var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction <TMP_FontAsset>), target, setFontMethod) as UnityAction <TMP_FontAsset>;

            Events.UnityEventTools.AddPersistentListener(comp.OnUpdateAsset, methodDelegate);

            //Find font table and set it up automatically
            var collections = LocalizationEditorSettings.GetAssetTableCollections();

            foreach (var tableCollection in collections)
            {
                if (tableCollection.name == "Fonts")
                {
                    comp.AssetReference.TableReference = tableCollection.TableCollectionNameReference;
                    foreach (var entry in tableCollection.SharedData.Entries)
                    {
                        if (entry.Key == "font")
                        {
                            comp.AssetReference.TableEntryReference = entry.Id;
                        }
                    }
                }
            }

            return(null);
        }
示例#2
0
        private void Reset()
        {
            //Set up Unity Event automatically
            var target         = GetComponent <TextMeshProUGUI>();
            var setFontMethod  = target.GetType().GetProperty("font").GetSetMethod();
            var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction <TMP_FontAsset>), target, setFontMethod) as UnityAction <TMP_FontAsset>;

            UnityEditor.Events.UnityEventTools.AddPersistentListener(this.OnUpdateAsset, methodDelegate);

            //Set up font localize asset table automatically
            var collections = LocalizationEditorSettings.GetAssetTableCollections();

            foreach (var tableCollection in collections)
            {
                if (tableCollection.name == "Fonts")
                {
                    this.AssetReference.TableReference = tableCollection.TableCollectionNameReference;
                    foreach (var entry in tableCollection.SharedData.Entries)
                    {
                        if (entry.Key == "font")
                        {
                            this.AssetReference.TableEntryReference = entry.Id;
                        }
                    }
                }
            }
        }
示例#3
0
        protected override TreeViewItem BuildRoot()
        {
            var root = new TreeViewItem(-1, -1);
            var id   = 1;

            root.AddChild(new TableEntryTreeViewItem(null, null, id++, 0)
            {
                displayName = $"None ({m_AssetType.Name})"
            });

            if (m_AssetType == typeof(string))
            {
                var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
                foreach (var collection in stringTableCollections)
                {
                    var tableNode = new TreeViewItem(id++, 0, collection.TableCollectionName)
                    {
                        icon = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(collection)) as Texture2D
                    };
                    root.AddChild(tableNode);

                    var sharedData = collection.SharedData;
                    foreach (var entry in sharedData.Entries)
                    {
                        tableNode.AddChild(new TableEntryTreeViewItem(collection, entry, id++, 1));
                    }
                }
            }
            else
            {
                var assetTableCollections = LocalizationEditorSettings.GetAssetTableCollections();
                foreach (var collection in assetTableCollections)
                {
                    var tableNode = new TreeViewItem(id++, 0, collection.TableCollectionName)
                    {
                        icon = AssetDatabase.GetCachedIcon(AssetDatabase.GetAssetPath(collection)) as Texture2D
                    };
                    root.AddChild(tableNode);

                    // Only show keys that have a compatible type.
                    var sharedData = collection.SharedData;
                    foreach (var entry in sharedData.Entries)
                    {
                        var typeMetadata = entry.Metadata.GetMetadata <AssetTypeMetadata>();
                        if (typeMetadata == null || m_AssetType.IsAssignableFrom(typeMetadata.Type))
                        {
                            tableNode.AddChild(new TableEntryTreeViewItem(collection, entry, id++, 1));
                        }
                    }
                }
            }

            if (!root.hasChildren)
            {
                root.AddChild(new TreeViewItem(1, 0, "No Tables Found."));
            }

            return(root);
        }
示例#4
0
        internal protected virtual List <LocalizationTableCollection> GetCollections()
        {
            var tableCollections = new List <LocalizationTableCollection>();

            if (m_TableType == typeof(StringTable))
            {
                tableCollections.AddRange(LocalizationEditorSettings.GetStringTableCollections());
            }
            else
            {
                tableCollections.AddRange(LocalizationEditorSettings.GetAssetTableCollections());
            }
            return(tableCollections);
        }
        public void Initialize(bool defaultSelectState = true)
        {
            m_ContentContainer.Clear();

            if (VisibleType.HasFlag(CollectionType.String))
            {
                var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
                foreach (var collection in stringTableCollections)
                {
                    AddCollection(collection, defaultSelectState);
                }
            }

            if (VisibleType.HasFlag(CollectionType.Asset))
            {
                var assetTableCollections = LocalizationEditorSettings.GetAssetTableCollections();
                foreach (var collection in assetTableCollections)
                {
                    AddCollection(collection, defaultSelectState);
                }
            }
        }
示例#6
0
 internal protected virtual ReadOnlyCollection <AssetTableCollection> GetAssetTableCollections() => LocalizationEditorSettings.GetAssetTableCollections();