|
|
|
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using Unity.UIWidgets.async; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using Unity.UIWidgets.ui; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
public readonly string assetName; |
|
|
|
public readonly AssetBundle bundle; |
|
|
|
|
|
|
|
protected override |
|
|
|
IPromise<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) { |
|
|
|
protected override IPromise<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) { |
|
|
|
AssetImageConfiguration assetConfig = new AssetImageConfiguration(configuration, this.assetName); |
|
|
|
AssetBundleImageKey key; |
|
|
|
var cache = AssetBundleCache.instance.get(configuration.bundle); |
|
|
|
|
|
|
|
|
|
|
AssetBundle chosenBundle = this.bundle ? this.bundle : configuration.bundle; |
|
|
|
var devicePixelRatio = configuration.devicePixelRatio ?? Window.instance.devicePixelRatio; |
|
|
|
var coroutine = Window.instance.startCoroutine(this._loadAssetAsync(chosenBundle, devicePixelRatio)); |
|
|
|
return coroutine.promise.Then(result => { |
|
|
|
D.assert(result != null); |
|
|
|
|
|
|
|
key = (AssetBundleImageKey) result; |
|
|
|
cache[assetConfig] = key; |
|
|
|
return key; |
|
|
|
}); |
|
|
|
key = this._loadAsset(chosenBundle, devicePixelRatio); |
|
|
|
cache[assetConfig] = key; |
|
|
|
|
|
|
|
return Promise<AssetBundleImageKey>.Resolved(key); |
|
|
|
IEnumerator _loadAssetAsync(AssetBundle bundle, float devicePixelRatio) { |
|
|
|
AssetBundleImageKey _loadAsset(AssetBundle bundle, float devicePixelRatio) { |
|
|
|
var upper = devicePixelRatio.ceil(); |
|
|
|
var upper = Mathf.Min(3, devicePixelRatio.ceil()); |
|
|
|
ResourceRequest request = Resources.LoadAsync(assetName); |
|
|
|
yield return request; |
|
|
|
asset = request.asset; |
|
|
|
} |
|
|
|
else { |
|
|
|
AssetBundleRequest request = bundle.LoadAssetAsync(assetName); |
|
|
|
yield return request; |
|
|
|
asset = request.asset; |
|
|
|
asset = Resources.Load(assetName); |
|
|
|
} else { |
|
|
|
asset = bundle.LoadAsset(assetName); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
yield return new AssetBundleImageKey( |
|
|
|
return new AssetBundleImageKey( |
|
|
|
yield break; |
|
|
|
yield return new AssetBundleImageKey( |
|
|
|
return new AssetBundleImageKey( |
|
|
|
bundle, |
|
|
|
this.assetName, |
|
|
|
scale: 1.0f |
|
|
|