(client) feat:支持定义实体的碰撞体大小和偏移;建筑支持定义实体建筑和瓦片建筑,建筑支持指定按钮回调;添加存档管理器;Dev支持设置是否暂停;实体允许定义事件组;添加基地界面 (#57)

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/57
This commit is contained in:
2025-09-28 15:02:57 +08:00
parent 87a8abe86c
commit aff747be17
232 changed files with 39203 additions and 4161 deletions

View File

@@ -1,6 +1,7 @@
using Managers;
using Prefab;
using System.Collections.Generic;
using Base;
using UnityEngine;
using UnityEngine.Events;
@@ -19,12 +20,15 @@ namespace Entity
public static Vector3 minimum = new(0.5f, 0.5f, 0.5f);
public bool CanShow => Setting.Instance.CurrentSettings.developerMode && entity.canSelect;
public virtual void Init()
{
var size = GetSize();
outlineRenderer.size = size;
outlineRenderer.size = GetBodyTextureSize();
var size = GetColliderSize();
outlineCollider.direction = size.x > size.y ? CapsuleDirection2D.Horizontal : CapsuleDirection2D.Vertical;
outlineCollider.size = size;
outlineCollider.offset = GetOffset();
if (progressBarPrefab)
{
progressBarPrefab.transform.localPosition += new Vector3(0f, size.y * 2 / 3, 0f);
@@ -49,7 +53,14 @@ namespace Entity
/// 返回一个 Vector3 对象,表示对象在世界空间中的总大小(宽度、高度、深度)。
/// 如果没有找到任何渲染器,则返回 (-1, -1, -1) 表示无效大小。
/// </returns>
public Vector3 GetSize()
public Vector2 GetColliderSize()
{
return !string.IsNullOrEmpty(entity.entityDef.colliderSize)
? Utils.StringUtils.StringToVector2(entity.entityDef.colliderSize)
: GetBodyTextureSize();
}
public Vector2 GetBodyTextureSize()
{
// 获取所有子对象的 Renderer 组件
var renderers = body.GetComponentsInChildren<Renderer>();
@@ -80,28 +91,37 @@ namespace Entity
return size;
}
private void OnMouseEnter()
public Vector2 GetOffset()
{
return string.IsNullOrEmpty(entity.entityDef.colliderPosition)
? Vector2.zero
: Utils.StringUtils.StringToVector2(entity.entityDef.colliderPosition);
}
protected virtual void OnMouseEnter()
{
if (!CanShow)
return;
Show();
}
private void OnMouseExit()
protected virtual void OnMouseExit()
{
Hide();
}
private void OnMouseOver()
protected virtual void OnMouseOver()
{
if (!entity.canSelect)
if (!Program.Instance.CanOpenRightMenu || !CanShow)
return;
// 检测是否按下的是鼠标右键
if (Input.GetMouseButtonDown(1)) // 鼠标右键对应的是按钮索引 1
if (Input.GetMouseButtonDown(1))
{
RightMenuManager.GenerateRightMenu(GetMenu(), Input.mousePosition);
}
}
private List<(string name, UnityAction callback)> GetMenu()
protected virtual List<(string name, UnityAction callback)> GetMenu()
{
var result = new List<(string name, UnityAction callback)>();
if (entity.PlayerControlled)
@@ -113,18 +133,18 @@ namespace Entity
return result;
}
private void BecomeDefault()
protected void BecomeDefault()
{
entity.Kill();
EntityManage.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId, entity.Position);
EntityManager.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId, entity.Position);
}
private void StartControl()
protected void StartControl()
{
entity.PlayerControlled = true;
}
private void EndControl()
protected void EndControl()
{
entity.PlayerControlled = false;
}