mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
设置图片支持CancellationToken取消
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using TEngine;
|
using System.Threading;
|
||||||
|
using TEngine;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -10,9 +11,10 @@ public static class SetSpriteExtensions
|
|||||||
/// <param name="image">UI/Image。</param>
|
/// <param name="image">UI/Image。</param>
|
||||||
/// <param name="location">资源定位地址。</param>
|
/// <param name="location">资源定位地址。</param>
|
||||||
/// <param name="setNativeSize">是否使用原始分辨率。</param>
|
/// <param name="setNativeSize">是否使用原始分辨率。</param>
|
||||||
public static void SetSprite(this Image image, string location, bool setNativeSize = false)
|
/// <param name="cancellationToken">取消设置资源的Token。</param>
|
||||||
|
public static void SetSprite(this Image image, string location, bool setNativeSize = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ResourceExtComponent.Instance.SetAssetByResources<Sprite>(SetSpriteObject.Create(image, location, setNativeSize)).Forget();
|
ResourceExtComponent.Instance.SetAssetByResources<Sprite>(SetSpriteObject.Create(image, location, setNativeSize, cancellationToken)).Forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -20,8 +22,9 @@ public static class SetSpriteExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteRenderer">2D/SpriteRender。</param>
|
/// <param name="spriteRenderer">2D/SpriteRender。</param>
|
||||||
/// <param name="location">资源定位地址。</param>
|
/// <param name="location">资源定位地址。</param>
|
||||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string location)
|
/// <param name="cancellationToken">取消设置资源的Token。</param>
|
||||||
|
public static void SetSprite(this SpriteRenderer spriteRenderer, string location, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ResourceExtComponent.Instance.SetAssetByResources<Sprite>(SetSpriteObject.Create(spriteRenderer, location)).Forget();
|
ResourceExtComponent.Instance.SetAssetByResources<Sprite>(SetSpriteObject.Create(spriteRenderer, location, cancellationToken)).Forget();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
@@ -41,10 +42,15 @@ namespace TEngine
|
|||||||
|
|
||||||
private bool _setNativeSize = false;
|
private bool _setNativeSize = false;
|
||||||
|
|
||||||
|
private CancellationToken _cancellationToken;
|
||||||
|
|
||||||
public void SetAsset(Object asset)
|
public void SetAsset(Object asset)
|
||||||
{
|
{
|
||||||
_sprite = (Sprite)asset;
|
_sprite = (Sprite)asset;
|
||||||
|
|
||||||
|
if (_cancellationToken.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_image != null)
|
if (_image != null)
|
||||||
{
|
{
|
||||||
_image.sprite = _sprite;
|
_image.sprite = _sprite;
|
||||||
@@ -84,21 +90,23 @@ namespace TEngine
|
|||||||
_setNativeSize = false;
|
_setNativeSize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SetSpriteObject Create(Image image, string location, bool setNativeSize = false)
|
public static SetSpriteObject Create(Image image, string location, bool setNativeSize = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
SetSpriteObject item = MemoryPool.Acquire<SetSpriteObject>();
|
SetSpriteObject item = MemoryPool.Acquire<SetSpriteObject>();
|
||||||
item._image = image;
|
item._image = image;
|
||||||
item._setNativeSize = setNativeSize;
|
item._setNativeSize = setNativeSize;
|
||||||
item.Location = location;
|
item.Location = location;
|
||||||
|
item._cancellationToken = cancellationToken;
|
||||||
item._setType = SetType.Image;
|
item._setType = SetType.Image;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SetSpriteObject Create(SpriteRenderer spriteRenderer, string location)
|
public static SetSpriteObject Create(SpriteRenderer spriteRenderer, string location, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
SetSpriteObject item = MemoryPool.Acquire<SetSpriteObject>();
|
SetSpriteObject item = MemoryPool.Acquire<SetSpriteObject>();
|
||||||
item._spriteRenderer = spriteRenderer;
|
item._spriteRenderer = spriteRenderer;
|
||||||
item.Location = location;
|
item.Location = location;
|
||||||
|
item._cancellationToken = cancellationToken;
|
||||||
item._setType = SetType.SpriteRender;
|
item._setType = SetType.SpriteRender;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user