示例#1
0
        public void Initialize(ILogger logger, string gameRoot)
        {
            if (GameVersion < MIN_SUPPORTED_VERSION)
            {
                logger.LogWarning(
                    $"This version of i18nEx core supports only game versions {MIN_SUPPORTED_VERSION} or newer. Detected game version: {GameVersion}");
                Destroy(this);
                return;
            }

            if (Initialized)
            {
                return;
            }

            Logger = logger;
            Logger.LogInfo("Initializing i18nEx...");

            Paths.Initialize(gameRoot);
            InitializeTranslationManagers();
            TranslationHooks.Initialize();

            Logger.LogInfo("i18nEx initialized!");
            Initialized = true;
        }
        private void TranslateExisting(bool levelChanged = false)
        {
            isRetranslating = !levelChanged && Settings.EnableTranslationReload;
            var processedTextures = new HashSet<string>();
            foreach (var widget in FindObjectsOfType<UIWidget>())
                if (widget is UILabel label)
                {
                    processAndRequest(label);
                }
                else
                {
                    string texName = widget.mainTexture?.name;
                    if (string.IsNullOrEmpty(texName) || processedTextures.Contains(texName))
                        continue;
                    processedTextures.Add(texName);

                    switch (widget)
                    {
                        case UI2DSprite sprite:
                            TranslationHooks.OnAssetTextureLoad(1, sprite);
                            break;
                        case UITexture tex:
                            TranslationHooks.OnAssetTextureLoad(1, tex);
                            break;
                        default:
                            TranslationHooks.OnAssetTextureLoad(1, widget);
                            break;
                    }
                }

            isRetranslating = false;

            foreach (var graphic in FindObjectsOfType<MaskableGraphic>())
            {
                if (graphic is Image img && img.sprite != null)
                    if (img.sprite.name.StartsWith("!"))
                        img.sprite.name = img.sprite.name.Substring(1);
                TranslationHooks.OnTranslateGraphic(graphic);
            }
        }
        private void TranslateExisting(bool levelChanged = false)
        {
            isRetranslating = !levelChanged && Settings.EnableStringReload;
            HashSet <string> processedTextures = new HashSet <string>();

            foreach (UIWidget widget in FindObjectsOfType <UIWidget>())
            {
                if (widget is UILabel label)
                {
                    processAndRequest(label);
                }
                else
                {
                    string texName = widget.mainTexture?.name;
                    if (string.IsNullOrEmpty(texName) || processedTextures.Contains(texName))
                    {
                        continue;
                    }
                    processedTextures.Add(texName);
                    TranslationHooks.OnAssetTextureLoad(1, widget);
                }
            }
            isRetranslating = false;

            foreach (MaskableGraphic graphic in FindObjectsOfType <MaskableGraphic>())
            {
                if (graphic is Image img && img.sprite != null)
                {
                    if (img.sprite.name.StartsWith("!"))
                    {
                        img.sprite.name = img.sprite.name.Substring(1);
                    }
                }
                TranslationHooks.OnTranslateGraphic(graphic);
            }
        }