mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
设置图片支持CancellationToken取消
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using TEngine;
|
||||
using System.Threading;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -10,9 +11,10 @@ public static class SetSpriteExtensions
|
||||
/// <param name="image">UI/Image。</param>
|
||||
/// <param name="location">资源定位地址。</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>
|
||||
@@ -20,8 +22,9 @@ public static class SetSpriteExtensions
|
||||
/// </summary>
|
||||
/// <param name="spriteRenderer">2D/SpriteRender。</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.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -40,10 +41,15 @@ namespace TEngine
|
||||
public string Location { get; private set; }
|
||||
|
||||
private bool _setNativeSize = false;
|
||||
|
||||
private CancellationToken _cancellationToken;
|
||||
|
||||
public void SetAsset(Object asset)
|
||||
{
|
||||
_sprite = (Sprite)asset;
|
||||
|
||||
if (_cancellationToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
if (_image != null)
|
||||
{
|
||||
@@ -84,21 +90,23 @@ namespace TEngine
|
||||
_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>();
|
||||
item._image = image;
|
||||
item._setNativeSize = setNativeSize;
|
||||
item.Location = location;
|
||||
item._cancellationToken = cancellationToken;
|
||||
item._setType = SetType.Image;
|
||||
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>();
|
||||
item._spriteRenderer = spriteRenderer;
|
||||
item.Location = location;
|
||||
item._cancellationToken = cancellationToken;
|
||||
item._setType = SetType.SpriteRender;
|
||||
return item;
|
||||
}
|
||||
|
Reference in New Issue
Block a user