mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 04:07:13 +08:00
(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:
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -20,6 +18,7 @@ namespace Data
|
||||
Walking,
|
||||
MeleeAttack,
|
||||
RangedAttack,
|
||||
Death,
|
||||
}
|
||||
|
||||
public class DrawingOrderDef : Define
|
||||
@@ -43,6 +42,11 @@ namespace Data
|
||||
public DrawNodeDef rangedAttack_up;
|
||||
public DrawNodeDef rangedAttack_left;
|
||||
public DrawNodeDef rangedAttack_right;
|
||||
|
||||
public DrawNodeDef death_down;
|
||||
public DrawNodeDef death_up;
|
||||
public DrawNodeDef death_left;
|
||||
public DrawNodeDef death_right;
|
||||
|
||||
public DrawNodeDef GetDrawNodeDef(EntityState state, Orientation orientation,
|
||||
out Orientation? fallbackOrientation)
|
||||
@@ -218,6 +222,16 @@ namespace Data
|
||||
case Orientation.Right: return rangedAttack_right;
|
||||
}
|
||||
|
||||
break;
|
||||
case EntityState.Death:
|
||||
switch (orientation)
|
||||
{
|
||||
case Orientation.Down: return death_down;
|
||||
case Orientation.Up: return death_up;
|
||||
case Orientation.Left: return death_left;
|
||||
case Orientation.Right: return death_right;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -238,29 +252,42 @@ namespace Data
|
||||
base.Init(xmlDef);
|
||||
|
||||
nodeName = xmlDef.Attribute("name")?.Value ?? "noName";
|
||||
position = StringToVector(xmlDef.Attribute("position")?.Value ?? "(0 0)");
|
||||
position = Utils.StringUtils.StringToVector2(xmlDef.Attribute("position")?.Value ?? "0,0");
|
||||
FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out var result) ? result : 5.0f;
|
||||
return false;
|
||||
}
|
||||
public Vector2 StringToVector(string vectorDef)
|
||||
|
||||
/// <summary>
|
||||
/// 获取播放一遍动画所需的最小时间(取当前节点动画与所有子集动画的最大值)。
|
||||
/// </summary>
|
||||
/// <returns>播放一遍动画所需的最小时间(秒),如果无动画则为0。</returns>
|
||||
public float GetMinAnimationDuration()
|
||||
{
|
||||
// 去掉可能存在的括号和多余的空格
|
||||
var cleanedInput = vectorDef.Replace("(", "").Replace(")", "").Trim();
|
||||
|
||||
// 使用正则表达式匹配两个浮点数
|
||||
var match = Regex.Match(cleanedInput, @"\s*(-?\d+(\.\d*)?)\s*[, ]\s*(-?\d+(\.\d*)?)\s*");
|
||||
|
||||
if (match.Success)
|
||||
var maxDuration = 0f;
|
||||
// 计算当前节点自身的动画时间
|
||||
if (textures != null && textures.Length > 0)
|
||||
{
|
||||
// 提取匹配到的两个浮点数
|
||||
var x = float.Parse(match.Groups[1].Value);
|
||||
var y = float.Parse(match.Groups[3].Value);
|
||||
|
||||
// 返回 Vector2 对象
|
||||
return new Vector2(x, y);
|
||||
// 只有当FPS大于0时,才计算有效的动画时间。
|
||||
// 如果FPS <= 0,表示该部分动画无法播放,其时长贡献为0,不参与最大值计算。
|
||||
if (FPS > 0)
|
||||
{
|
||||
maxDuration = Math.Max(maxDuration, textures.Length / FPS);
|
||||
}
|
||||
}
|
||||
|
||||
return Vector2.zero;
|
||||
// 递归计算子节点的动画时间,并更新最大值
|
||||
if (nodes != null && nodes.Length > 0)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
maxDuration = Math.Max(maxDuration, node.GetMinAnimationDuration());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maxDuration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user