public override void LoadAllFileListAsync(Action <LocalizationFile[]> complete)
        {
            if (complete != null)
            {
                string bundlePath = Path.Combine(Application.streamingAssetsPath, FilesPath, FilesPath);

                var loadrequest = AssetBundle.LoadFromFileAsync(bundlePath);
                loadrequest.completed += operation =>
                {
                    AssetBundleManifest manifest =
                        loadrequest.assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                    var files = manifest.GetAllAssetBundles();

                    List <LocalizationFile> fileList = new List <LocalizationFile>();
                    for (int i = 0; i < files.Length; i++)
                    {
                        if (!files[i].Equals(CommonAssetsPath.ToLower()))
                        {
                            LocalizationFile data = new LocalizationFile(files[i]);
                            fileList.Add(data);
                        }
                    }

                    loadrequest.assetBundle.Unload(manifest);
                    complete(fileList.ToArray());
                };
            }
        }
        private void OnLocalizationChanged(LocalizationFile localizationFile)
        {
            if (text == null)
            {
                text = GetComponent <TextMesh>();
            }
            if (text != null)
            {
                string value = LocalizationManager.Singleton.GetLocalizedText(localizationKey);
                if (value == null)
                {
                    value = defaultValue;
                }

                text.text = value;
            }
        }
        public override void LoadAllFileListAsync(Action <LocalizationFile[]> complete)
        {
            if (complete != null)
            {
                TextAsset[]             res      = Resources.LoadAll <TextAsset>(FilesPath);
                List <LocalizationFile> fileList = new List <LocalizationFile>();

                for (int i = 0; i < res.Length; i++)
                {
                    TextAsset        asset = res[i];
                    LocalizationFile data  = new LocalizationFile(asset.name);
                    fileList.Add(data);
                    Resources.UnloadAsset(asset);
                }
                complete(fileList.ToArray());
            }
        }
 public override void LoadAllFileListAsync(Action <LocalizationFile[]> complete)
 {
     if (complete != null)
     {
         Addressables.LoadResourceLocationsAsync(KLocalizeFolder).Completed += handle =>
         {
             List <LocalizationFile> fileList = new List <LocalizationFile>();
             if (handle.Status == AsyncOperationStatus.Succeeded)
             {
                 foreach (var file in handle.Result)
                 {
                     LocalizationFile data = new LocalizationFile(file.PrimaryKey);
                     fileList.Add(data);
                 }
             }
             complete(fileList.ToArray());
         };
     }
 }
        private void OnLocalizationChanged(LocalizationFile localizationFile)
        {
            if (spriteRenderer == null)
            {
                spriteRenderer = GetComponent <SpriteRenderer>();
            }
            if (spriteRenderer != null)
            {
                string value = LocalizationManager.Singleton.GetLocalizedText(localizationKey);
                if (value == null)
                {
                    value = defaultValue;
                }

                LocalizationManager.Singleton.LoadLocalizationAssetAsync(value, defaultValue,
                                                                         delegate(Sprite sprite)
                {
                    if (sprite != null)
                    {
                        spriteRenderer.sprite = sprite;
                    }
                });
            }
        }
Ejemplo n.º 6
0
        private void OnLocalizationChanged(LocalizationFile localizationFile)
        {
            if (image == null)
            {
                image = GetComponent <Image>();
            }
            if (image != null)
            {
                if (_originalImageSize == Vector2.zero)
                {
                    _originalImageSize = image.rectTransform.sizeDelta;
                }
                string value = LocalizationManager.Singleton.GetLocalizedText(localizationKey);
                if (value == null)
                {
                    value = defaultValue;
                }

                LocalizationManager.Singleton.LoadLocalizationAssetAsync(value, defaultValue,
                                                                         delegate(Sprite sprite)
                {
                    if (sprite != null)
                    {
                        image.sprite = sprite;
                        if (setNativeSize)
                        {
                            image.SetNativeSize();
                        }
                        else
                        {
                            image.rectTransform.sizeDelta = _originalImageSize;
                        }
                    }
                });
            }
        }
Ejemplo n.º 7
0
        private void OnLocalizationChanged(LocalizationFile localizationFile)
        {
            _currentLanguage = localizationFile.Type;
            foreach (var item in items)
            {
                if (!string.IsNullOrEmpty(item.localizationKey) && item.component != null)
                {
                    string value = LocalizationManager.Singleton.GetLocalizedText(item.localizationKey);
                    if (value == null)
                    {
                        value = item.defaultValue;
                    }

                    if (item.component is Text text)
                    {
                        text.text = value;
                    }
                    else if (item.component is TextMesh mesh)
                    {
                        mesh.text = value;
                    }
                    else
                    {
                        Image          image          = item.component as Image;
                        SpriteRenderer spriteRenderer = item.component as SpriteRenderer;

                        if (image != null)
                        {
                            if (item.originalImageSize == Vector2.zero)
                            {
                                item.originalImageSize = image.rectTransform.sizeDelta;
                            }
                        }

                        if (image != null || spriteRenderer != null)
                        {
                            //替换图片
                            LocalizationManager.Singleton.LoadLocalizationAssetAsync(value, item.defaultValue,
                                                                                     delegate(Sprite sprite)
                            {
                                if (sprite != null)
                                {
                                    if (image != null)
                                    {
                                        image.sprite = sprite;
                                        if (item.setNativeSize)
                                        {
                                            image.SetNativeSize();
                                        }
                                        else
                                        {
                                            image.rectTransform.sizeDelta = item.originalImageSize;
                                        }
                                    }

                                    if (spriteRenderer != null)
                                    {
                                        spriteRenderer.sprite = sprite;
                                    }
                                }
                            });
                        }
                    }
                }
            }
        }