parent
334b96f90e
commit
923b0751e5
|
@ -92,58 +92,63 @@ namespace YooAsset
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步初始化游戏对象
|
/// 同步初始化游戏对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parent">父类对象</param>
|
public GameObject InstantiateSync()
|
||||||
/// <returns></returns>
|
|
||||||
public GameObject InstantiateSync(Transform parent = null)
|
|
||||||
{
|
{
|
||||||
return InstantiateSyncInternal(Vector3.zero, Quaternion.identity, parent);
|
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, null, false);
|
||||||
}
|
}
|
||||||
|
public GameObject InstantiateSync(Transform parent)
|
||||||
/// <summary>
|
|
||||||
/// 同步初始化游戏对象
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position">坐标</param>
|
|
||||||
/// <param name="rotation">角度</param>
|
|
||||||
/// <param name="parent">父类对象</param>
|
|
||||||
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent = null)
|
|
||||||
{
|
{
|
||||||
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>
|
||||||
/// 异步初始化游戏对象
|
/// 异步初始化游戏对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="parent">父类对象</param>
|
public InstantiateOperation InstantiateAsync()
|
||||||
public InstantiateOperation InstantiateAsync(Transform parent = null)
|
|
||||||
{
|
{
|
||||||
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>
|
private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||||
/// 异步初始化游戏对象
|
|
||||||
/// </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)
|
|
||||||
{
|
{
|
||||||
if (IsValidWithWarning == false)
|
if (IsValidWithWarning == false)
|
||||||
return null;
|
return null;
|
||||||
if (Provider.AssetObject == null)
|
if (Provider.AssetObject == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
GameObject clone = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, position, rotation, parent);
|
return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays);
|
||||||
return clone;
|
|
||||||
}
|
}
|
||||||
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);
|
OperationSystem.StartOperation(operation);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,11 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly AssetOperationHandle _handle;
|
private readonly AssetOperationHandle _handle;
|
||||||
|
private readonly bool _setPositionAndRotation;
|
||||||
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 _worldPositionStays;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,12 +25,14 @@ namespace YooAsset
|
||||||
public GameObject Result = null;
|
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;
|
_handle = handle;
|
||||||
|
_setPositionAndRotation = setPositionAndRotation;
|
||||||
_position = position;
|
_position = position;
|
||||||
_rotation = rotation;
|
_rotation = rotation;
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
_worldPositionStays = worldPositionStays;
|
||||||
}
|
}
|
||||||
internal override void Start()
|
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;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
@ -91,5 +95,38 @@ namespace YooAsset
|
||||||
_handle.WaitForAsyncComplete();
|
_handle.WaitForAsyncComplete();
|
||||||
Update();
|
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