public void ClearChangeHandler_DoesNotThrowException_WhenCompletedWasNotUsed()
        {
            var localizedTexture = new LocalizedTexture
            {
                CurrentLoadingOperation = Addressables.ResourceManager.CreateCompletedOperation((Texture)Texture2D.whiteTexture, null)
            };

            Assert.DoesNotThrow(() => localizedTexture.ClearChangeHandler());
        }
示例#2
0
        public void SettingAssetReference_TriggersUpdate()
        {
            const string tableName = "SettingAssetReference Table Collection Name";
            const string entryName = "SettingAssetReference Entry Name";

            var newAssetReference = new LocalizedTexture()
            {
                TableReference = tableName, TableEntryReference = entryName
            };

            m_LocalizeTextureEvent.AssetReference = newAssetReference;
            CheckEntryWasRequested(tableName, entryName);
        }
示例#3
0
        static void GenerateLocalizedIcon(string filePath, Locale locale, LocalizedTexture localizedTexture)
        {
            if (localizedTexture.IsEmpty)
            {
                return;
            }

            var tableCollection = LocalizationEditorSettings.GetAssetTableCollection(localizedTexture.TableReference);
            var table           = tableCollection?.GetTable(locale.Identifier) as AssetTable;
            var entry           = table?.GetEntryFromReference(localizedTexture.TableEntryReference);

            if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizedValue))
            {
                var fallBack = FallbackLocaleHelper.GetLocaleFallback(locale);
                if (fallBack != null)
                {
                    GenerateLocalizedIcon(filePath, fallBack, localizedTexture);
                    return;
                }

                Debug.LogWarning($"Could not find a localized Icons for {locale} from {localizedTexture}");
                return;
            }
            var iconPath = AssetDatabase.GUIDToAssetPath(entry.Guid);

            if (string.IsNullOrEmpty(iconPath))
            {
                return;
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var texture = AssetDatabase.LoadAssetAtPath(iconPath, typeof(Texture2D)) as Texture2D;

            byte[] bytes = texture.EncodeToPNG();

            //Saving the Icon as ".png" file to gradle res folder
            File.WriteAllBytes(filePath, bytes);
        }
示例#4
0
 void ChangeTexture(LocalizedTexture texture)
 {
     // When we assign a new AssetReference the system will automatically load the new Sprite asset then call the AssetChanged event.
     localizeTextureEvent.AssetReference = texture;
 }