parent
334b96f90e
commit
923b0751e5
|
@ -92,58 +92,63 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 同步初始化游戏对象
|
||||
/// </summary>
|
||||
/// <param name="parent">父类对象</param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步初始化游戏对象
|
||||
/// </summary>
|
||||
/// <param name="position">坐标</param>
|
||||
/// <param name="rotation">角度</param>
|
||||
/// <param name="parent">父类对象</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化游戏对象
|
||||
/// </summary>
|
||||
/// <param name="parent">父类对象</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化游戏对象
|
||||
/// </summary>
|
||||
/// <param name="position">坐标</param>
|
||||
/// <param name="rotation">角度</param>
|
||||
/// <param name="parent">父类对象</param>
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue