- 补充游戏核心逻辑

- 完成 TodOList P0
    - 添加游戏内控制台便于调试
    - 增加敌人互斥机制提高运算负载
    - 优化互斥算法将游戏性能基准线拉到 1k 敌人
This commit is contained in:
SepComet
2026-02-20 18:08:27 +08:00
parent b4bc8b0445
commit 3742110e9a
196 changed files with 4868 additions and 31326 deletions
@@ -14,6 +14,11 @@ namespace UI
private int _index = -1;
public void SetIndex(int index)
{
_index = index;
}
public void OnInit(DisplayItemContext context, int index)
{
if (context == null) return;
@@ -42,18 +47,25 @@ namespace UI
public void OnItemInfoShow()
{
if (_index < 0) return;
Vector3 targetPos = _itemRect.position + new Vector3(0, _itemRect.sizeDelta.y / 2, 0);
if (_itemRect == null) return;
Rect rect = _itemRect.rect;
Vector3 targetPos = _itemRect.TransformPoint(new Vector3(
(rect.xMin + rect.xMax) / 2,
rect.yMax,
0f)
);
GameEntry.Event.Fire(this, DisplayItemShowEventArgs.Create(_index, _context.IsWeapon, targetPos));
}
public void SetIndex(int index)
public void OnItemInfoLock()
{
_index = index;
GameEntry.Event.Fire(this, DisplayItemInfoLockEventArgs.Create());
}
public void OnItemInfoHide()
{
GameEntry.Event.Fire(this, DisplayItemHideEventArgs.Create());
GameEntry.Event.Fire(this, DisplayItemInfoHideEventArgs.Create());
}
}
}
@@ -1,6 +1,6 @@
using CustomEvent;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
@@ -45,6 +45,7 @@ namespace UI
_context = context;
_targetPos = ConvertWorldToAnchored(_context.TargetPos);
Log.Info($"{_context.TargetPos}->{_targetPos}");
if (_content != null)
{
@@ -172,14 +173,16 @@ namespace UI
}
Canvas canvas = _content.GetComponentInParent<Canvas>();
Canvas rootCanvas = canvas != null ? canvas.rootCanvas : null;
Camera uiCamera = null;
if (canvas != null && canvas.renderMode != RenderMode.ScreenSpaceOverlay)
if (rootCanvas != null && rootCanvas.renderMode != RenderMode.ScreenSpaceOverlay)
{
uiCamera = canvas.worldCamera;
uiCamera = rootCanvas.worldCamera != null ? rootCanvas.worldCamera : Camera.main;
}
Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(uiCamera, worldPos);
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, uiCamera, out Vector2 localPoint))
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(parent, screenPoint, uiCamera,
out Vector2 localPoint))
{
return worldPos;
}
@@ -187,5 +190,16 @@ namespace UI
float z = _content.anchoredPosition3D.z;
return new Vector3(localPoint.x, localPoint.y, z);
}
public void OnRecycleButtonClick()
{
if (_context == null || !_context.IsWeapon) return;
GameEntry.Event.Fire(this, ShopWeaponRecycleEventArgs.Create(_context.Index, _context.Price));
}
public void OnCancelButtonClick()
{
GameEntry.Event.Fire(this, DisplayItemInfoHideEventArgs.Create());
}
}
}
@@ -1,6 +1,5 @@
using Components;
using CustomComponent;
using CustomEvent;
using Entity;
using GameFramework.Event;
using TMPro;
using UnityEngine;
@@ -13,17 +12,17 @@ namespace UI
[SerializeField] private float _sliderFadeDuration = 0.5f;
[SerializeField] private Slider _hpSlider;
[SerializeField] private TMP_Text _hpText;
private float _currentHpPercent = 0;
private Coroutine _hpSliderFadeCoroutine;
[SerializeField] private Slider _expSlider;
private float _currentExpPercent = 0;
private Coroutine _expSliderFadeCoroutine;
[SerializeField] private TMP_Text _expText;
private int _playerCurrentLevel = 1;
@@ -31,11 +30,16 @@ namespace UI
[SerializeField] private TMP_Text _coinText;
private int _currentCoin = 0;
[SerializeField] private TMP_Text _levelTimeLeftText;
private int _currentTimeLeft = 0;
[SerializeField] private TMP_Text _enemyCountText;
private EnemyManagerComponent _enemy;
public void RefreshUI(HudFormContext hudFormContext)
{
}
#region FSM
protected override void OnInit(object userData)
@@ -46,6 +50,9 @@ namespace UI
GameEntry.Event.Subscribe(PlayerExpChangeEventArgs.EventId, PlayerExpChange);
GameEntry.Event.Subscribe(PlayerCoinChangeEventArgs.EventId, PlayerCoinChange);
GameEntry.Event.Subscribe(PlayerLevelUpEventArgs.EventId, PlayerLevelUp);
GameEntry.Event.Subscribe(LevelProcessEventArgs.EventId, LevelProcess);
_enemy = GameEntry.EnemyManager;
}
protected override void OnClose(bool isShutdown, object userData)
@@ -54,9 +61,24 @@ namespace UI
GameEntry.Event.Unsubscribe(PlayerHealthChangeEventArgs.EventId, PlayerHpChange);
GameEntry.Event.Unsubscribe(PlayerExpChangeEventArgs.EventId, PlayerExpChange);
GameEntry.Event.Unsubscribe(PlayerCoinChangeEventArgs.EventId, PlayerCoinChange);
GameEntry.Event.Unsubscribe(PlayerLevelUpEventArgs.EventId, PlayerLevelUp);
base.OnClose(isShutdown, userData);
}
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(elapseSeconds, realElapseSeconds);
if (_enemy == null)
{
_enemy = GameEntry.EnemyManager;
}
if (_enemy != null)
{
_enemyCountText.text = $"Enemy: {_enemy.CurrentEnemyCount}";
}
}
#endregion
@@ -67,7 +89,7 @@ namespace UI
if (!(e is PlayerHealthChangeEventArgs args)) return;
_hpText.text = $"{args.CurrentHealth}/{args.MaxHealth}";
float percent = (float)args.CurrentHealth / args.MaxHealth;
if (Mathf.Approximately(_currentHpPercent, percent)) return;
@@ -96,7 +118,7 @@ namespace UI
_playerCurrentLevel++;
_expText.text = $"LV.{_playerCurrentLevel}";
}
private void PlayerCoinChange(object sender, GameEventArgs e)
{
if (!(e is PlayerCoinChangeEventArgs args)) return;
@@ -106,24 +128,15 @@ namespace UI
_currentCoin = args.CoinCount;
}
#endregion
#region Test
private Player _player;
public void CauseDamageToPlayer()
private void LevelProcess(object sender, GameEventArgs e)
{
if (_player == null)
{
_player = FindObjectOfType<Player>();
}
if (!(e is LevelProcessEventArgs args)) return;
if (_currentTimeLeft == args.LevelTimeLeft) return;
if (_player == null) return;
_player.GetComponent<HealthComponent>().TakeDamage(2);
_currentTimeLeft = args.LevelTimeLeft;
_levelTimeLeftText.text = _currentTimeLeft.ToString();
}
#endregion
}
}
}
@@ -30,7 +30,7 @@ namespace UI
if (_titleText != null) _titleText.text = context.Title;
if (_descriptionText != null) _descriptionText.text = context.Description;
if (_iconArea != null) _iconArea.SetIcon(context.Icon);
if (_iconArea != null) _iconArea.OnInit(context.Icon, context.ItemRarity);
LoadIcon(_context.IconAssetName);
}
@@ -120,6 +120,12 @@ namespace UI
_weaponListArea.AddItem(context);
}
internal void RemoveWeaponDisplayItem(int index)
{
if (_weaponListArea == null) return;
_weaponListArea.RemoveItemAt(index);
}
#region ButtonClick
public void OnContinueButtonClick()