From 608f401a8077a58a94cff0958a47b650bf5a3df3 Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 11 Oct 2022 18:09:54 +0800 Subject: [PATCH] Update Operation System MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加异步操作取消方法 --- .../AssetSystem/Operations/InstantiateOperation.cs | 11 ++++++++++- .../Runtime/OperationSystem/AsyncOperationBase.cs | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs index 1241982..19bff32 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs @@ -62,7 +62,7 @@ namespace YooAsset return; } - if(_setPositionRotation) + if (_setPositionRotation) { if (_parent == null) Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation); @@ -81,5 +81,14 @@ namespace YooAsset Status = EOperationStatus.Succeed; } } + public override void Cancel() + { + if (IsDone == false) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"User cancelled !"; + } + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs index f2cbed6..0730ed8 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs @@ -81,6 +81,14 @@ namespace YooAsset _taskCompletionSource.TrySetResult(null); } + /// + /// 取消异步操作 + /// + public virtual void Cancel() + { + throw new NotImplementedException("Can not cancel operation !"); + } + #region 异步编程相关 bool IEnumerator.MoveNext() {