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

View File

@ -15,6 +15,7 @@ namespace YooAsset
private readonly Vector3 _position; private readonly Vector3 _position;
private readonly Quaternion _rotation; private readonly Quaternion _rotation;
private readonly Transform _parent; private readonly Transform _parent;
private readonly bool _setPositionRotation;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
/// <summary> /// <summary>
@ -23,12 +24,13 @@ namespace YooAsset
public GameObject Result = null; 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; _handle = handle;
_position = position; _position = position;
_rotation = rotation; _rotation = rotation;
_parent = parent; _parent = parent;
_setPositionRotation = setPositionRotation;
} }
internal override void Start() internal override void Start()
{ {
@ -54,10 +56,20 @@ namespace YooAsset
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null."; Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
} }
if (_parent == null) if(_setPositionRotation)
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation); {
if (_parent == null)
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation);
else
Result = Object.Instantiate(_handle.AssetObject as GameObject, _position, _rotation, _parent);
}
else 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; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;