diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 20cf027..c0783b7 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -87,7 +87,7 @@ namespace YooAsset /// public GameObject InstantiateSync(Transform parent = null) { - return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent, false); + return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent); } /// @@ -98,7 +98,7 @@ namespace YooAsset /// 父类对象 public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null) { - return InstantiateSyncInternal(position, rotation, parent, true); + return InstantiateSyncInternal(position, rotation, parent); } /// @@ -107,7 +107,7 @@ namespace YooAsset /// 父类对象 public InstantiateOperation InstantiateAsync(Transform parent = null) { - return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent, false); + return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent); } /// @@ -118,37 +118,23 @@ namespace YooAsset /// 父类对象 public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent = null) { - return InstantiateAsyncInternal(position, rotation, parent, true); + return InstantiateAsyncInternal(position, rotation, parent); } - private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) + private GameObject InstantiateSyncInternal(Vector3 position, Quaternion rotation, Transform parent) { if (IsValid == false) return null; if (Provider.AssetObject == null) return null; - GameObject result; - if (setPositionRotation) - { - if (parent == null) - result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation); - else - result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent); - } - else - { - if (parent == null) - result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject); - else - result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent); - } - return result; + GameObject clone = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent); + return clone; } - private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) + private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent) { - InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation); + InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent); OperationSystem.StartOperation(operation); return operation; } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs index ca3be38..49ebcc2 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs @@ -15,7 +15,6 @@ namespace YooAsset private readonly Vector3 _position; private readonly Quaternion _rotation; private readonly Transform _parent; - private readonly bool _setPositionRotation; private ESteps _steps = ESteps.None; /// @@ -24,13 +23,12 @@ namespace YooAsset public GameObject Result = null; - internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) + internal InstantiateOperation(AssetOperationHandle handle, Vector3 position, Quaternion rotation, Transform parent) { _handle = handle; _position = position; _rotation = rotation; _parent = parent; - _setPositionRotation = setPositionRotation; } internal override void Start() { @@ -62,20 +60,8 @@ namespace YooAsset return; } - 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 - { - if (_parent == null) - Result = Object.Instantiate(_handle.AssetObject as GameObject); - else - Result = Object.Instantiate(_handle.AssetObject as GameObject, _parent); - } + // 实例化游戏对象 + Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent); _steps = ESteps.Done; Status = EOperationStatus.Succeed; @@ -94,5 +80,16 @@ namespace YooAsset Error = $"User cancelled !"; } } + + /// + /// 等待异步实例化结束 + /// + public void WaitForAsyncComplete() + { + if (_steps == ESteps.Done) + return; + _handle.WaitForAsyncComplete(); + Update(); + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 58946b7..4810e96 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -9,7 +9,6 @@ namespace YooAsset { /// /// 编辑器下的模拟模式 - /// 注意:在初始化的时候自动构建真机模拟环境。 /// EditorSimulateMode,