浏览代码
Merge branch 'image_updates' into 'master'
Merge branch 'image_updates' into 'master'
add image resolution. See merge request upm-packages/ui-widgets/com.unity.uiwidgets!4/main
Fan Zhang
6 年前
当前提交
6dad37a9
共有 11 个文件被更改,包括 230 次插入 和 24 次删除
-
4Runtime/painting/decoration_image.cs
-
33Runtime/painting/image_provider.cs
-
2Runtime/ui/painting/GifDecoder.cs
-
2Runtime/ui/painting/canvas_impl.cs
-
4Runtime/ui/painting/codec.cs
-
41Runtime/ui/painting/image.cs
-
2Runtime/ui/painting/painting.cs
-
36Runtime/widgets/image.cs
-
18Tests/Editor/Widgets.cs
-
101Runtime/painting/image_resolution.cs
-
11Runtime/painting/image_resolution.cs.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using RSG; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using UnityEngine; |
|||
using Object = UnityEngine.Object; |
|||
using Path = System.IO.Path; |
|||
|
|||
namespace Unity.UIWidgets.painting { |
|||
public class AssetImage : AssetBundleImageProvider, IEquatable<AssetImage> { |
|||
public AssetImage(string assetName, |
|||
AssetBundle bundle = null) { |
|||
D.assert(assetName != null); |
|||
this.assetName = assetName; |
|||
this.bundle = bundle; |
|||
} |
|||
|
|||
public readonly string assetName; |
|||
public readonly AssetBundle bundle; |
|||
|
|||
protected override |
|||
IPromise<AssetBundleImageKey> obtainKey(ImageConfiguration configuration) { |
|||
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); |
|||
return (AssetBundleImageKey) result; |
|||
}); |
|||
} |
|||
|
|||
IEnumerator _loadAssetAsync(AssetBundle bundle, double devicePixelRatio) { |
|||
var extension = Path.GetExtension(this.assetName); |
|||
var name = Path.GetFileNameWithoutExtension(this.assetName); |
|||
|
|||
var upper = devicePixelRatio.ceil(); |
|||
for (var scale = upper; scale >= 1; scale--) { |
|||
var assetName = name + "@" + scale + extension; |
|||
|
|||
Object asset; |
|||
if (bundle == null) { |
|||
ResourceRequest request = Resources.LoadAsync(assetName); |
|||
yield return request; |
|||
asset = request.asset; |
|||
} else { |
|||
AssetBundleRequest request = bundle.LoadAssetAsync(assetName); |
|||
yield return request; |
|||
asset = request.asset; |
|||
} |
|||
|
|||
if (asset != null) { |
|||
yield return new AssetBundleImageKey( |
|||
bundle, |
|||
assetName, |
|||
scale: scale |
|||
); |
|||
yield break; |
|||
} |
|||
} |
|||
|
|||
yield return new AssetBundleImageKey( |
|||
bundle, |
|||
this.assetName, |
|||
scale: 1.0 |
|||
); |
|||
} |
|||
|
|||
public bool Equals(AssetImage other) { |
|||
if (ReferenceEquals(null, other)) return false; |
|||
if (ReferenceEquals(this, other)) return true; |
|||
return string.Equals(this.assetName, other.assetName) && Equals(this.bundle, other.bundle); |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (ReferenceEquals(null, obj)) return false; |
|||
if (ReferenceEquals(this, obj)) return true; |
|||
if (obj.GetType() != this.GetType()) return false; |
|||
return this.Equals((AssetImage) obj); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
return ((this.assetName != null ? this.assetName.GetHashCode() : 0) * 397) ^ (this.bundle != null ? this.bundle.GetHashCode() : 0); |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(AssetImage left, AssetImage right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(AssetImage left, AssetImage right) { |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return $"{this.GetType()}(bundle: {this.bundle}, name: \"{this.assetName}\")"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 10deadb7160304e88ae6468d43429bbe |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue