diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
index f9f9451..24a43d2 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs
@@ -92,58 +92,63 @@ namespace YooAsset
///
/// 同步初始化游戏对象
///
- /// 父类对象
- ///
- public GameObject InstantiateSync(Transform parent = null)
+ public GameObject InstantiateSync()
{
- return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent);
+ return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, null, false);
}
-
- ///
- /// 同步初始化游戏对象
- ///
- /// 坐标
- /// 角度
- /// 父类对象
- public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
+ public GameObject InstantiateSync(Transform parent)
{
- return InstantiateSyncInternal(position, rotation, parent);
+ return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, false);
+ }
+ public GameObject InstantiateSync(Transform parent, bool worldPositionStays)
+ {
+ return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays);
+ }
+ public GameObject InstantiateSync(Vector3 position, Quaternion rotation)
+ {
+ return InstantiateSyncInternal(true, position, rotation, null, false);
+ }
+ public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent)
+ {
+ return InstantiateSyncInternal(true, position, rotation, parent, false);
}
///
/// 异步初始化游戏对象
///
- /// 父类对象
- public InstantiateOperation InstantiateAsync(Transform parent = null)
+ public InstantiateOperation InstantiateAsync()
{
- return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent);
+ return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false);
+ }
+ public InstantiateOperation InstantiateAsync(Transform parent)
+ {
+ return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false);
+ }
+ public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays)
+ {
+ return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays);
+ }
+ public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation)
+ {
+ return InstantiateAsyncInternal(true, position, rotation, null, false);
+ }
+ public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent)
+ {
+ return InstantiateAsyncInternal(true, position, rotation, parent, false);
}
- ///
- /// 异步初始化游戏对象
- ///
- /// 坐标
- /// 角度
- /// 父类对象
- public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null)
- {
- return InstantiateAsyncInternal(position, rotation, parent);
- }
-
-
- private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent)
+ private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
{
if (IsValidWithWarning == false)
return null;
if (Provider.AssetObject == null)
return null;
- GameObject clone = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
- return clone;
+ return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays);
}
- private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent)
+ private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
{
- InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent);
+ InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays);
OperationSystem.StartOperation(operation);
return operation;
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
index 76b39b8..02f2d5a 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs
@@ -12,9 +12,11 @@ namespace YooAsset
}
private readonly AssetOperationHandle _handle;
+ private readonly bool _setPositionAndRotation;
private readonly Vector3 _position;
private readonly Quaternion _rotation;
private readonly Transform _parent;
+ private readonly bool _worldPositionStays;
private ESteps _steps = ESteps.None;
///
@@ -23,12 +25,14 @@ namespace YooAsset
public GameObject Result = null;
- internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent)
+ internal InstantiateOperation(AssetOperationHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
{
_handle = handle;
+ _setPositionAndRotation = setPositionAndRotation;
_position = position;
_rotation = rotation;
_parent = parent;
+ _worldPositionStays = worldPositionStays;
}
internal override void Start()
{
@@ -61,7 +65,7 @@ namespace YooAsset
}
// 实例化游戏对象
- Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
+ Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@@ -91,5 +95,38 @@ namespace YooAsset
_handle.WaitForAsyncComplete();
Update();
}
+
+ internal static GameObject InstantiateInternal(UnityEngine.Object assetObject, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
+ {
+ if (assetObject == null)
+ return null;
+
+ if (setPositionAndRotation)
+ {
+ if (parent != null)
+ {
+ GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation, parent);
+ return clone;
+ }
+ else
+ {
+ GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation);
+ return clone;
+ }
+ }
+ else
+ {
+ if (parent != null)
+ {
+ GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, parent, worldPositionStays);
+ return clone;
+ }
+ else
+ {
+ GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject);
+ return clone;
+ }
+ }
+ }
}
}
\ No newline at end of file