Update AssetSystem

实例化GameObject的时候,如果没有传递坐标和角度则使用默认值。
pull/4/head
hevinci 2022-04-08 19:10:00 +08:00
parent 11e03c7a13
commit f38d663e9d
2 changed files with 48 additions and 16 deletions

View File

@ -75,7 +75,7 @@ namespace YooAsset
/// <returns></returns>
public GameObject InstantiateSync(Transform parent = null)
{
return InstantiateSync(Vector3.zero, Quaternion.identity, parent);
return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent, false);
}
/// <summary>
@ -86,15 +86,7 @@ namespace YooAsset
/// <param name="parent">父类对象</param>
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);
}
/// <summary>
@ -103,7 +95,7 @@ namespace YooAsset
/// <param name="parent">父类对象</param>
public InstantiateOperation InstantiateAsync(Transform parent = null)
{
return InstantiateAsync(Vector3.zero, Quaternion.identity, parent);
return InstantiateAsyncInternal(Vector3.zero, Quaternion.identity, parent, false);
}
/// <summary>
@ -114,7 +106,35 @@ namespace YooAsset
/// <param name="parent">父类对象</param>
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;
}

View File

@ -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;
/// <summary>
@ -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(_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);
}
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;