(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)

Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com>
Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
2025-10-10 14:08:23 +08:00
parent 9a797479ff
commit 16b49f3d3a
1900 changed files with 114053 additions and 34157 deletions

View File

@@ -1,18 +1,24 @@
using System;
using Data;
using Prefab;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement; // 新增引用
using UnityEngine.UI; // 用于 LayoutGroup 和 RectTransform
using TMPro; // 用于 TMP_Text
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Utils;
// 新增引用
// 用于 LayoutGroup 和 RectTransform
// 用于 TMP_Text
namespace Managers
{
public class MessageManager:Utils.MonoSingleton<MessageManager>
public class MessageManager : MonoSingleton<MessageManager>
{
private RectTransform _canvas;
private TemporaryAnimatorText _temporaryAnimatorTextPrefab; // 重命名,表示是预制体
private RectTransform _passiveHintContainer; // 用于PassiveHint的容器
private TemporaryAnimatorText _temporaryAnimatorTextPrefab; // 重命名,表示是预制体
// SceneManager.sceneLoaded 注册/取消注册
private void OnEnable()
@@ -25,7 +31,7 @@ namespace Managers
SceneManager.sceneLoaded -= OnSceneLoaded;
}
public void DisplayMessage(string message, PromptDisplayCategory type,Color? color=null,float showTime=3)
public void DisplayMessage(string message, PromptDisplayCategory type, Color? color = null, float showTime = 3)
{
if (!_canvas)
{
@@ -42,21 +48,22 @@ namespace Managers
TemporaryAnimationManager.Instance.GenerateTemporaryAnimation(message,
Program.Instance.FocusedEntity.Position, showTime); // 5秒显示时间
break;
case PromptDisplayCategory.Default:
case PromptDisplayCategory.PassiveHint:
if (_passiveHintContainer == null)
{
Debug.LogWarning("Cannot display PassiveHint: PassiveHintContainer is not available. Please ensure Canvas is present.");
Debug.LogWarning(
"Cannot display PassiveHint: PassiveHintContainer is not available. Please ensure Canvas is present.");
return;
}
// 实例化消息文本作为PassiveHintContainer的子对象
var hintTextInstance = Instantiate(_temporaryAnimatorTextPrefab, _passiveHintContainer.transform);
// 确保它在Layout Group中正确显示
// var hintTextRect = hintTextInstance.GetComponent<RectTransform>();
// 如果temporaryAnimatorText有ContentSizeFitter这里可能不需要设置sizeDelta但为了LayoutGroup能识别可以添加LayoutElement
// var layoutElement = hintTextInstance.GetComponent<LayoutElement>();
// if (layoutElement == null) layoutElement = hintTextInstance.gameObject.AddComponent<LayoutElement>();
@@ -70,22 +77,22 @@ namespace Managers
hintTmpText.fontSize = 24; // 较小的字体
hintTmpText.alignment = TextAlignmentOptions.TopLeft; // 左上对齐
hintTmpText.enableAutoSizing = false; // 关闭自动调整字体,保持统一
if(color.HasValue)
if (color.HasValue)
hintTmpText.color = color.Value;
}
hintTextInstance.Init(message); // Init 方法会处理动画和生命周期
hintTextInstance.lifeTime = showTime;
// TemporaryAnimatorText 应该在 Init 内部设置好 lifeTime 并自动销毁。
break;
case PromptDisplayCategory.ScreenCenterLargeText:
var textInstance = GameObject.Instantiate(_temporaryAnimatorTextPrefab, _canvas.transform); // 使用预制体变量
var textInstance = Instantiate(_temporaryAnimatorTextPrefab, _canvas.transform); // 使用预制体变量
// 设置RectTransform实现全屏
var textRect = textInstance.GetComponent<RectTransform>();
textRect.anchorMin = Vector2.zero; // (0,0)
textRect.anchorMax = Vector2.one; // (1,1)
textRect.anchorMax = Vector2.one; // (1,1)
textRect.offsetMin = Vector2.zero; // 左下角偏移为(0,0)
textRect.offsetMax = Vector2.zero; // 右上角偏移为(0,0)
@@ -98,14 +105,14 @@ namespace Managers
tmpText.alignment = TextAlignmentOptions.Center; // 居中对齐
tmpText.enableAutoSizing = true; // 允许自动调整字体大小以适应文本框 (可选)
tmpText.SetText(message); // 先设置文本,确保布局计算正确
if(color.HasValue)
if (color.HasValue)
tmpText.color = color.Value;
}
textInstance.Init(message); // Init 方法会处理动画和生命周期
textInstance.lifeTime = showTime;
break;
case PromptDisplayCategory.FocusedEntityChatBubble:
break;
default:
@@ -120,20 +127,17 @@ namespace Managers
Resources.Load<TemporaryAnimatorText>("Prefab/TemporaryAnimation/UITemporaryAnimationText");
if (_temporaryAnimatorTextPrefab == null)
{
Debug.LogError("Failed to load TemporaryAnimatorText prefab. Check the path: Prefab/TemporaryAnimation/UITemporaryAnimationText");
}
Debug.LogError(
"Failed to load TemporaryAnimatorText prefab. Check the path: Prefab/TemporaryAnimation/UITemporaryAnimationText");
// 首次启动时也尝试查找 Canvas 和创建 PassiveHint 容器
// 这可以处理管理器在 Canvas 和其他 UI 元素之前启动的情况
if (SceneManager.GetActiveScene().isLoaded)
{
OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
}
}
/// <summary>
/// 场景加载完成回调用于查找并设置Canvas和PassiveHint容器
/// 场景加载完成回调用于查找并设置Canvas和PassiveHint容器
/// </summary>
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
@@ -153,12 +157,14 @@ namespace Managers
Destroy(_passiveHintContainer.gameObject);
_passiveHintContainer = null;
}
Debug.LogWarning($"MessageManager: No Canvas found in scene '{scene.name}'. UI messages might not display.");
Debug.LogWarning(
$"MessageManager: No Canvas found in scene '{scene.name}'. UI messages might not display.");
}
}
/// <summary>
/// 创建并初始化PassiveHint的UI容器
/// 创建并初始化PassiveHint的UI容器
/// </summary>
private void InitializePassiveHintContainer()
{
@@ -196,4 +202,4 @@ namespace Managers
layoutGroup.childForceExpandHeight = false;
}
}
}
}