From 94623d8dc0c81e35b0c4fd91d7909ead983fa021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 22 Aug 2024 15:18:31 +0800 Subject: [PATCH] feat : Instantiate add actived param. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实例化对象方法增加激活参数。 --- .../ResourceManager/Handle/AssetHandle.cs | 24 +++++++++---------- .../Operation/InstantiateOperation.cs | 8 ++++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handle/AssetHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handle/AssetHandle.cs index fee4c63..3370713 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handle/AssetHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handle/AssetHandle.cs @@ -116,25 +116,25 @@ namespace YooAsset /// /// 异步初始化游戏对象 /// - public InstantiateOperation InstantiateAsync() + public InstantiateOperation InstantiateAsync(bool actived = true) { - return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false); + return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false, actived); } - public InstantiateOperation InstantiateAsync(Transform parent) + public InstantiateOperation InstantiateAsync(Transform parent, bool actived = true) { - return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false); + return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false, actived); } - public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays) + public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays, bool actived = true) { - return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays); + return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays, actived); } - public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation) + public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, bool actived = true) { - return InstantiateAsyncInternal(true, position, rotation, null, false); + return InstantiateAsyncInternal(true, position, rotation, null, false, actived); } - public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent) + public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent, bool actived = true) { - return InstantiateAsyncInternal(true, position, rotation, parent, false); + return InstantiateAsyncInternal(true, position, rotation, parent, false, actived); } private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) @@ -146,10 +146,10 @@ namespace YooAsset return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays); } - private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) + private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays, bool actived) { string packageName = GetAssetInfo().PackageName; - InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays); + InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays, actived); OperationSystem.StartOperation(packageName, operation); return operation; } diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/InstantiateOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/InstantiateOperation.cs index 35741cb..755472c 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operation/InstantiateOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/InstantiateOperation.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.TextCore.Text; namespace YooAsset { @@ -17,6 +18,7 @@ namespace YooAsset private readonly Quaternion _rotation; private readonly Transform _parent; private readonly bool _worldPositionStays; + private readonly bool _actived; private ESteps _steps = ESteps.None; /// @@ -25,7 +27,8 @@ namespace YooAsset public GameObject Result = null; - internal InstantiateOperation(AssetHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) + internal InstantiateOperation(AssetHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation, + Transform parent, bool worldPositionStays, bool actived) { _handle = handle; _setPositionAndRotation = setPositionAndRotation; @@ -33,6 +36,7 @@ namespace YooAsset _rotation = rotation; _parent = parent; _worldPositionStays = worldPositionStays; + _actived = actived; } internal override void InternalOnStart() { @@ -66,6 +70,8 @@ namespace YooAsset // 实例化游戏对象 Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays); + if (_actived == false) + Result.SetActive(false); _steps = ESteps.Done; Status = EOperationStatus.Succeed;