|
|
|
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.Text; |
|
|
|
using Unity.UIWidgets.async2; |
|
|
|
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Networking; |
|
|
|
using Codec = Unity.UIWidgets.ui.Codec; |
|
|
|
using Image = Unity.UIWidgets.ui.Image; |
|
|
|
using Window = Unity.UIWidgets.ui.Window; |
|
|
|
|
|
|
|
namespace Unity.UIWidgets.painting { |
|
|
|
public static partial class painting_ { |
|
|
|
|
|
|
|
|
|
|
public static ImageProvider resizeIfNeeded(int? cacheWidth, int? cacheHeight, ImageProvider provider) { |
|
|
|
if (cacheWidth != null || cacheHeight != null) { |
|
|
|
return new ResizeImage((ImageProvider<object>) provider, width: cacheWidth.Value, height: cacheHeight.Value); |
|
|
|
return new ResizeImage((ImageProvider<object>) provider, width: cacheWidth.Value, |
|
|
|
height: cacheHeight.Value); |
|
|
|
} |
|
|
|
|
|
|
|
return provider; |
|
|
|
|
|
|
var completer = Completer.create(); |
|
|
|
var isolate = Isolate.current; |
|
|
|
var panel = UIWidgetsPanel.current; |
|
|
|
panel.StartCoroutine(_loadCoroutine(key.url, completer, isolate)); |
|
|
|
return completer.future.to<byte[]>().then_<byte[]>(data => { |
|
|
|
if (data != null && data.Length > 0) { |
|
|
|
return decode(data); |
|
|
|
} |
|
|
|
if (panel.IsActive()) { |
|
|
|
panel.StartCoroutine(_loadCoroutine(key.url, completer, isolate)); |
|
|
|
return completer.future.to<byte[]>().then_<byte[]>(data => { |
|
|
|
if (data != null && data.Length > 0) { |
|
|
|
return decode(data); |
|
|
|
} |
|
|
|
throw new Exception("not loaded"); |
|
|
|
}).to<Codec>(); |
|
|
|
throw new Exception("not loaded"); |
|
|
|
}).to<Codec>(); |
|
|
|
} |
|
|
|
|
|
|
|
return new Future<Codec>(Future.create(() => FutureOr.value(null))); |
|
|
|
} |
|
|
|
|
|
|
|
IEnumerator _loadCoroutine(string key, Completer completer, Isolate isolate) { |
|
|
|