(client):feat:添加对列表定义读取的支持,ui管理器将对没有键的窗口也进行统一管理
This commit is contained in:
@ -7,23 +7,17 @@ namespace Base
|
||||
{
|
||||
public interface ITick
|
||||
{
|
||||
public void Tick()
|
||||
{
|
||||
}
|
||||
public void Tick();
|
||||
}
|
||||
|
||||
public interface ITickPhysics
|
||||
{
|
||||
public void TickPhysics()
|
||||
{
|
||||
}
|
||||
public void TickPhysics();
|
||||
}
|
||||
|
||||
public interface ITickUI
|
||||
{
|
||||
public void TickUI()
|
||||
{
|
||||
}
|
||||
public void TickUI();
|
||||
}
|
||||
|
||||
public class Clock : MonoSingleton<Clock>
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
@ -7,11 +8,15 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace Base
|
||||
{
|
||||
public class UIInputControl:Utils.MonoSingleton<UIInputControl>
|
||||
public class UIInputControl : Utils.MonoSingleton<UIInputControl>, ITickUI
|
||||
{
|
||||
// 存储窗口及其激活键的字典
|
||||
public Dictionary<KeyCode, UIBase> UIwindowKeys = new();
|
||||
|
||||
private void Update()
|
||||
// 存储没有激活键的窗口列表
|
||||
private List<UIBase> noKeyWindows = new();
|
||||
|
||||
// 每帧更新逻辑
|
||||
public void TickUI()
|
||||
{
|
||||
foreach (var kvp in UIwindowKeys)
|
||||
{
|
||||
@ -22,60 +27,147 @@ namespace Base
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Init()
|
||||
{
|
||||
// 查找所有继承自 UIBase 的实例
|
||||
UIBase[] uiInstances = Object.FindObjectsByType<UIBase>(FindObjectsSortMode.None);
|
||||
UIwindowKeys.Clear();
|
||||
noKeyWindows.Clear();
|
||||
|
||||
var uiInstances = Resources.FindObjectsOfTypeAll<UIBase>();
|
||||
|
||||
foreach (var uiBase in uiInstances)
|
||||
{
|
||||
var key = uiBase.actionButton;
|
||||
|
||||
// 忽略 None 按键
|
||||
if (key == KeyCode.None)
|
||||
{
|
||||
noKeyWindows.Add(uiBase);
|
||||
uiBase.Hide();
|
||||
continue;
|
||||
|
||||
// 检查按键是否重复
|
||||
}
|
||||
if (UIwindowKeys.ContainsKey(key))
|
||||
{
|
||||
Debug.LogWarning($"Key '{key}' is already assigned to another window. Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 添加到字典
|
||||
UIwindowKeys[key] = uiBase;
|
||||
uiBase.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleWindowActivation(UIBase targetWindow)
|
||||
|
||||
private void HandleWindowActivation(UIBase targetWindow, bool isFunctionCall = false)
|
||||
{
|
||||
// 遍历所有窗口,关闭非目标窗口
|
||||
foreach (var kvp in UIwindowKeys)
|
||||
bool wasTargetVisible = targetWindow.IsVisible;
|
||||
bool anyOtherWindowOpen = false;
|
||||
|
||||
// 遍历所有窗口(包括有键和无键窗口)
|
||||
foreach (var kvp in UIwindowKeys.Concat(noKeyWindows.Select(w => new KeyValuePair<KeyCode, UIBase>(KeyCode.None, w))))
|
||||
{
|
||||
if (kvp.Value != targetWindow && kvp.Value.IsVisible)
|
||||
if (kvp.Value == targetWindow)
|
||||
{
|
||||
kvp.Value.Hide();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (kvp.Value.IsVisible)
|
||||
{
|
||||
if (!wasTargetVisible || isFunctionCall) // 只在目标窗口要打开时才关闭其他窗口
|
||||
{
|
||||
kvp.Value.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
anyOtherWindowOpen = true; // 记录是否有其他窗口打开
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 切换目标窗口的显示状态
|
||||
if (targetWindow.IsVisible)
|
||||
if (wasTargetVisible)
|
||||
{
|
||||
targetWindow.Hide(); // 如果已经打开,则关闭
|
||||
targetWindow.Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWindow.Show(); // 如果未打开,则打开
|
||||
targetWindow.Show();
|
||||
}
|
||||
|
||||
bool currentWindowState = !wasTargetVisible || anyOtherWindowOpen;
|
||||
if (Base.Clock.Instance.Pause != currentWindowState)
|
||||
{
|
||||
Base.Clock.Instance.Pause = currentWindowState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模拟按键输入切换窗口
|
||||
/// </summary>
|
||||
/// <param name="keyCode">要模拟的按键</param>
|
||||
public void SimulateKeyPress(KeyCode keyCode)
|
||||
{
|
||||
if (UIwindowKeys.TryGetValue(keyCode, out UIBase targetWindow))
|
||||
{
|
||||
HandleWindowActivation(targetWindow); // 调用内部逻辑处理
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"No window is assigned to the key '{keyCode}'.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开指定的窗口(无论是否有激活键)
|
||||
/// </summary>
|
||||
/// <param name="window">要打开的窗口</param>
|
||||
public void OpenWindow(UIBase window)
|
||||
{
|
||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
||||
{
|
||||
Debug.LogWarning("Cannot open the specified window as it is not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭指定的窗口(无论是否有激活键)
|
||||
/// </summary>
|
||||
/// <param name="window">要关闭的窗口</param>
|
||||
public void CloseWindow(UIBase window)
|
||||
{
|
||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
||||
{
|
||||
Debug.LogWarning("Cannot close the specified window as it is not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换指定窗口的显示状态(无论是否有激活键)
|
||||
/// </summary>
|
||||
/// <param name="window">要切换的窗口</param>
|
||||
public void ToggleWindow(UIBase window)
|
||||
{
|
||||
if (window == null || !(UIwindowKeys.ContainsValue(window) || noKeyWindows.Contains(window)))
|
||||
{
|
||||
Debug.LogWarning("Cannot toggle the specified window as it is not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWindowActivation(window, true); // 调用内部逻辑处理,标记为函数调用
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在对象销毁时清理事件监听
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
// 移除事件监听
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在对象启动时初始化
|
||||
/// </summary>
|
||||
protected override void OnStart()
|
||||
{
|
||||
// 注册场景加载事件
|
||||
@ -84,6 +176,10 @@ namespace Base
|
||||
// 初始化时调用一次
|
||||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景加载完成后重新初始化
|
||||
/// </summary>
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
// 场景加载完成后调用 Init 方法
|
||||
|
3
Client/Assets/Scripts/Camera.meta
Normal file
3
Client/Assets/Scripts/Camera.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f17e95f87b94882a0a6b913f4cd3521
|
||||
timeCreated: 1752978726
|
13
Client/Assets/Scripts/Camera/CameraControl.cs
Normal file
13
Client/Assets/Scripts/Camera/CameraControl.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Camera
|
||||
{
|
||||
public class CameraControl:MonoBehaviour,Base.ITick
|
||||
{
|
||||
public Entity.Entity focusedEntity=null;
|
||||
public void Tick()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Camera/CameraControl.cs.meta
Normal file
3
Client/Assets/Scripts/Camera/CameraControl.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f749a65b381541fab3f5dd5e487a457b
|
||||
timeCreated: 1752977849
|
@ -34,17 +34,49 @@ namespace Data
|
||||
base.Init(xmlDef);
|
||||
|
||||
var nodes = xmlDef.Elements("DrawNodeDef");
|
||||
if (nodes.Count() == 0)
|
||||
var xElements = nodes as XElement[] ?? nodes.ToArray();
|
||||
if (!xElements.Any())
|
||||
return false;
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var drawNode = new DrawNodeDef();
|
||||
drawNode.Init(node);
|
||||
drawNodes.Add(drawNode);
|
||||
}
|
||||
foreach (var node in xElements)
|
||||
{
|
||||
var drawNode = new DrawNodeDef();
|
||||
drawNode.Init(node);
|
||||
drawNodes.Add(drawNode);
|
||||
}
|
||||
|
||||
return true;;
|
||||
}
|
||||
// 重载 == 运算符
|
||||
public static bool operator ==(DrawingOrderDef a, DrawingOrderDef b)
|
||||
{
|
||||
if (ReferenceEquals(a, b)) return true; // 如果是同一个对象,直接返回 true
|
||||
if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) return false; // 如果其中一个为 null,返回 false
|
||||
|
||||
return AreEqual(a, b);
|
||||
}
|
||||
|
||||
// 重载 != 运算符
|
||||
public static bool operator !=(DrawingOrderDef a, DrawingOrderDef b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
// 判断两个 DrawingOrderDef 是否相等
|
||||
private static bool AreEqual(DrawingOrderDef a, DrawingOrderDef b)
|
||||
{
|
||||
// 比较 drawNodes 的数量
|
||||
if (a.drawNodes.Count != b.drawNodes.Count)
|
||||
return false;
|
||||
|
||||
// 递归比较每个 DrawNodeDef
|
||||
for (int i = 0; i < a.drawNodes.Count; i++)
|
||||
{
|
||||
if (!DrawNodeDef.AreEqual(a.drawNodes[i], b.drawNodes[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class DrawNodeDef : Define
|
||||
@ -77,16 +109,16 @@ namespace Data
|
||||
public Vector2 StringToVector(string vectorDef)
|
||||
{
|
||||
// 去掉可能存在的括号和多余的空格
|
||||
string cleanedInput = vectorDef.Replace("(", "").Replace(")", "").Trim();
|
||||
var cleanedInput = vectorDef.Replace("(", "").Replace(")", "").Trim();
|
||||
|
||||
// 使用正则表达式匹配两个浮点数
|
||||
Match match = Regex.Match(cleanedInput, @"\s*(-?\d+(\.\d*)?)\s*[, ]\s*(-?\d+(\.\d*)?)\s*");
|
||||
var match = Regex.Match(cleanedInput, @"\s*(-?\d+(\.\d*)?)\s*[, ]\s*(-?\d+(\.\d*)?)\s*");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
// 提取匹配到的两个浮点数
|
||||
float x = float.Parse(match.Groups[1].Value);
|
||||
float y = float.Parse(match.Groups[3].Value);
|
||||
var x = float.Parse(match.Groups[1].Value);
|
||||
var y = float.Parse(match.Groups[3].Value);
|
||||
|
||||
// 返回 Vector2 对象
|
||||
return new Vector2(x, y);
|
||||
@ -96,6 +128,30 @@ namespace Data
|
||||
return Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
// 判断两个 DrawNodeDef 是否相等
|
||||
public static bool AreEqual(DrawNodeDef a, DrawNodeDef b)
|
||||
{
|
||||
if (ReferenceEquals(a, b)) return true; // 如果是同一个对象,直接返回 true
|
||||
if (ReferenceEquals(a, null) || ReferenceEquals(b, null)) return false; // 如果其中一个为 null,返回 false
|
||||
// 比较基本属性
|
||||
if (a.drawNodeType != b.drawNodeType ||
|
||||
a.nodeName != b.nodeName ||
|
||||
a.position != b.position ||
|
||||
Math.Abs(a.FPS - b.FPS) > 0.001f) // 浮点数比较需要考虑精度
|
||||
return false;
|
||||
// 比较 children 的数量
|
||||
if (a.children.Count != b.children.Count)
|
||||
return false;
|
||||
// 递归比较每个子节点
|
||||
for (var i = 0; i < a.children.Count; i++)
|
||||
{
|
||||
if (!AreEqual(a.children[i], b.children[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -279,8 +279,14 @@ namespace Data
|
||||
value = reference;
|
||||
}
|
||||
}
|
||||
else if(field.FieldType.IsArray)
|
||||
{
|
||||
value = ProcessArrayField(field, element);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = Convert.ChangeType(element.Value, field.FieldType);
|
||||
}
|
||||
field.SetValue(define, value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -289,7 +295,44 @@ namespace Data
|
||||
}
|
||||
}
|
||||
}
|
||||
private static object ProcessArrayField(FieldInfo field, XElement element)
|
||||
{
|
||||
Type elementType = field.FieldType.GetElementType();
|
||||
if (elementType == null) return null;
|
||||
|
||||
var arrayElements = new List<object>();
|
||||
foreach (var liElement in element.Elements())
|
||||
{
|
||||
if (elementType.IsSubclassOf(typeof(Define)))
|
||||
{
|
||||
Define nestedDefine = (Define)Activator.CreateInstance(elementType);
|
||||
DefaultInitDefine(nestedDefine, liElement, elementType);
|
||||
arrayElements.Add(nestedDefine);
|
||||
}
|
||||
else if (elementType.IsArray) // 嵌套数组处理
|
||||
{
|
||||
// 递归处理嵌套数组
|
||||
var nestedArray = ProcessArrayField(
|
||||
new { FieldType = elementType }.GetType().GetField("FieldType"),
|
||||
liElement
|
||||
);
|
||||
arrayElements.Add(nestedArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 基本类型处理
|
||||
arrayElements.Add(Convert.ChangeType(liElement.Value, elementType));
|
||||
}
|
||||
}
|
||||
|
||||
// 构建结果数组
|
||||
Array resultArray = Array.CreateInstance(elementType, arrayElements.Count);
|
||||
for (int i = 0; i < arrayElements.Count; i++)
|
||||
{
|
||||
resultArray.SetValue(arrayElements[i], i);
|
||||
}
|
||||
return resultArray;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 List<c>XDocument</c> 中查找指定根元素名称的文档。
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
@ -11,6 +14,10 @@ namespace Data
|
||||
drawingOrder_up,
|
||||
drawingOrder_left,
|
||||
drawingOrder_right;
|
||||
|
||||
public string[] behaviorTree;
|
||||
|
||||
|
||||
public DrawingOrderDef GetDrawingOrder(Orientation orientation)
|
||||
{
|
||||
// 定义一个临时变量用于存储结果
|
||||
@ -48,4 +55,33 @@ namespace Data
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class BehaviorTreeDef : Define
|
||||
{
|
||||
public BehaviorTreeDef[] childTree;
|
||||
public string className;
|
||||
|
||||
public override bool Init(XElement xmlDef)
|
||||
{
|
||||
base.Init(xmlDef);
|
||||
|
||||
var nodes = xmlDef.Elements("Node");
|
||||
var xElements = nodes as XElement[] ?? nodes.ToArray();
|
||||
if (!xElements.Any())
|
||||
return false;
|
||||
|
||||
className = xmlDef.Attribute("className")?.Value;
|
||||
List<BehaviorTreeDef> children = new();
|
||||
foreach (var node in xElements)
|
||||
{
|
||||
var childNode = new BehaviorTreeDef();
|
||||
childNode.Init(node);
|
||||
children.Add(childNode);
|
||||
}
|
||||
|
||||
childTree = children.ToArray();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
35
Client/Assets/Scripts/Entity/AIBase.cs
Normal file
35
Client/Assets/Scripts/Entity/AIBase.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public abstract class AIBase
|
||||
{
|
||||
public virtual bool Run(Entity target)
|
||||
{
|
||||
foreach (var aiBase in children)
|
||||
{
|
||||
if (aiBase.Run(target))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public List<AIBase> children=new();
|
||||
}
|
||||
|
||||
public class ContinuousMove : AIBase
|
||||
{
|
||||
override public bool Run(Entity target)
|
||||
{
|
||||
target.gameObject.transform.position +=
|
||||
Time.deltaTime * target.runtimeAttributes.moveSpeed * target.direction;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class TrackPlayer : AIBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Entity/AIBase.cs.meta
Normal file
3
Client/Assets/Scripts/Entity/AIBase.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7dba424df1b6411f91925da8288cb91f
|
||||
timeCreated: 1752983113
|
@ -1,96 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Base;
|
||||
using Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Character : MonoBehaviour
|
||||
public class Character : Entity,ITick
|
||||
{
|
||||
private void Start()
|
||||
public CharacterDef characterDef;
|
||||
public GameObject body;
|
||||
public void Init()
|
||||
{
|
||||
if (Managers.DefineManager.Instance.defines.TryGetValue("DrawingOrderDef",out var typeDict))
|
||||
{
|
||||
GenerateDrawNode(typeDict.Values?.FirstOrDefault()as DrawingOrderDef);
|
||||
}
|
||||
}
|
||||
|
||||
public void Init(CharacterDef def)
|
||||
{
|
||||
|
||||
if (def == null)
|
||||
if (characterDef == null)
|
||||
return;
|
||||
GenerateDrawNode(def.GetDrawingOrder(Orientation.Down));
|
||||
}
|
||||
|
||||
// 生成图片或动画节点
|
||||
private void GenerateDrawNode(DrawingOrderDef def)
|
||||
public new void Tick()
|
||||
{
|
||||
// Debug.Log(def);
|
||||
// 删除现有子节点
|
||||
DeleteAllChildren();
|
||||
|
||||
// 生成根节点下的所有节点
|
||||
foreach (var nodeDef in def.drawNodes) GenerateNode(nodeDef, transform); // 在当前节点下生成
|
||||
}
|
||||
|
||||
// 递归生成节点
|
||||
private void GenerateNode(DrawNodeDef nodeDef, Transform parent)
|
||||
{
|
||||
// Debug.Log(nodeDef.nodeName);
|
||||
// 创建新的 GameObject 表示节点
|
||||
var nodeObject = new GameObject(nodeDef.nodeName);
|
||||
|
||||
// 设置父节点
|
||||
nodeObject.transform.SetParent(parent, false);
|
||||
|
||||
// 根据节点类型生成不同的内容
|
||||
switch (nodeDef.drawNodeType)
|
||||
{
|
||||
case DrawNodeType.Image:
|
||||
CreateImageNode(nodeObject);
|
||||
break;
|
||||
|
||||
case DrawNodeType.Animation:
|
||||
CreateAnimationNode(nodeObject);
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogWarning($"Unsupported node type: {nodeDef.drawNodeType}");
|
||||
break;
|
||||
}
|
||||
|
||||
// 递归生成子节点
|
||||
if (nodeDef.children != null && nodeDef.children.Count > 0)
|
||||
foreach (var childNodeDef in nodeDef.children)
|
||||
GenerateNode(childNodeDef, nodeObject.transform); // 在当前节点下生成子节点
|
||||
}
|
||||
|
||||
// 创建图片节点
|
||||
private void CreateImageNode(GameObject nodeObject)
|
||||
{
|
||||
// 添加 SpriteRenderer 组件表示图片
|
||||
var spriteRenderer = nodeObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.sprite = Resources.Load<Sprite>("DefaultImage"); // 加载默认图片
|
||||
spriteRenderer.color = Color.white; // 设置默认颜色
|
||||
}
|
||||
|
||||
// 创建动画节点
|
||||
private void CreateAnimationNode(GameObject nodeObject)
|
||||
{
|
||||
// 添加 Animator 组件表示动画
|
||||
var animator = nodeObject.AddComponent<Animator>();
|
||||
animator.runtimeAnimatorController =
|
||||
Resources.Load<RuntimeAnimatorController>("DefaultAnimation"); // 加载默认动画控制器
|
||||
}
|
||||
|
||||
private void DeleteAllChildren()
|
||||
{
|
||||
// 获取当前对象的 Transform
|
||||
var parentTransform = transform;
|
||||
|
||||
// 删除所有子对象
|
||||
foreach (Transform child in parentTransform) Destroy(child.gameObject); // 使用 Destroy 方法删除子对象
|
||||
base.Tick();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
Client/Assets/Scripts/Entity/Entity.cs
Normal file
35
Client/Assets/Scripts/Entity/Entity.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using Base;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public abstract class Entity:MonoBehaviour,ITick
|
||||
{
|
||||
public bool playerControlled = false;
|
||||
public List<AIBase> aiTree=new();
|
||||
public Data.AttributesDef runtimeAttributes;
|
||||
public Vector3 direction;
|
||||
public void Tick()
|
||||
{
|
||||
foreach (var aiBase in aiTree)
|
||||
{
|
||||
if (aiBase.Run(this))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void TryAttck()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void OnHit(Entity from)
|
||||
{
|
||||
var hit = from.runtimeAttributes.attack - runtimeAttributes.defense;
|
||||
if (hit < 0)
|
||||
hit = from.runtimeAttributes.attack / 100;
|
||||
runtimeAttributes.health -= hit;
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Entity/Entity.cs.meta
Normal file
3
Client/Assets/Scripts/Entity/Entity.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbde354e0bcc4409b3378ee9b698ddc0
|
||||
timeCreated: 1752932072
|
45
Client/Assets/Scripts/Entity/Outline.cs
Normal file
45
Client/Assets/Scripts/Entity/Outline.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Entity
|
||||
{
|
||||
public class Outline:MonoBehaviour
|
||||
{
|
||||
public GameObject body;
|
||||
public SpriteRenderer outlineRenderer;
|
||||
|
||||
public void Show()
|
||||
{
|
||||
var size = GetSize();
|
||||
outlineRenderer.gameObject.SetActive(true);
|
||||
outlineRenderer.size = size;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
outlineRenderer.gameObject.SetActive(false);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定对象及其所有子对象组成的图像的大小。
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// 返回一个 Vector3 对象,表示对象在世界空间中的总大小(宽度、高度、深度)。
|
||||
/// 如果没有找到任何渲染器,则返回 (-1, -1, -1) 表示无效大小。
|
||||
/// </returns>
|
||||
public Vector3 GetSize()
|
||||
{
|
||||
var renderers = body.GetComponentsInChildren<Renderer>();
|
||||
|
||||
if (renderers.Length == 0)
|
||||
{
|
||||
return new(-1,-1);
|
||||
}
|
||||
var totalBounds = renderers[0].bounds;
|
||||
for (var i = 1; i < renderers.Length; i++)
|
||||
{
|
||||
totalBounds.Encapsulate(renderers[i].bounds);
|
||||
}
|
||||
var size = totalBounds.size;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
2
Client/Assets/Scripts/Entity/Outline.cs.meta
Normal file
2
Client/Assets/Scripts/Entity/Outline.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acf99b9aa18d4ab9b4ce796d513d476b
|
15
Client/Assets/Scripts/Managers/Generator.cs
Normal file
15
Client/Assets/Scripts/Managers/Generator.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
public class Generator:MonoBehaviour
|
||||
{
|
||||
public GameObject entityLevel;
|
||||
|
||||
|
||||
public void GenerateEntity(Data.PawnDef pawnDef, Vector3 pos)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Managers/Generator.cs.meta
Normal file
3
Client/Assets/Scripts/Managers/Generator.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d78f1b5a44344a4a987e308d3b9478cc
|
||||
timeCreated: 1752937967
|
9
Client/Assets/Scripts/Prefab/EntityPrefab.cs
Normal file
9
Client/Assets/Scripts/Prefab/EntityPrefab.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Prefab
|
||||
{
|
||||
public class EntityPrefab:MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Prefab/EntityPrefab.cs.meta
Normal file
3
Client/Assets/Scripts/Prefab/EntityPrefab.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b20b1846b9ef47db83c2ac8c4c4e82cb
|
||||
timeCreated: 1752975550
|
@ -11,11 +11,6 @@ namespace UI
|
||||
|
||||
public Prefab.TextPrefab textTemplate;
|
||||
public Prefab.ButtonPrefab buttonTemplate;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
actionButton = KeyCode.F1;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
@ -27,6 +22,9 @@ namespace UI
|
||||
InitEvent();
|
||||
InitCharacter();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void InitEvent()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
@ -42,7 +40,7 @@ namespace UI
|
||||
void InitCharacter()
|
||||
{
|
||||
var title = InstantiatePrefab(textTemplate, menuContent.transform);
|
||||
title.Label = "点击切换人物";
|
||||
title.Label = "生成人物";
|
||||
|
||||
var defList = Managers.DefineManager.Instance.QueryNamedDefinesByType<Data.CharacterDef>();
|
||||
foreach (var def in defList)
|
||||
|
24
Client/Assets/Scripts/UI/EscUI.cs
Normal file
24
Client/Assets/Scripts/UI/EscUI.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace UI
|
||||
{
|
||||
public class EscUI:UIBase
|
||||
{
|
||||
public void ContinueButton()
|
||||
{
|
||||
Base.UIInputControl.Instance.CloseWindow(this);
|
||||
}
|
||||
|
||||
public void ExitButton()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false; // 停止编辑器播放模式
|
||||
#else
|
||||
Application.Quit(); // 关闭游戏
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SettingsButton()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/UI/EscUI.cs.meta
Normal file
3
Client/Assets/Scripts/UI/EscUI.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eac7c56e1474c4ea646c0a408d293a3
|
||||
timeCreated: 1752932683
|
8
Client/Assets/Scripts/UI/PauseUI.cs
Normal file
8
Client/Assets/Scripts/UI/PauseUI.cs
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class PauseUI : UIBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/UI/PauseUI.cs.meta
Normal file
3
Client/Assets/Scripts/UI/PauseUI.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcc7e9d015ee465684be520b65c2e182
|
||||
timeCreated: 1752932641
|
Reference in New Issue
Block a user