mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Update
Update
This commit is contained in:
1706
Assets/AssetRaw/UI/TestUI.prefab
Normal file
1706
Assets/AssetRaw/UI/TestUI.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/AssetRaw/UI/TestUI.prefab.meta
Normal file
7
Assets/AssetRaw/UI/TestUI.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e7f73a9317cd2134fa6613d787208825
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -1,7 +1,23 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace TEngine
|
namespace TEngine
|
||||||
{
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class UpdateAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class LateUpdateAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class FixedUpdateAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过LogicSys来驱动且具备Unity完整生命周期的单例(不继承MonoBehaviour)
|
/// 通过LogicSys来驱动且具备Unity完整生命周期的单例(不继承MonoBehaviour)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -53,14 +69,30 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 帧更新。
|
||||||
|
/// <remarks>需要UpdateAttribute。</remarks>
|
||||||
|
/// </summary>
|
||||||
public virtual void Update()
|
public virtual void Update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 后帧更新。
|
||||||
|
/// <remarks>需要LateUpdateAttribute。</remarks>
|
||||||
|
/// </summary>
|
||||||
public virtual void LateUpdate()
|
public virtual void LateUpdate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 物理帧更新。
|
||||||
|
/// <remarks>需要FixedUpdateAttribute。</remarks>
|
||||||
|
/// </summary>
|
||||||
|
public virtual void FixedUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Destroy()
|
public virtual void Destroy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -84,12 +116,25 @@ namespace TEngine
|
|||||||
private readonly List<BaseBehaviourSingleton> _listStart = new List<BaseBehaviourSingleton>();
|
private readonly List<BaseBehaviourSingleton> _listStart = new List<BaseBehaviourSingleton>();
|
||||||
private readonly List<BaseBehaviourSingleton> _listUpdate = new List<BaseBehaviourSingleton>();
|
private readonly List<BaseBehaviourSingleton> _listUpdate = new List<BaseBehaviourSingleton>();
|
||||||
private readonly List<BaseBehaviourSingleton> _listLateUpdate = new List<BaseBehaviourSingleton>();
|
private readonly List<BaseBehaviourSingleton> _listLateUpdate = new List<BaseBehaviourSingleton>();
|
||||||
|
private readonly List<BaseBehaviourSingleton> _listFixedUpdate = new List<BaseBehaviourSingleton>();
|
||||||
|
|
||||||
public void RegSingleton(BaseBehaviourSingleton inst)
|
public void RegSingleton(BaseBehaviourSingleton inst)
|
||||||
{
|
{
|
||||||
Log.Assert(!_listInst.Contains(inst));
|
Log.Assert(!_listInst.Contains(inst));
|
||||||
_listInst.Add(inst);
|
_listInst.Add(inst);
|
||||||
_listStart.Add(inst);
|
_listStart.Add(inst);
|
||||||
|
if (HadAttribute<UpdateAttribute>(inst.GetType()))
|
||||||
|
{
|
||||||
|
_listUpdate.Add(inst);
|
||||||
|
}
|
||||||
|
if (HadAttribute<LateUpdateAttribute>(inst.GetType()))
|
||||||
|
{
|
||||||
|
_listLateUpdate.Add(inst);
|
||||||
|
}
|
||||||
|
if (HadAttribute<FixedUpdateAttribute>(inst.GetType()))
|
||||||
|
{
|
||||||
|
_listFixedUpdate.Add(inst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnRegSingleton(BaseBehaviourSingleton inst)
|
public void UnRegSingleton(BaseBehaviourSingleton inst)
|
||||||
@@ -175,6 +220,20 @@ namespace TEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnFixedUpdate()
|
||||||
|
{
|
||||||
|
var listFixedUpdate = _listFixedUpdate;
|
||||||
|
var listFixedUpdateCnt = listFixedUpdate.Count;
|
||||||
|
for (int i = 0; i < listFixedUpdateCnt; i++)
|
||||||
|
{
|
||||||
|
var inst = listFixedUpdate[i];
|
||||||
|
|
||||||
|
TProfiler.BeginFirstSample(inst.GetType().FullName);
|
||||||
|
inst.FixedUpdate();
|
||||||
|
TProfiler.EndFirstSample();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnDestroy()
|
public override void OnDestroy()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _listInst.Count; i++)
|
for (int i = 0; i < _listInst.Count; i++)
|
||||||
@@ -208,5 +267,12 @@ namespace TEngine
|
|||||||
inst.OnDrawGizmos();
|
inst.OnDrawGizmos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool HadAttribute<T>(Type type) where T:Attribute
|
||||||
|
{
|
||||||
|
T attribute = Attribute.GetCustomAttribute(type, typeof(T)) as T;
|
||||||
|
|
||||||
|
return attribute != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -11,7 +11,8 @@ using Random = UnityEngine.Random;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 战斗房间
|
/// 战斗房间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BattleRoom
|
[Update]
|
||||||
|
public class BattleSystem:BehaviourSingleton<BattleSystem>
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
@@ -44,15 +45,50 @@ public class BattleRoom
|
|||||||
private UniTimer _spawnWaitTimer = UniTimer.CreateOnceTimer(0.75f);
|
private UniTimer _spawnWaitTimer = UniTimer.CreateOnceTimer(0.75f);
|
||||||
private UniTimer _waveWaitTimer = UniTimer.CreateOnceTimer(4f);
|
private UniTimer _waveWaitTimer = UniTimer.CreateOnceTimer(4f);
|
||||||
|
|
||||||
public BattleRoom()
|
|
||||||
{
|
|
||||||
Utility.Unity.AddUpdateListener(UpdateRoom);
|
|
||||||
}
|
|
||||||
|
|
||||||
~BattleRoom()
|
/// <summary>
|
||||||
|
/// 加载房间
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerator LoadRoom()
|
||||||
{
|
{
|
||||||
Utility.Unity.RemoveUpdateListener(UpdateRoom);
|
// 创建房间根对象
|
||||||
DestroyRoom();
|
_roomRoot = new GameObject("BattleRoom");
|
||||||
|
|
||||||
|
// 加载背景音乐
|
||||||
|
GameModule.Audio.Play(AudioType.Music, "music_background", true);
|
||||||
|
|
||||||
|
// 创建游戏对象发生器
|
||||||
|
_entitySpawner = UniPooling.CreateSpawner("DefaultPackage");
|
||||||
|
|
||||||
|
// 创建游戏对象池
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("player_ship");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("player_bullet");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("enemy_ship");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("enemy_bullet");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid01");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid02");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid03");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_asteroid");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_enemy");
|
||||||
|
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_player");
|
||||||
|
|
||||||
|
// 创建玩家实体对象
|
||||||
|
var handle = _entitySpawner.SpawnSync("player_ship", _roomRoot.transform);
|
||||||
|
var entity = handle.GameObj.GetComponent<EntityPlayer>();
|
||||||
|
entity.InitEntity(handle);
|
||||||
|
|
||||||
|
// 显示战斗界面
|
||||||
|
yield return GameModule.UI.ShowUIAsync<UIBattleWindow>();
|
||||||
|
|
||||||
|
// 监听游戏事件
|
||||||
|
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerDead,OnPlayerDead);
|
||||||
|
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyDead,OnEnemyDead);
|
||||||
|
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.AsteroidExplosion,OnAsteroidExplosion);
|
||||||
|
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerFireBullet,OnPlayerFireBullet);
|
||||||
|
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyFireBullet,OnEnemyFireBullet);
|
||||||
|
|
||||||
|
_startWaitTimer.Reset();
|
||||||
|
_steps = ESteps.Ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -70,6 +106,18 @@ public class BattleRoom
|
|||||||
Object.Destroy(_roomRoot);
|
Object.Destroy(_roomRoot);
|
||||||
|
|
||||||
GameModule.UI.CloseWindow<UIBattleWindow>();
|
GameModule.UI.CloseWindow<UIBattleWindow>();
|
||||||
|
|
||||||
|
// 监听游戏事件
|
||||||
|
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerDead,OnPlayerDead);
|
||||||
|
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyDead,OnEnemyDead);
|
||||||
|
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.AsteroidExplosion,OnAsteroidExplosion);
|
||||||
|
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerFireBullet,OnPlayerFireBullet);
|
||||||
|
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyFireBullet,OnEnemyFireBullet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
UpdateRoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -140,49 +188,6 @@ public class BattleRoom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载房间
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerator LoadRoom()
|
|
||||||
{
|
|
||||||
// 创建房间根对象
|
|
||||||
_roomRoot = new GameObject("BattleRoom");
|
|
||||||
|
|
||||||
// 加载背景音乐
|
|
||||||
GameModule.Audio.Play(AudioType.Music, "music_background", true);
|
|
||||||
|
|
||||||
// 创建游戏对象发生器
|
|
||||||
_entitySpawner = UniPooling.CreateSpawner("DefaultPackage");
|
|
||||||
|
|
||||||
// 创建游戏对象池
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("player_ship");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("player_bullet");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("enemy_ship");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("enemy_bullet");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid01");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid02");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("asteroid03");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_asteroid");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_enemy");
|
|
||||||
yield return _entitySpawner.CreateGameObjectPoolAsync("explosion_player");
|
|
||||||
|
|
||||||
// 创建玩家实体对象
|
|
||||||
var handle = _entitySpawner.SpawnSync("player_ship", _roomRoot.transform);
|
|
||||||
var entity = handle.GameObj.GetComponent<EntityPlayer>();
|
|
||||||
entity.InitEntity(handle);
|
|
||||||
|
|
||||||
// 显示战斗界面
|
|
||||||
yield return GameModule.UI.ShowUIAsync<UIBattleWindow>();
|
|
||||||
|
|
||||||
// 监听游戏事件
|
|
||||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerDead,OnPlayerDead);
|
|
||||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyDead,OnEnemyDead);
|
|
||||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.AsteroidExplosion,OnAsteroidExplosion);
|
|
||||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerFireBullet,OnPlayerFireBullet);
|
|
||||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyFireBullet,OnEnemyFireBullet);
|
|
||||||
|
|
||||||
_steps = ESteps.Ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region 接收事件
|
#region 接收事件
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ namespace GameLogic
|
|||||||
|
|
||||||
public override void OnRefresh()
|
public override void OnRefresh()
|
||||||
{
|
{
|
||||||
|
m_textScore.text = "Score : 0";
|
||||||
m_goOverView.SetActive(false);
|
m_goOverView.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,14 +44,10 @@ namespace GameLogic
|
|||||||
private async UniTaskVoid OnClickRestartBtn()
|
private async UniTaskVoid OnClickRestartBtn()
|
||||||
{
|
{
|
||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
// yield return YooAssets.LoadSceneAsync("scene_battle");
|
await GameModule.Resource.LoadSceneAsync("scene_battle").ToUniTask(Utility.Unity.Behaviour);
|
||||||
//
|
|
||||||
// _battleRoom = new BattleRoom();
|
BattleSystem.Instance.DestroyRoom();
|
||||||
// yield return _battleRoom.LoadRoom();
|
await BattleSystem.Instance.LoadRoom().ToUniTask(Utility.Unity.Behaviour);
|
||||||
//
|
|
||||||
// // 释放资源
|
|
||||||
// var package = YooAssets.GetPackage("DefaultPackage");
|
|
||||||
// package.UnloadUnusedAssets();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async UniTaskVoid OnClickHomeBtn()
|
private async UniTaskVoid OnClickHomeBtn()
|
||||||
|
@@ -36,9 +36,7 @@ public partial class GameApp:Singleton<GameApp>
|
|||||||
private async UniTaskVoid StartBattleRoom()
|
private async UniTaskVoid StartBattleRoom()
|
||||||
{
|
{
|
||||||
await GameModule.Resource.LoadSceneAsync("scene_battle").ToUniTask(Utility.Unity.Behaviour);
|
await GameModule.Resource.LoadSceneAsync("scene_battle").ToUniTask(Utility.Unity.Behaviour);
|
||||||
|
await BattleSystem.Instance.LoadRoom().ToUniTask(Utility.Unity.Behaviour);
|
||||||
BattleRoom battleRoom = new BattleRoom();
|
|
||||||
await battleRoom.LoadRoom().ToUniTask(Utility.Unity.Behaviour);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -20,6 +20,7 @@ public partial class GameApp
|
|||||||
{
|
{
|
||||||
// 初始化对象池系统
|
// 初始化对象池系统
|
||||||
UniPooling.Initalize();
|
UniPooling.Initalize();
|
||||||
|
AddLogicSys(BehaviourSingleSystem.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@@ -16,6 +16,7 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
private static GameObject _entity;
|
private static GameObject _entity;
|
||||||
private static MainBehaviour _behaviour;
|
private static MainBehaviour _behaviour;
|
||||||
|
public static MainBehaviour Behaviour => _behaviour;
|
||||||
|
|
||||||
#region 控制协程Coroutine
|
#region 控制协程Coroutine
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ namespace TEngine
|
|||||||
_behaviour = _entity.AddComponent<MainBehaviour>();
|
_behaviour = _entity.AddComponent<MainBehaviour>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MainBehaviour : MonoBehaviour
|
public class MainBehaviour : MonoBehaviour
|
||||||
{
|
{
|
||||||
private event UnityAction updateEvent;
|
private event UnityAction updateEvent;
|
||||||
private event UnityAction fixedUpdateEvent;
|
private event UnityAction fixedUpdateEvent;
|
||||||
|
Reference in New Issue
Block a user