feat : Instantiate add actived param.

实例化对象方法增加激活参数。
pull/353/head
何冠峰 2024-08-22 15:18:31 +08:00
parent 50eed2be10
commit 94623d8dc0
2 changed files with 19 additions and 13 deletions

View File

@ -116,25 +116,25 @@ namespace YooAsset
/// <summary> /// <summary>
/// 异步初始化游戏对象 /// 异步初始化游戏对象
/// </summary> /// </summary>
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) 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); 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; 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); OperationSystem.StartOperation(packageName, operation);
return operation; return operation;
} }

View File

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.TextCore.Text;
namespace YooAsset namespace YooAsset
{ {
@ -17,6 +18,7 @@ namespace YooAsset
private readonly Quaternion _rotation; private readonly Quaternion _rotation;
private readonly Transform _parent; private readonly Transform _parent;
private readonly bool _worldPositionStays; private readonly bool _worldPositionStays;
private readonly bool _actived;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
/// <summary> /// <summary>
@ -25,7 +27,8 @@ namespace YooAsset
public GameObject Result = null; 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; _handle = handle;
_setPositionAndRotation = setPositionAndRotation; _setPositionAndRotation = setPositionAndRotation;
@ -33,6 +36,7 @@ namespace YooAsset
_rotation = rotation; _rotation = rotation;
_parent = parent; _parent = parent;
_worldPositionStays = worldPositionStays; _worldPositionStays = worldPositionStays;
_actived = actived;
} }
internal override void InternalOnStart() internal override void InternalOnStart()
{ {
@ -66,6 +70,8 @@ namespace YooAsset
// 实例化游戏对象 // 实例化游戏对象
Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays); Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays);
if (_actived == false)
Result.SetActive(false);
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;