diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
index d59f27e..99e6054 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
@@ -75,7 +75,7 @@ namespace YooAsset
///
public GameObject InstantiateSync(Transform parent = null)
{
- return InstantiateSync(Vector3.zero, Quaternion.identity, parent);
+ return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent, false);
}
///
@@ -86,15 +86,7 @@ namespace YooAsset
/// 父类对象
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
{
- if (IsValid == false)
- return null;
- if (_provider.AssetObject == null)
- return null;
-
- if (parent == null)
- return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation);
- else
- return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation, parent);
+ return InstantiateSyncInternal(position, rotation, parent, true);
}
///
@@ -103,7 +95,7 @@ namespace YooAsset
/// 父类对象
public InstantiateOperation InstantiateAsync(Transform parent = null)
{
- return InstantiateAsync(Vector3.zero, Quaternion.identity, parent);
+ return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent, false);
}
///
@@ -114,7 +106,35 @@ namespace YooAsset
/// 父类对象
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
{
- InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent);
+ return InstantiateAsyncInternal(position, rotation, parent, true);
+ }
+
+
+ private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
+ {
+ if (IsValid == false)
+ return null;
+ if (_provider.AssetObject == null)
+ return null;
+
+ if (setPositionRotation)
+ {
+ if (parent == null)
+ return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation);
+ else
+ return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, position, rotation, parent);
+ }
+ else
+ {
+ if (parent == null)
+ return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject);
+ else
+ return UnityEngine.Object.Instantiate(_provider.AssetObject as GameObject, parent);
+ }
+ }
+ private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
+ {
+ InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
OperationSystem.ProcessOperaiton(operation);
return operation;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
index 6c8bae7..eaa6b16 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
@@ -15,6 +15,7 @@ namespace YooAsset
private readonly Vector3 _position;
private readonly Quaternion _rotation;
private readonly Transform _parent;
+ private readonly bool _setPositionRotation;
private ESteps _steps = ESteps.None;
///
@@ -23,12 +24,13 @@ namespace YooAsset
public GameObject Result = null;
- internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent)
+ internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
{
_handle = handle;
_position = position;
_rotation = rotation;
_parent = parent;
+ _setPositionRotation = setPositionRotation;
}
internal override void Start()
{
@@ -54,10 +56,20 @@ namespace YooAsset
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
}
- if (_parent == null)
- Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
+ if(_setPositionRotation)
+ {
+ if (_parent == null)
+ Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
+ else
+ Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
+ }
else
- Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
+ {
+ if (_parent == null)
+ Result = Object.Instantiate(_handle.AssetObject as GameObject);
+ else
+ Result = Object.Instantiate(_handle.AssetObject as GameObject, _parent);
+ }
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;