diff --git a/Assets/Adrenak.UPF/Runtime/Core/DynamicImage.cs b/Assets/Adrenak.UPF/Runtime/Core/DynamicImage.cs index 52a7d5f..e7b4d73 100644 --- a/Assets/Adrenak.UPF/Runtime/Core/DynamicImage.cs +++ b/Assets/Adrenak.UPF/Runtime/Core/DynamicImage.cs @@ -8,11 +8,12 @@ namespace Adrenak.UPF { [Serializable] public class DynamicImage : Image { public enum Source { + Asset, ResourcePath, RemotePath } - public enum Compression{ + public enum Compression { None, HighQuality, LowQuality @@ -20,7 +21,7 @@ public enum Compression{ Compression _oldCompression = Compression.LowQuality; [SerializeField] Compression _compression = Compression.LowQuality; - public Compression compression{ + public Compression compression { get => _compression; set { _compression = value; @@ -35,7 +36,7 @@ public Source source { get => _source; set { _source = value; - if(NeedsRefresh()) + if (NeedsRefresh()) Refresh(); } } @@ -53,19 +54,30 @@ public string path { [ContextMenu("Refresh")] public void Refresh() { - if (_oldSource == source) { - - } switch (source) { + case Source.Asset: + break; + case Source.ResourcePath: + if (string.IsNullOrWhiteSpace(path)) { + Debug.LogWarning("Source path is null or whitespace"); + break; + } + var resourceSprite = Resources.Load(path); - if(resourceSprite == null){ + if (resourceSprite == null) { Debug.LogError($"Not Resource found at {path}"); break; } SetSprite(resourceSprite); break; + case Source.RemotePath: + if (string.IsNullOrWhiteSpace(path)) { + Debug.LogWarning("Source path is null or whitespace"); + break; + } + try { DownloadSprite(path, result => SetSprite(result), @@ -85,10 +97,10 @@ bool NeedsRefresh() { if (_oldCompression != compression) result = true; - if (_oldSource != source) + if (_oldSource != source) result = true; - if(!_oldPath.Equals(path)) + if (!_oldPath.Equals(path)) result = true; _oldCompression = compression; @@ -100,7 +112,7 @@ bool NeedsRefresh() { void SetSprite(Sprite s) { if (sprite != null) { var id = sprite.GetInstanceID(); - if(id < 0){ + if (id < 0) { if (Application.isPlaying) { Destroy(sprite.texture); Destroy(sprite); @@ -132,7 +144,7 @@ IEnumerator DownloadSpriteCo(string path, Action onSuccess, Action