(client) feat:窗口新增独占、占用输入属性,添加部分行为树节点和工作类

This commit is contained in:
m0_75251201
2025-07-31 17:45:50 +08:00
parent 82dc89c890
commit e1ff66ff28
41 changed files with 2418 additions and 7175 deletions

View File

@ -12,21 +12,21 @@ namespace UI
public Prefab.TextPrefab textTemplate;
public Prefab.ButtonPrefab buttonTemplate;
void Start()
private void Start()
{
Init();
}
void Init()
private void Init()
{
InitEvent();
InitCharacter();
InitMonster();
}
void InitEvent()
private void InitEvent()
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "事件菜单";
@ -38,7 +38,7 @@ namespace UI
}
void InitCharacter()
private void InitCharacter()
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "生成人物";
@ -52,6 +52,22 @@ namespace UI
button.AddListener(() => GenerateEntityCallback(pawnDef));
}
}
private void InitMonster()
{
var title = InstantiatePrefab(textTemplate, menuContent.transform);
title.Label = "生成怪物";
var defList=Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.MonsterDef>();
foreach (var def in defList)
{
var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = def.label;
var pawnDef = def;
button.AddListener(() => GenerateEntityCallback(pawnDef));
}
}
/// <summary>
/// 通用的实例化函数,返回实例化的预制件脚本组件。
/// </summary>
@ -59,7 +75,7 @@ namespace UI
/// <param name="prefab">要实例化的预制件</param>
/// <param name="parent">实例化对象的父对象</param>
/// <returns>实例化的预制件脚本组件</returns>
T InstantiatePrefab<T>(T prefab, Transform parent) where T : Component
private T InstantiatePrefab<T>(T prefab, Transform parent) where T : Component
{
if (prefab == null || parent == null)
{
@ -81,7 +97,7 @@ namespace UI
return instantiatedComponent;
}
void GenerateEntityCallback(PawnDef pawnDef)
private void GenerateEntityCallback(PawnDef pawnDef)
{
Managers.EntityManage.Instance.GenerateEntity(pawnDef, new(0, 0));
}

View File

@ -0,0 +1,26 @@
using Base;
using UnityEngine;
using UnityEngine.Events;
namespace UI
{
public class EntityPlacementUI:UIBase,ITickUI
{
public UnityAction currentAction = null;
public void TickUI()
{
if (!IsVisible||currentAction==null)
return;
if (Input.GetMouseButton(0))
{
currentAction.Invoke();
}
if (Input.GetKeyDown(KeyCode.Escape))
{
Hide();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 22c2554b0c0949aab37618f3a80ffe5a
timeCreated: 1753505464

View File

@ -1,3 +1,5 @@
using UnityEngine;
namespace UI
{
public class EscUI:UIBase

View File

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using Prefab;
using TMPro;
using UnityEngine;
namespace UI
{
public class LogUI : UIBase
{
public Transform contentPanel; // 日志内容容器
public TextPrefab textPrefab; // 文本预制体引用
// 日志类型颜色映射
private static readonly Dictionary<LogType, Color> logColors = new Dictionary<LogType, Color>
{
{ LogType.Log, Color.white },
{ LogType.Warning, Color.yellow },
{ LogType.Error, new Color(1f, 0.4f, 0.4f) },
{ LogType.Exception, new Color(1f, 0.2f, 0.2f) },
{ LogType.Assert, new Color(0.8f, 0.4f, 1f) }
};
private List<Transform> _logItems = new List<Transform>(); // 已创建的日志条目
private int _lastLogCount = 0; // 上次显示的日志数量
private void Start()
{
Logging.LogCapturer.Clear();
}
public override void Show()
{
base.Show();
RefreshLogDisplay();
}
private void RefreshLogDisplay()
{
var logs = Logging.LogCapturer.GetLogs();
// 如果日志数量减少,清理多余的条目
if (logs.Count < _lastLogCount)
{
for (int i = logs.Count; i < _lastLogCount; i++)
{
Destroy(_logItems[i].gameObject);
}
_logItems.RemoveRange(logs.Count, _logItems.Count - logs.Count);
}
// 更新现有条目
for (int i = 0; i < Math.Min(logs.Count, _logItems.Count); i++)
{
UpdateLogEntry(_logItems[i], logs[logs.Count - 1 - i]);
}
// 添加新的条目
if (logs.Count > _lastLogCount)
{
for (int i = _lastLogCount; i < logs.Count; i++)
{
CreateLogEntry(logs[logs.Count - 1 - i]);
}
}
_lastLogCount = logs.Count;
}
private void CreateLogEntry(Logging.LogCapturer.LogEntry entry)
{
// 实例化文本预制体
var logItem = Instantiate(textPrefab, contentPanel);
_logItems.Add(logItem.transform);
UpdateLogEntry(logItem.transform, entry);
}
private void UpdateLogEntry(Transform logItemTransform, Logging.LogCapturer.LogEntry entry)
{
var logItem = logItemTransform.GetComponent<TextPrefab>();
// 设置文本内容
logItem.Label = entry.ToString();
// 设置文本颜色(根据日志类型)
if (logColors.TryGetValue(entry.Type, out Color color))
{
logItem.text.color = color;
}
else
{
logItem.text.color = Color.white; // 默认颜色
}
logItem.text.alignment = TextAlignmentOptions.TopLeft;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 84d93a37c40b425890e954f2ddb9344c
timeCreated: 1753457075

View File

@ -2,12 +2,24 @@ using UnityEngine;
namespace UI
{
public abstract class UIBase:MonoBehaviour
public abstract class UIBase : MonoBehaviour
{
public bool exclusive = true;
public bool needPause = true;
public bool isInputOccupied = false;
public KeyCode actionButton = KeyCode.None;
// 显示或隐藏窗口
public virtual void Show() { gameObject.SetActive(true); }
public virtual void Hide() { gameObject.SetActive(false); }
public virtual void Show()
{
gameObject.SetActive(true);
}
public virtual void Hide()
{
gameObject.SetActive(false);
}
// 判断是否可见
public bool IsVisible => gameObject.activeInHierarchy;