mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Init TEngine4.0.0
Init TEngine4.0.0
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class InstantiateOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Clone,
|
||||
Done,
|
||||
}
|
||||
|
||||
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>
|
||||
/// 实例化的游戏对象
|
||||
/// </summary>
|
||||
public GameObject Result = null;
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
_steps = ESteps.Clone;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Clone)
|
||||
{
|
||||
if (_handle.IsValidWithWarning == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(AssetOperationHandle)} is invalid.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_handle.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_handle.AssetObject == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(AssetOperationHandle.AssetObject)} is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
// 实例化游戏对象
|
||||
Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消实例化对象操作
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"User cancelled !";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步实例化结束
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e7d3b16d9b01f548b4654e958d43a37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,86 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 场景卸载异步操作类
|
||||
/// </summary>
|
||||
public sealed class UnloadSceneOperation : AsyncOperationBase
|
||||
{
|
||||
private enum EFlag
|
||||
{
|
||||
Normal,
|
||||
Error,
|
||||
}
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
UnLoad,
|
||||
Checking,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly EFlag _flag;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private Scene _scene;
|
||||
private AsyncOperation _asyncOp;
|
||||
|
||||
internal UnloadSceneOperation(string error)
|
||||
{
|
||||
_flag = EFlag.Error;
|
||||
Error = error;
|
||||
}
|
||||
internal UnloadSceneOperation(Scene scene)
|
||||
{
|
||||
_flag = EFlag.Normal;
|
||||
_scene = scene;
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
if (_flag == EFlag.Normal)
|
||||
{
|
||||
_steps = ESteps.UnLoad;
|
||||
}
|
||||
else if (_flag == EFlag.Error)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(_flag.ToString());
|
||||
}
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.UnLoad)
|
||||
{
|
||||
if (_scene.IsValid() && _scene.isLoaded)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_scene);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
Error = "Scene is invalid or is not loaded.";
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone == false)
|
||||
return;
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5299512de5ab5c141ae37dac6ee1721e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user