(client) chore:Clean code #47

Merged
TheRedApricot merged 1 commits from TheRedApricot/Gen_Hack-and-Slash-Roguelite:main into main 2025-08-28 16:21:26 +08:00
76 changed files with 5689 additions and 445 deletions

View File

@ -195,6 +195,8 @@ TilemapRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1 m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1 m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
@ -216,6 +218,7 @@ TilemapRenderer:
m_AutoUVMaxDistance: 0.5 m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89 m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
@ -242,37 +245,6 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 613797070} m_Father: {fileID: 613797070}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &309861628
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 309861630}
m_Layer: 0
m_Name: "\u5B9E\u4F53\u5C42"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &309861630
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 309861628}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.17242, y: 0.05575, z: 1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &613797067 --- !u!1 &613797067
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -290,7 +262,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!114 &613797068 --- !u!114 &613797068
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -388,7 +360,6 @@ MonoBehaviour:
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0 m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0 m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings: m_TaaSettings:
m_Quality: 3 m_Quality: 3
m_FrameInfluence: 0.1 m_FrameInfluence: 0.1
@ -396,6 +367,7 @@ MonoBehaviour:
m_MipBias: 0 m_MipBias: 0
m_VarianceClampScale: 0.9 m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0 m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!81 &1057087088 --- !u!81 &1057087088
AudioListener: AudioListener:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -546,6 +518,8 @@ TilemapRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0 m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1 m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1 m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1 m_RenderingLayerMask: 1
m_RendererPriority: 0 m_RendererPriority: 0
m_Materials: m_Materials:
@ -567,6 +541,7 @@ TilemapRenderer:
m_AutoUVMaxDistance: 0.5 m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89 m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0} m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
@ -593,51 +568,6 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 613797070} m_Father: {fileID: 613797070}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1371068281
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1371068282}
- component: {fileID: 1371068283}
m_Layer: 0
m_Name: Loader
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1371068282
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1371068281}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1371068283
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1371068281}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 147e91e6929d90a4fb877c0b0a6b608c, type: 3}
m_Name:
m_EditorClassIdentifier:
entityManager: {fileID: 2036983433}
--- !u!1 &2036983430 --- !u!1 &2036983430
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -655,7 +585,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!4 &2036983432 --- !u!4 &2036983432
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -684,8 +614,11 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
isGlobal: 1 isGlobal: 1
entityLevel: {fileID: 309861628} characterPrefab: {fileID: 0}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3} monsterPrefab: {fileID: 0}
buildingPrefab: {fileID: 0}
bulletPrefab: {fileID: 0}
pickupPrefab: {fileID: 0}
defaultEntityPrefab: {fileID: 7975757421877276383, guid: 89661daa5f100c64783f0ad9cd37a7ff, type: 3} defaultEntityPrefab: {fileID: 7975757421877276383, guid: 89661daa5f100c64783f0ad9cd37a7ff, type: 3}
--- !u!114 &2036983434 --- !u!114 &2036983434
MonoBehaviour: MonoBehaviour:
@ -716,7 +649,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!114 &2104915507 --- !u!114 &2104915507
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -751,6 +684,4 @@ SceneRoots:
- {fileID: 1057087090} - {fileID: 1057087090}
- {fileID: 613797070} - {fileID: 613797070}
- {fileID: 2104915508} - {fileID: 2104915508}
- {fileID: 309861630}
- {fileID: 2036983432} - {fileID: 2036983432}
- {fileID: 1371068282}

View File

@ -1,9 +1,7 @@
using Data;
using Parsing;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using Data;
using UnityEngine;
namespace AI namespace AI
{ {
@ -35,7 +33,7 @@ namespace AI
{ {
// 条件函数,返回 true 表示满足条件 // 条件函数,返回 true 表示满足条件
private Func<Entity.Entity, bool> condition; private Func<Entity.Entity, bool> condition;
public override JobBase GetJob(Entity.Entity target) public override JobBase GetJob(Entity.Entity target)
{ {
// 检查条件是否满足 // 检查条件是否满足
@ -75,5 +73,5 @@ namespace AI
} }
} }
} }
} }

View File

@ -1,10 +1,8 @@
using System;
using AI;
using Data; using Data;
using System;
namespace Utils namespace AI
{ {
public static class BehaviorTree public static class BehaviorTree
{ {
/// <summary> /// <summary>

View File

@ -1,9 +1,5 @@
using System.Collections.Generic;
using Base;
using Data; using Data;
using Managers; using Managers;
using Prefab;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
namespace AI namespace AI

View File

@ -1,6 +1,6 @@
using System; using System;
using UnityEngine;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Base namespace Base
@ -8,7 +8,7 @@ namespace Base
// 定义渐变方向枚举 // 定义渐变方向枚举
[AddComponentMenu("UI/Effects/Gradient")] [AddComponentMenu("UI/Effects/Gradient")]
public enum Dir public enum Dir
{ {
Horizontal, // 水平方向 Horizontal, // 水平方向
Vertical, // 垂直方向 Vertical, // 垂直方向
} }
@ -71,7 +71,7 @@ namespace Base
} }
} }
} }
// 绘制垂直方向的渐变 // 绘制垂直方向的渐变
private void DrawVertical(VertexHelper vh, List<UIVertex> vertices, int count) private void DrawVertical(VertexHelper vh, List<UIVertex> vertices, int count)
{ {

View File

@ -1,8 +1,7 @@
// C# // C#
using Managers; // 确保日志命名空间正确
using System.Collections; using System.Collections;
using System.Collections.Generic; // 新增用于List using System.Collections.Generic; // 新增用于List
using Logging;
using Managers; // 确保日志命名空间正确
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -18,7 +17,7 @@ namespace Base
public GameObject loadingUI; public GameObject loadingUI;
// 假设 CustomProgressBar 是一个自定义组件,其 API 与原代码使用方式一致 // 假设 CustomProgressBar 是一个自定义组件,其 API 与原代码使用方式一致
// 如果这里是 UnityEngine.UI.Image需要完全改变 Progress 和 Opacity 的实现 // 如果这里是 UnityEngine.UI.Image需要完全改变 Progress 和 Opacity 的实现
public Gradient progressBar; // 自定义进度条组件 public Gradient progressBar; // 自定义进度条组件
public TMP_Text describeText; // 描述文本 public TMP_Text describeText; // 描述文本
public float duration = 0.5f; // 每个步骤的过渡时间 public float duration = 0.5f; // 每个步骤的过渡时间
@ -96,7 +95,7 @@ namespace Base
// 在 Awake 中初始化管理器列表并注册,确保在 Start 之前完成 // 在 Awake 中初始化管理器列表并注册,确保在 Start 之前完成
_managersToLoad = new List<ILaunchManager> _managersToLoad = new List<ILaunchManager>
{ {
new Logging.LoggerManagerWrapper(), // UnityLogger的包装器 Logging.UnityLogger.Instance, // UnityLogger的包装器
Managers.DefineManager.Instance, Managers.DefineManager.Instance,
Managers.PackagesImageManager.Instance, Managers.PackagesImageManager.Instance,
Managers.TileManager.Instance, Managers.TileManager.Instance,
@ -187,7 +186,7 @@ namespace Base
} }
} }
} }
/// <summary> /// <summary>
/// 协程:按顺序加载所有管理器。 /// 协程:按顺序加载所有管理器。
/// </summary> /// </summary>
@ -314,7 +313,7 @@ namespace Base
SceneManager.LoadScene(scene); SceneManager.LoadScene(scene);
} }
} }
} }

View File

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UI; using UI;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
namespace Base namespace Base
{ {
@ -72,7 +70,7 @@ namespace Base
needUpdate = false; needUpdate = false;
return; return;
} }
if(_visibleWindows.Any(window => window.isInputOccupied)) if (_visibleWindows.Any(window => window.isInputOccupied))
return; return;
foreach (var window in _allWindows) foreach (var window in _allWindows)
{ {
@ -114,10 +112,10 @@ namespace Base
// 显示目标窗口并更新缓存与暂停状态 // 显示目标窗口并更新缓存与暂停状态
windowToShow.Show(); windowToShow.Show();
var itick=windowToShow as ITickUI; var itick = windowToShow as ITickUI;
if (itick != null) if (itick != null)
Base.Clock.AddTickUI(itick); Base.Clock.AddTickUI(itick);
needUpdate = true; needUpdate = true;
} }
@ -202,7 +200,7 @@ namespace Base
protected override void OnStart() protected override void OnStart()
{ {
SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneLoaded += OnSceneLoaded;
RegisterAllWindows(); RegisterAllWindows();
} }

View File

@ -16,7 +16,7 @@ namespace CameraControl
private bool _isDragging = false; private bool _isDragging = false;
private Camera _camera; private Camera _camera;
private int dimensionId; private int dimensionId;
private string[] dimensionList; private string[] dimensionList;
@ -46,7 +46,7 @@ namespace CameraControl
// 这确保了如果CameraControl是DontDestroyOnLoad在切换场景后也能正确工作。 // 这确保了如果CameraControl是DontDestroyOnLoad在切换场景后也能正确工作。
Init(); Init();
} }
private void Init() private void Init()
{ {
@ -68,7 +68,7 @@ namespace CameraControl
// 初始化维度数据 (假设 Program.Instance 总是已初始化) // 初始化维度数据 (假设 Program.Instance 总是已初始化)
dimensionId = 0; // 默认从第一个维度开始 dimensionId = 0; // 默认从第一个维度开始
dimensionList = Program.Instance.Dimensions; dimensionList = Program.Instance.Dimensions;
if (dimensionList != null && dimensionList.Length > 0) if (dimensionList != null && dimensionList.Length > 0)
{ {
SetCameraPositionForDimension(0); SetCameraPositionForDimension(0);
@ -78,7 +78,7 @@ namespace CameraControl
Debug.LogWarning("Dimension list is empty or null from Program.Instance. Cannot set initial camera position for dimensions."); Debug.LogWarning("Dimension list is empty or null from Program.Instance. Cannot set initial camera position for dimensions.");
} }
} }
public void NextDimension() public void NextDimension()
{ {
if (_camera == null) if (_camera == null)
@ -94,10 +94,10 @@ namespace CameraControl
// 1. 保存当前相机的真实位置到当前维度 (假设 Program.Instance 总是已初始化) // 1. 保存当前相机的真实位置到当前维度 (假设 Program.Instance 总是已初始化)
// 维度ID范围检查仍然保留因为这是数组访问的安全保障 // 维度ID范围检查仍然保留因为这是数组访问的安全保障
if (dimensionId >= 0 && dimensionId < dimensionList.Length) if (dimensionId >= 0 && dimensionId < dimensionList.Length)
{ {
// Program.Instance 假设不会为 null // Program.Instance 假设不会为 null
var currentDimension = Program.Instance.GetDimension(dimensionList[dimensionId]); var currentDimension = Program.Instance.GetDimension(dimensionList[dimensionId]);
if (currentDimension != null) if (currentDimension != null)
{ {
currentDimension.cameraPosition = _camera.transform.position; currentDimension.cameraPosition = _camera.transform.position;
@ -135,7 +135,7 @@ namespace CameraControl
// Program.Instance 假设不会为 null // Program.Instance 假设不会为 null
// 确保获取到的 Dimension 对象不为 null // 确保获取到的 Dimension 对象不为 null
var dimension = Program.Instance.GetDimension(dimensionList[id]); var dimension = Program.Instance.GetDimension(dimensionList[id]);
if (dimension) if (dimension)
{ {
Vector3 cameraPosition = dimension.cameraPosition; Vector3 cameraPosition = dimension.cameraPosition;
@ -152,7 +152,7 @@ namespace CameraControl
if (_camera == null) return; // 确保相机存在 if (_camera == null) return; // 确保相机存在
// 假设 Program.Instance 总是已初始化 // 假设 Program.Instance 总是已初始化
if (Program.Instance.FocusedEntity) if (Program.Instance.FocusedEntity)
{ {
var targetPosition = new Vector3( var targetPosition = new Vector3(
Program.Instance.FocusedEntity.Position.x, Program.Instance.FocusedEntity.Position.x,
@ -171,7 +171,7 @@ namespace CameraControl
NextDimension(); NextDimension();
} }
} }
public void TickUI() public void TickUI()
{ {
if (!_camera) // 确保相机存在 if (!_camera) // 确保相机存在
@ -199,7 +199,7 @@ namespace CameraControl
_dragOrigin = _camera.ScreenToWorldPoint(Input.mousePosition); _dragOrigin = _camera.ScreenToWorldPoint(Input.mousePosition);
_isDragging = true; _isDragging = true;
// 假设 Program.Instance 总是已初始化 // 假设 Program.Instance 总是已初始化
if (Program.Instance.FocusedEntity) if (Program.Instance.FocusedEntity)
{ {
Program.Instance.FocusedEntity.PlayerControlled = false; Program.Instance.FocusedEntity.PlayerControlled = false;
Program.Instance.SetFocusedEntity(null); Program.Instance.SetFocusedEntity(null);

View File

@ -1,13 +1,10 @@
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using Newtonsoft.Json;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking;
using Formatting = Newtonsoft.Json.Formatting; using Formatting = Newtonsoft.Json.Formatting;
namespace Configs namespace Configs
@ -182,7 +179,7 @@ namespace Configs
var xmlFiles = Directory.GetFiles(dir, "*.xml", SearchOption.AllDirectories); var xmlFiles = Directory.GetFiles(dir, "*.xml", SearchOption.AllDirectories);
xmlFilePaths.AddRange(xmlFiles); xmlFilePaths.AddRange(xmlFiles);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -275,7 +272,7 @@ namespace Configs
// 加载指定路径下的所有资源 // 加载指定路径下的所有资源
var resources = Resources.LoadAll<T>(path); var resources = Resources.LoadAll<T>(path);
foreach (var resource in resources) foreach (var resource in resources)
{ {
if (resource != null) if (resource != null)

View File

@ -7,10 +7,10 @@ namespace Data
public class BehaviorTreeDef : Define public class BehaviorTreeDef : Define
{ {
public BehaviorTreeDef[] childTree; public BehaviorTreeDef[] childTree;
public string className= "ThinkNode_Selector"; public string className = "ThinkNode_Selector";
public string value; public string value;
public override bool Init(XElement xmlDef) public override bool Init(XElement xmlDef)
{ {
base.Init(xmlDef); base.Init(xmlDef);
@ -23,7 +23,7 @@ namespace Data
var xElements = nodes as XElement[] ?? nodes.ToArray(); var xElements = nodes as XElement[] ?? nodes.ToArray();
if (!xElements.Any()) if (!xElements.Any())
return true; // 没有子节点也是有效的 return true; // 没有子节点也是有效的
List<BehaviorTreeDef> children = new(); List<BehaviorTreeDef> children = new();
foreach (var node in xElements) foreach (var node in xElements)
{ {

View File

@ -1,6 +1,6 @@
namespace Data namespace Data
{ {
public class BulletDef:EntityDef public class BulletDef : EntityDef
{ {
public string className; public string className;
public string value; public string value;

View File

@ -1,10 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using UnityEngine;
namespace Data namespace Data
{ {
public class CharacterDef : EntityDef public class CharacterDef : EntityDef

View File

@ -1,7 +1,4 @@
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;

View File

@ -1,3 +1,4 @@
using Configs;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -5,9 +6,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Configs;
using UnityEngine; using UnityEngine;
using Object = System.Object;
namespace Data namespace Data
{ {

View File

@ -43,7 +43,7 @@ namespace Data
public DrawNodeDef rangedAttack_up; public DrawNodeDef rangedAttack_up;
public DrawNodeDef rangedAttack_left; public DrawNodeDef rangedAttack_left;
public DrawNodeDef rangedAttack_right; public DrawNodeDef rangedAttack_right;
public DrawNodeDef GetDrawNodeDef(EntityState state, Orientation orientation, public DrawNodeDef GetDrawNodeDef(EntityState state, Orientation orientation,
out Orientation? fallbackOrientation) out Orientation? fallbackOrientation)
{ {
@ -237,7 +237,7 @@ namespace Data
{ {
base.Init(xmlDef); base.Init(xmlDef);
nodeName = xmlDef.Attribute("name")?.Value??"noName"; nodeName = xmlDef.Attribute("name")?.Value ?? "noName";
position = StringToVector(xmlDef.Attribute("position")?.Value ?? "(0 0)"); position = StringToVector(xmlDef.Attribute("position")?.Value ?? "(0 0)");
FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out var result) ? result : 1.0f; FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out var result) ? result : 1.0f;
return false; return false;

View File

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace Data namespace Data
{ {
public class EntityDef : Define public class EntityDef : Define

View File

@ -46,5 +46,5 @@ namespace Data
} }
} }

View File

@ -1,6 +1,6 @@
namespace Data namespace Data
{ {
public class MonsterDef:EntityDef public class MonsterDef : EntityDef
{ {
public WeaponDef weapon; public WeaponDef weapon;
} }

View File

@ -22,6 +22,6 @@ namespace Entity
attackTargetCount = def.attackTargetCount; attackTargetCount = def.attackTargetCount;
} }
public Attributes() public Attributes()
{} { }
} }
} }

View File

@ -1,10 +1,8 @@
using Base;
using Data;
using UnityEngine; using UnityEngine;
namespace Entity namespace Entity
{ {
public class Building:Entity public class Building : Entity
{ {
public override void SetTarget(Vector3 pos) public override void SetTarget(Vector3 pos)
{ {

View File

@ -2,7 +2,7 @@ using UnityEngine;
namespace Entity namespace Entity
{ {
public class BuildingOutline:Outline public class BuildingOutline : Outline
{ {
public BoxCollider2D boxCollider; public BoxCollider2D boxCollider;
override public void Init() override public void Init()

View File

@ -1,7 +1,5 @@
using System;
using Base; using Base;
using Data; using Data;
using Prefab;
using UnityEngine; using UnityEngine;
namespace Entity namespace Entity
@ -10,7 +8,7 @@ namespace Entity
{ {
public Entity bulletSource; public Entity bulletSource;
public float lifeTime = 10; public float lifeTime = 10;
public override void SetTarget(Vector3 pos) public override void SetTarget(Vector3 pos)
{ {
base.SetTarget(pos); base.SetTarget(pos);
@ -20,7 +18,7 @@ namespace Entity
protected override void AutoBehave() protected override void AutoBehave()
{ {
TryMove(); TryMove();
lifeTime-=Time.deltaTime; lifeTime -= Time.deltaTime;
if (lifeTime <= 0) if (lifeTime <= 0)
{ {
Kill(); Kill();
@ -55,7 +53,7 @@ namespace Entity
// 计算当前向上方向与目标方向之间的角度 // 计算当前向上方向与目标方向之间的角度
var angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg; var angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg;
// 应用旋转 // 应用旋转
transform.rotation = Quaternion.Euler(0f, 0f, angle); transform.rotation = Quaternion.Euler(0f, 0f, angle);

View File

@ -1,10 +1,6 @@
using System;
using System.Linq;
using Data; using Data;
using Item; using Item;
using Managers;
using UnityEngine; using UnityEngine;
using Utils;
// 添加 System 命名空间以使用 Action // 添加 System 命名空间以使用 Action
namespace Entity namespace Entity
@ -29,7 +25,7 @@ namespace Entity
} }
public Inventory Inventory { get; private set; } public Inventory Inventory { get; private set; }
public override void Init(EntityDef entityDef) public override void Init(EntityDef entityDef)
{ {

View File

@ -1,13 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AI; using AI;
using Base; using Base;
using Data; using Data;
using Item; using Item;
using Managers; using Managers;
using Prefab; using Prefab;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
@ -177,7 +177,7 @@ namespace Entity
public virtual void Init(EntityDef entityDef) public virtual void Init(EntityDef entityDef)
{ {
attributes = new Attributes(entityDef.attributes); attributes = new Attributes(entityDef.attributes);
aiTree = Utils.BehaviorTree.ConvertToAIBase(entityDef.behaviorTree); aiTree = AI.BehaviorTree.ConvertToAIBase(entityDef.behaviorTree);
affiliation = entityDef.affiliation?.defName; affiliation = entityDef.affiliation?.defName;
InitBody(entityDef.drawingOrder); InitBody(entityDef.drawingOrder);
this.entityDef = entityDef; this.entityDef = entityDef;
@ -219,7 +219,7 @@ namespace Entity
// 实例化imagePrefab作为默认占位符 // 实例化imagePrefab作为默认占位符
targetObj = Instantiate(imagePrefab.gameObject, body.transform); targetObj = Instantiate(imagePrefab.gameObject, body.transform);
targetObj.name = $"{state}_{orientation}_Default"; targetObj.name = $"{state}_{orientation}_Default";
targetObj.transform.localPosition=Vector3.zero; targetObj.transform.localPosition = Vector3.zero;
var imagePrefabCom = targetObj.GetComponent<ImagePrefab>(); var imagePrefabCom = targetObj.GetComponent<ImagePrefab>();
if (imagePrefabCom != null) if (imagePrefabCom != null)
{ {

View File

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Item;
using UnityEngine; using UnityEngine;
namespace Entity namespace Entity

View File

@ -4,7 +4,7 @@ using Managers;
namespace Entity namespace Entity
{ {
public class Monster:Entity public class Monster : Entity
{ {
private WeaponResource weapon; private WeaponResource weapon;
public override void Init(EntityDef entityDef) public override void Init(EntityDef entityDef)

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Managers; using Managers;
using Prefab; using Prefab;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
@ -9,15 +9,15 @@ namespace Entity
public class Outline : MonoBehaviour public class Outline : MonoBehaviour
{ {
public RightMenuPrefab rightMenuPrefab; public RightMenuPrefab rightMenuPrefab;
public GameObject body; public GameObject body;
public SpriteRenderer outlineRenderer; public SpriteRenderer outlineRenderer;
public CapsuleCollider2D outlineCollider; public CapsuleCollider2D outlineCollider;
public ProgressBarPrefab progressBarPrefab; public ProgressBarPrefab progressBarPrefab;
public Entity entity; public Entity entity;
public static Vector3 minimum=new(0.5f,0.5f,0.5f); public static Vector3 minimum = new(0.5f, 0.5f, 0.5f);
public virtual void Init() public virtual void Init()
{ {
@ -116,7 +116,7 @@ namespace Entity
private void BecomeDefault() private void BecomeDefault()
{ {
entity.Kill(); entity.Kill();
EntityManage.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId,entity.Position); EntityManage.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId, entity.Position);
} }
private void StartControl() private void StartControl()

View File

@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Base; using Base;
using Data; using Data;
using Item; using Item;
using Prefab; using Prefab;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
namespace Entity namespace Entity
{ {
public class Pickup:Entity public class Pickup : Entity
{ {
public ItemResource itemResource; public ItemResource itemResource;
protected override void AutoBehave() protected override void AutoBehave()
@ -18,7 +18,7 @@ namespace Entity
public override void SetTarget(Vector3 pos) public override void SetTarget(Vector3 pos)
{ {
} }
public void Init(ItemDef itemDef) public void Init(ItemDef itemDef)

View File

@ -1,12 +1,10 @@
using UnityEngine;
namespace Item namespace Item
{ {
public class ItemBase public class ItemBase
{ {
public ItemResource resource; public ItemResource resource;
public int count=0; public int count = 0;
} }
} }

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Data; using Data;
using Managers; using Managers;
using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Item namespace Item

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq; // Added for LINQ
using Base; using Base;
using Data; using Data;
using Entity; using Entity;
using Prefab; using Prefab;
using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
@ -15,11 +14,11 @@ namespace Item
public Attributes Attributes { get; private set; } public Attributes Attributes { get; private set; }
public BulletDef Bullet { get; private set; } public BulletDef Bullet { get; private set; }
public WeaponType Type { get; private set; } public WeaponType Type { get; private set; }
public DrawNodeDef AttackAnimationDef { get; private set; } public DrawNodeDef AttackAnimationDef { get; private set; }
public float AttackAnimationTime{get; private set;} public float AttackAnimationTime { get; private set; }
public float AttackDetectionTime{get;private set;} public float AttackDetectionTime { get; private set; }
/// <summary> /// <summary>
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。 /// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
@ -76,12 +75,12 @@ namespace Item
Debug.LogError("InstantiateAttackAnimation: 无法加载 Prefab/Animation."); Debug.LogError("InstantiateAttackAnimation: 无法加载 Prefab/Animation.");
return (null, Array.Empty<ITick>()); return (null, Array.Empty<ITick>());
} }
// 逻辑修改说明 2调用修改后的私有辅助方法来创建 GameObject 层次结构。 // 逻辑修改说明 2调用修改后的私有辅助方法来创建 GameObject 层次结构。
var animationRoot = _CreateBodyPartGameObject( var animationRoot = _CreateBodyPartGameObject(
AttackAnimationDef, AttackAnimationDef,
parent, parent,
imagePrefab, imagePrefab,
animatorPrefab); animatorPrefab);
if (animationRoot == null) if (animationRoot == null)
@ -91,9 +90,9 @@ namespace Item
} }
// 逻辑修改说明 3收集所有实现了 ITick 接口的组件。 // 逻辑修改说明 3收集所有实现了 ITick 接口的组件。
var tickComponents = animationRoot.GetComponentsInChildren<ITick>(true); var tickComponents = animationRoot.GetComponentsInChildren<ITick>(true);
// GetComponentsInChildren(true) 会查找包括自身在内的所有子对象上的组件,即使它们是处于非活动状态。 // GetComponentsInChildren(true) 会查找包括自身在内的所有子对象上的组件,即使它们是处于非活动状态。
return (animationRoot, tickComponents); return (animationRoot, tickComponents);
} }
@ -112,7 +111,7 @@ namespace Item
if (parent == null) if (parent == null)
{ {
// 逻辑修改说明:这里直接返回 null 更合适,因为没有父节点无法创建实例。 // 逻辑修改说明:这里直接返回 null 更合适,因为没有父节点无法创建实例。
Debug.LogWarning($"CreateBodyPartGameObject: 父节点为null (节点名: {drawNode.nodeName ?? "Unnamed DrawNode"})"); Debug.LogWarning($"CreateBodyPartGameObject: 父节点为null (节点名: {drawNode.nodeName ?? "Unnamed DrawNode"})");
return null; return null;
} }

View File

@ -15,7 +15,7 @@ namespace Logging
public string StackTrace; public string StackTrace;
public override string ToString() => public override string ToString() =>
$"[{Timestamp:HH:mm:ss}] [{Type}] {Message}" + $"[{Timestamp:HH:mm:ss}] [{Type}] {Message}" +
(Type == LogType.Exception ? $"\n{StackTrace}" : ""); (Type == LogType.Exception ? $"\n{StackTrace}" : "");
} }
@ -27,8 +27,10 @@ namespace Logging
public static int MaxLogs public static int MaxLogs
{ {
get => _maxLogs; get => _maxLogs;
set { set
lock (_lock) { {
lock (_lock)
{
_maxLogs = Mathf.Max(value, 1); // 最小值为1 _maxLogs = Mathf.Max(value, 1); // 最小值为1
TrimExcess(); TrimExcess();
} }

View File

@ -1,17 +0,0 @@
using Managers;
using UnityEngine;
namespace Logging
{
public class LoggerManagerWrapper : ILaunchManager
{
public string StepDescription => "初始化日志";
public void Init()
{
Logging.UnityLogger.Init();
}
public void Clear()
{
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ffa9f8b447ee49f486398248d438f7ca
timeCreated: 1756128101

View File

@ -1,57 +1,66 @@
using Managers;
using Serilog; using Serilog;
using UnityEngine; using UnityEngine;
using Utils;
using SerilogLogger = Serilog.Core.Logger; using SerilogLogger = Serilog.Core.Logger;
namespace Logging namespace Logging
{ {
public static class UnityLogger public class UnityLogger : Singleton<UnityLogger>, ILaunchManager
{ {
private static readonly SerilogLogger Logger = new LoggerConfiguration() private bool _initialized = false;
private readonly SerilogLogger _logger = new LoggerConfiguration()
.WriteTo.File("Logs/UnityLog.txt") .WriteTo.File("Logs/UnityLog.txt")
.CreateLogger(); .CreateLogger();
private static bool _initialized = false;
public static void Init() public void Init()
{ {
if(_initialized) if (_initialized) return;
return;
Application.logMessageReceived += OnLogMessageReceived; Application.logMessageReceivedThreaded += OnLogMessageReceived;
_initialized = true; _initialized = true;
} }
private static void OnLogMessageReceived(string logString, string stackTrace, LogType type) public void Clear()
{
}
public string StepDescription => "初始化日志";
private void OnLogMessageReceived(string logString, string stackTrace, LogType type)
{ {
switch (type) switch (type)
{ {
case LogType.Assert: case LogType.Assert:
{ {
Logger.Warning("\nContent: {0}", logString); _logger.Warning("\nContent: {0}", logString);
break; break;
} }
case LogType.Log: case LogType.Log:
{ {
Logger.Information("\nContent: {0}", logString); _logger.Information("\nContent: {0}", logString);
break; break;
} }
case LogType.Warning: case LogType.Warning:
{ {
Logger.Warning("\nContent: {0}", logString); _logger.Warning("\nContent: {0}", logString);
break; break;
} }
case LogType.Error: case LogType.Error:
{ {
Logger.Error("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]); _logger.Error("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break; break;
} }
case LogType.Exception: case LogType.Exception:
{ {
Logger.Fatal("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]); _logger.Fatal("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break; break;
} }
default: default:
{ {
Logger.Information("\nContent: {0}", logString); _logger.Information("\nContent: {0}", logString);
break; break;
} }
} }
} }
} }

View File

@ -1,7 +1,7 @@
using Data;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Data;
using UnityEngine; using UnityEngine;
namespace Managers namespace Managers
@ -10,7 +10,7 @@ namespace Managers
/// 阵营管理器,负责管理游戏中的所有阵营定义及其相互关系。 /// 阵营管理器,负责管理游戏中的所有阵营定义及其相互关系。
/// 继承自 <see cref="Utils.Singleton{T}"/> ,确保全局只有一个实例。 /// 继承自 <see cref="Utils.Singleton{T}"/> ,确保全局只有一个实例。
/// </summary> /// </summary>
public class AffiliationManager:Utils.Singleton<AffiliationManager>,ILaunchManager public class AffiliationManager : Utils.Singleton<AffiliationManager>, ILaunchManager
{ {
/// <summary> /// <summary>
/// 存储所有已加载的阵营定义,键为阵营的唯一名称,值为对应的 <see cref="AffiliationDef"/> 对象。 /// 存储所有已加载的阵营定义,键为阵营的唯一名称,值为对应的 <see cref="AffiliationDef"/> 对象。
@ -28,7 +28,7 @@ namespace Managers
// 如果管理器已经初始化,则直接返回,避免重复加载。 // 如果管理器已经初始化,则直接返回,避免重复加载。
if (_affiliations.Count > 0) if (_affiliations.Count > 0)
{ {
return; return;
} }
var affiliationList = Managers.DefineManager.Instance.QueryDefinesByType<AffiliationDef>(); var affiliationList = Managers.DefineManager.Instance.QueryDefinesByType<AffiliationDef>();
@ -80,7 +80,7 @@ namespace Managers
// 如果任一阵营定义为空,则返回中立关系。 // 如果任一阵营定义为空,则返回中立关系。
if (affiliation1 == null || affiliation2 == null) if (affiliation1 == null || affiliation2 == null)
{ {
return Relation.Neutral; return Relation.Neutral;
} }
return GetRelation(affiliation1.defName, affiliation2.defName); return GetRelation(affiliation1.defName, affiliation2.defName);
} }
@ -136,7 +136,7 @@ namespace Managers
// 如果 faction1 没有明确设置与 faction2 的关系,则使用 faction1 的默认关系。 // 如果 faction1 没有明确设置与 faction2 的关系,则使用 faction1 的默认关系。
return faction1.defaultRelation; return faction1.defaultRelation;
} }
/// <summary> /// <summary>
/// 设置两个阵营之间的关系。 /// 设置两个阵营之间的关系。
/// </summary> /// </summary>
@ -187,7 +187,7 @@ namespace Managers
throw new ArgumentOutOfRangeException(nameof(relation), relation, null); throw new ArgumentOutOfRangeException(nameof(relation), relation, null);
} }
} }
/// <summary> /// <summary>
/// 检查并修复所有阵营之间的关系,以确保没有冲突。 /// 检查并修复所有阵营之间的关系,以确保没有冲突。
/// 修复遵循优先级规则:友好关系优先于敌对关系,敌对关系优先于中立关系。 /// 修复遵循优先级规则:友好关系优先于敌对关系,敌对关系优先于中立关系。

View File

@ -1,9 +1,9 @@
using Data;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Data;
using UnityEngine; using UnityEngine;
using Utils; using Utils;
@ -16,7 +16,7 @@ namespace Managers
/// 该管理器是一个单例,用于在应用程序中集中管理各种游戏或系统定义, /// 该管理器是一个单例,用于在应用程序中集中管理各种游戏或系统定义,
/// 包括从不同数据包Mods加载定义处理定义之间的引用以及提供多种查询方法。 /// 包括从不同数据包Mods加载定义处理定义之间的引用以及提供多种查询方法。
/// </remarks> /// </remarks>
public class DefineManager : Singleton<DefineManager>,ILaunchManager public class DefineManager : Singleton<DefineManager>, ILaunchManager
{ {
/// <summary> /// <summary>
/// 数据集文件路径数组,用于指定定义包的根目录。 /// 数据集文件路径数组,用于指定定义包的根目录。
@ -84,7 +84,7 @@ namespace Managers
// 存储需要进行链接的定义引用信息。 // 存储需要进行链接的定义引用信息。
// Tuple的元素依次代表被引用的定义Define引用该定义的字段FieldInfo以及引用占位符Define // Tuple的元素依次代表被引用的定义Define引用该定义的字段FieldInfo以及引用占位符Define
List<Tuple<Define, FieldInfo, Define>> defineCache = new(); List<Tuple<Define, FieldInfo, Define>> defineCache = new();
string currentPackID; string currentPackID;
// 递归处理定义对象及其内部的嵌套定义和引用。 // 递归处理定义对象及其内部的嵌套定义和引用。
@ -100,7 +100,7 @@ namespace Managers
{ {
// 获取所有公共实例字段。 // 获取所有公共实例字段。
defineFields = def.GetType() defineFields = def.GetType()
.GetFields(BindingFlags.Public | BindingFlags.Instance); .GetFields(BindingFlags.Public | BindingFlags.Instance);
// 缓存当前类型的字段信息。 // 缓存当前类型的字段信息。
fieldCache[def.GetType()] = defineFields; fieldCache[def.GetType()] = defineFields;
@ -181,7 +181,7 @@ namespace Managers
{ {
if (!defines.ContainsKey(typeName)) if (!defines.ContainsKey(typeName))
defines[typeName] = new Dictionary<string, Define>(); defines[typeName] = new Dictionary<string, Define>();
foreach (var def in defList) foreach (var def in defList)
{ {
defines[typeName][def.defName] = def; defines[typeName][def.defName] = def;
@ -321,7 +321,7 @@ namespace Managers
} }
return defineList.ToArray(); return defineList.ToArray();
} }
/// <summary> /// <summary>
/// 查询指定类型下的所有 <see cref="Define"/> 对象(包括命名定义和匿名定义)。 /// 查询指定类型下的所有 <see cref="Define"/> 对象(包括命名定义和匿名定义)。
/// </summary> /// </summary>
@ -399,7 +399,7 @@ namespace Managers
return null; return null;
} }
} }
/// <summary> /// <summary>
/// 查询指定类型下的所有命名 <see cref="Define"/> 对象(不包括匿名定义)。 /// 查询指定类型下的所有命名 <see cref="Define"/> 对象(不包括匿名定义)。
/// </summary> /// </summary>
@ -481,9 +481,9 @@ namespace Managers
if (packs == null || packs.Count == 0) if (packs == null || packs.Count == 0)
{ {
// 如果集合为空或为 null返回默认信息。 // 如果集合为空或为 null返回默认信息。
return "No packs available"; return "No packs available";
} }
var result = new System.Text.StringBuilder(); var result = new System.Text.StringBuilder();
foreach (var definePack in packs) foreach (var definePack in packs)
@ -492,7 +492,7 @@ namespace Managers
result.AppendLine(definePack.ToString()); result.AppendLine(definePack.ToString());
} }
return result.ToString(); return result.ToString();
} }
} }
} }

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Base; using Base;
using Data; using Data;
using Entity; using Entity;
using Prefab; using Prefab;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -45,7 +45,7 @@ namespace Managers
/// <summary> 子弹实体的预制体。 </summary> /// <summary> 子弹实体的预制体。 </summary>
public EntityPrefab bulletPrefab; public EntityPrefab bulletPrefab;
public EntityPrefab pickupPrefab; public EntityPrefab pickupPrefab;
/// <summary> 默认实体的预制体,用于生成失败时的回退。 </summary> /// <summary> 默认实体的预制体,用于生成失败时的回退。 </summary>
@ -269,7 +269,7 @@ namespace Managers
throw new InvalidOperationException( throw new InvalidOperationException(
$"在 '{instantiatedEntity.name}' 上缺少 EntityPrefab 组件,无法完成实体初始化。"); $"在 '{instantiatedEntity.name}' 上缺少 EntityPrefab 组件,无法完成实体初始化。");
} }
entityComponent.entity.currentDimensionId=dimensionId; entityComponent.entity.currentDimensionId = dimensionId;
entityComponent.Init(def); entityComponent.Init(def);
extraInit?.Invoke(entityComponent); extraInit?.Invoke(entityComponent);
@ -504,14 +504,14 @@ namespace Managers
Debug.LogError($"实体管理器:无法在维度 '{dimensionId}' 中获取或创建实体的父层。"); Debug.LogError($"实体管理器:无法在维度 '{dimensionId}' 中获取或创建实体的父层。");
return; return;
} }
var result=Instantiate(pickupPrefab, pos, Quaternion.identity); var result = Instantiate(pickupPrefab, pos, Quaternion.identity);
var pickup = result.GetComponent<Pickup>(); var pickup = result.GetComponent<Pickup>();
result.transform.SetParent(parentLayer); result.transform.SetParent(parentLayer);
pickup.Init(itemDef); pickup.Init(itemDef);
if (result == null) GenerateDefaultEntity(dimensionId, pos); if (result == null) GenerateDefaultEntity(dimensionId, pos);
_pendingAdditions.Add(Tuple.Create(dimensionId, "default", result)); _pendingAdditions.Add(Tuple.Create(dimensionId, "default", result));
} }
/// <summary> /// <summary>
/// 在指定维度和位置生成一个默认实体(通常作为回退选项)。 /// 在指定维度和位置生成一个默认实体(通常作为回退选项)。

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Data; using Data;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using EventType = Data.EventType; using EventType = Data.EventType;

View File

@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Data; using Data;
using Item; using Item;
using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
namespace Managers namespace Managers
{ {
public class ItemResourceManager : Utils.Singleton<ItemResourceManager>,ILaunchManager public class ItemResourceManager : Utils.Singleton<ItemResourceManager>, ILaunchManager
{ {
private ItemResource defaultItem; private ItemResource defaultItem;
private readonly Dictionary<string, Item.ItemResource> _items = new(); private readonly Dictionary<string, Item.ItemResource> _items = new();
@ -16,7 +16,7 @@ namespace Managers
public void Init() public void Init()
{ {
defaultItem=ItemResource.GetDefault(); defaultItem = ItemResource.GetDefault();
var baseItemDefs = Managers.DefineManager.Instance.QueryDefinesByType<ItemDef>(); var baseItemDefs = Managers.DefineManager.Instance.QueryDefinesByType<ItemDef>();
var weaponDefs = Managers.DefineManager.Instance.QueryDefinesByType<WeaponDef>(); var weaponDefs = Managers.DefineManager.Instance.QueryDefinesByType<WeaponDef>();
@ -38,7 +38,7 @@ namespace Managers
$"ItemResourceManager: Duplicate itemDef.defName found: {def.defName}. Skipping this item."); $"ItemResourceManager: Duplicate itemDef.defName found: {def.defName}. Skipping this item.");
continue; continue;
} }
Item.ItemResource itemResource; Item.ItemResource itemResource;
if (def is WeaponDef currentWeaponDef) if (def is WeaponDef currentWeaponDef)

View File

@ -1,8 +1,8 @@
using Data;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Data;
using UnityEngine; using UnityEngine;
namespace Managers namespace Managers
@ -51,7 +51,7 @@ namespace Managers
{ {
// 如果已经加载过,直接返回。 // 如果已经加载过,直接返回。
StepDescription = "包图像管理器已初始化。"; StepDescription = "包图像管理器已初始化。";
return; return;
} }
StepDescription = "正在加载默认精灵..."; // 更新加载步骤描述 StepDescription = "正在加载默认精灵..."; // 更新加载步骤描述
@ -73,7 +73,7 @@ namespace Managers
{ {
var textureCache = new Dictionary<string, Texture2D>(); var textureCache = new Dictionary<string, Texture2D>();
var imageDef = Managers.DefineManager.Instance.QueryDefinesByType<ImageDef>(); var imageDef = Managers.DefineManager.Instance.QueryDefinesByType<ImageDef>();
if (imageDef == null || !imageDef.Any()) if (imageDef == null || !imageDef.Any())
{ {
Debug.Log($"在 DefineManager 中未找到任何 ImageDef 定义。({typeof(ImageDef).Name})"); Debug.Log($"在 DefineManager 中未找到任何 ImageDef 定义。({typeof(ImageDef).Name})");
@ -91,9 +91,9 @@ namespace Managers
try try
{ {
string cacheKey; string cacheKey;
Texture2D texture = null; Texture2D texture = null;
if (ima.path.StartsWith("res:")) if (ima.path.StartsWith("res:"))
{ {
// 处理 Resources 路径 // 处理 Resources 路径
var resPath = ima.path.Substring(4).Replace('\\', '/').TrimStart('/'); var resPath = ima.path.Substring(4).Replace('\\', '/').TrimStart('/');
@ -243,7 +243,7 @@ namespace Managers
Debug.LogError($"包 '{packId}' 中 '{baseName}' 的纹理尺寸 ({textureWidth}x{textureHeight}) 不能被指定的行数 ({rows}) 和列数 ({cols}) 完美整除。子精灵将不会生成或可能不正确。仅显示完整精灵。"); Debug.LogError($"包 '{packId}' 中 '{baseName}' 的纹理尺寸 ({textureWidth}x{textureHeight}) 不能被指定的行数 ({rows}) 和列数 ({cols}) 完美整除。子精灵将不会生成或可能不正确。仅显示完整精灵。");
return; // 终止子精灵分割,只保留完整的精灵 return; // 终止子精灵分割,只保留完整的精灵
} }
var tileWidth = textureWidth / cols; var tileWidth = textureWidth / cols;
var tileHeight = textureHeight / rows; var tileHeight = textureHeight / rows;
@ -251,11 +251,11 @@ namespace Managers
{ {
for (var col = 0; col < cols; col++) for (var col = 0; col < cols; col++)
{ {
Rect spriteRect = new(col * tileWidth, row * tileHeight, tileWidth, tileHeight); Rect spriteRect = new(col * tileWidth, row * tileHeight, tileWidth, tileHeight);
var sprite = Sprite.Create(texture, spriteRect, new Vector2(0.5f, 0.5f), pixelsPerUnit); var sprite = Sprite.Create(texture, spriteRect, new Vector2(0.5f, 0.5f), pixelsPerUnit);
// 精灵索引计算方式 // 精灵索引计算方式
var index = (rows - row - 1) * cols + col; var index = (rows - row - 1) * cols + col;
var spriteName = $"{baseName}_{index}"; var spriteName = $"{baseName}_{index}";
sprite.name = spriteName; sprite.name = spriteName;
@ -268,7 +268,7 @@ namespace Managers
} }
} }
} }
/// <summary> /// <summary>
/// 清理所有已加载的纹理和精灵数据。 /// 清理所有已加载的纹理和精灵数据。
/// </summary> /// </summary>
@ -291,8 +291,8 @@ namespace Managers
/// </remarks> /// </remarks>
public void Reload() public void Reload()
{ {
Clear(); Clear();
Init(); Init();
} }
@ -303,7 +303,7 @@ namespace Managers
/// <returns>如果找到对应的精灵,则返回该精灵;否则返回 <see cref="defaultSprite"/>。</returns> /// <returns>如果找到对应的精灵,则返回该精灵;否则返回 <see cref="defaultSprite"/>。</returns>
public Sprite GetSprite(ImageDef ima) public Sprite GetSprite(ImageDef ima)
{ {
if (ima == null) return defaultSprite; if (ima == null) return defaultSprite;
return GetSprite(ima.packID, ima.name); return GetSprite(ima.packID, ima.name);
} }

View File

@ -1,16 +1,16 @@
using System.Collections.Generic;
using Prefab; using Prefab;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
namespace Managers namespace Managers
{ {
public class RightMenuManager:Utils.MonoSingleton<RightMenuManager> public class RightMenuManager : Utils.MonoSingleton<RightMenuManager>
{ {
[SerializeField] [SerializeField]
private GameObject _canvas; private GameObject _canvas;
[SerializeField] [SerializeField]
private RightMenuPrefab _rightMenuPrefab; private RightMenuPrefab _rightMenuPrefab;
public GameObject Canvas public GameObject Canvas
@ -35,7 +35,7 @@ namespace Managers
{ {
if (_rightMenuPrefab == null) if (_rightMenuPrefab == null)
{ {
_rightMenuPrefab = Resources.Load<RightMenuPrefab>("Prefab/RightMenu"); _rightMenuPrefab = Resources.Load<RightMenuPrefab>("Prefab/RightMenu");
if (_rightMenuPrefab == null) if (_rightMenuPrefab == null)
{ {
Debug.LogError("RightMenuPrefab not found in Resources!"); Debug.LogError("RightMenuPrefab not found in Resources!");
@ -45,11 +45,11 @@ namespace Managers
} }
} }
public static void GenerateRightMenu(List<(string name, UnityAction callback)> buttons,Vector3 position) public static void GenerateRightMenu(List<(string name, UnityAction callback)> buttons, Vector3 position)
{ {
var rightMenuObj = Instantiate(RightMenuManager.Instance.RightMenuPrefab.gameObject, var rightMenuObj = Instantiate(RightMenuManager.Instance.RightMenuPrefab.gameObject,
RightMenuManager.Instance.Canvas.transform); RightMenuManager.Instance.Canvas.transform);
var rightMenu=rightMenuObj.GetComponent<RightMenuPrefab>(); var rightMenu = rightMenuObj.GetComponent<RightMenuPrefab>();
rightMenu.Init(buttons); rightMenu.Init(buttons);
rightMenu.transform.position = position; rightMenu.transform.position = position;
rightMenu.Show(); rightMenu.Show();
@ -57,7 +57,7 @@ namespace Managers
protected override void OnStart() protected override void OnStart()
{ {
} }
} }
} }

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Data; using Data;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps; using UnityEngine.Tilemaps;
using Utils; using Utils;
@ -35,15 +35,15 @@ namespace Managers
{ {
return; return;
} }
// 确保依赖的 PackagesImageManager 已初始化。 // 确保依赖的 PackagesImageManager 已初始化。
// 虽然 Launcher 会按顺序初始化,但这里做一次检查和调用, // 虽然 Launcher 会按顺序初始化,但这里做一次检查和调用,
// 可以防止其他地方直接调用 TileManager.Instance.Init() 时, // 可以防止其他地方直接调用 TileManager.Instance.Init() 时,
// 其依赖未准备好的情况。PackagesImageManager 也应该是幂等的。 // 其依赖未准备好的情况。PackagesImageManager 也应该是幂等的。
PackagesImageManager.Instance.Init(); PackagesImageManager.Instance.Init();
var imagePack = Managers.PackagesImageManager.Instance; var imagePack = Managers.PackagesImageManager.Instance;
// 获取所有瓦片定义 // 获取所有瓦片定义
var tileDefs = DefineManager.Instance.QueryDefinesByType<TileDef>(); var tileDefs = DefineManager.Instance.QueryDefinesByType<TileDef>();
for (var i = 0; i < tileDefs.Length; i++) for (var i = 0; i < tileDefs.Length; i++)
@ -54,7 +54,7 @@ namespace Managers
Debug.LogWarning($"<color=orange>瓦片定义 '{tileDefs[i].name}' 的名称重复。</color> 将忽略后续定义。"); Debug.LogWarning($"<color=orange>瓦片定义 '{tileDefs[i].name}' 的名称重复。</color> 将忽略后续定义。");
} }
} }
// 处理瓦片纹理映射表定义 // 处理瓦片纹理映射表定义
var tileTextureMappingDefs = DefineManager.Instance.QueryDefinesByType<TileMappingTableDef>(); var tileTextureMappingDefs = DefineManager.Instance.QueryDefinesByType<TileMappingTableDef>();
foreach (var mappingTableDef in tileTextureMappingDefs) foreach (var mappingTableDef in tileTextureMappingDefs)
@ -94,9 +94,9 @@ namespace Managers
continue; continue;
} }
// 创建瓦片实例并存储到映射表中 // 创建瓦片实例并存储到映射表中
var newTile = CreateTileInstance(sprite); var newTile = CreateTileInstance(sprite);
tileToTileBaseMapping[tileKey] = newTile; tileToTileBaseMapping[tileKey] = newTile;
// 同样检查 tileBaseMapping 的重复性 // 同样检查 tileBaseMapping 的重复性
if (tileBaseMapping.ContainsKey(spriteName)) if (tileBaseMapping.ContainsKey(spriteName))
{ {
@ -139,29 +139,29 @@ namespace Managers
Object.Destroy(tile); Object.Destroy(tile);
} }
} }
tileBaseMapping.Clear(); tileBaseMapping.Clear();
tileToTileBaseMapping.Clear(); tileToTileBaseMapping.Clear();
tileID.Clear(); tileID.Clear();
} }
// ------------- ILaunchManager 接口实现结束 ------------- // ------------- ILaunchManager 接口实现结束 -------------
/// <summary> /// <summary>
/// 存储瓦片名称与 <see cref="TileBase"/> 对象的映射关系。 /// 存储瓦片名称与 <see cref="TileBase"/> 对象的映射关系。
/// </summary> /// </summary>
public Dictionary<string, TileBase> tileBaseMapping = new(); public Dictionary<string, TileBase> tileBaseMapping = new();
/// <summary> /// <summary>
/// 存储瓦片组合索引与 <see cref="TileBase"/> 对象的映射关系。 /// 存储瓦片组合索引与 <see cref="TileBase"/> 对象的映射关系。
/// 索引由四个整数组成,表示瓦片的组合方式。 /// 索引由四个整数组成,表示瓦片的组合方式。
/// </summary> /// </summary>
public Dictionary<(int, int, int, int), TileBase> tileToTileBaseMapping = new(); public Dictionary<(int, int, int, int), TileBase> tileToTileBaseMapping = new();
/// <summary> /// <summary>
/// 存储瓦片名称与唯一 ID 的映射关系。 /// 存储瓦片名称与唯一 ID 的映射关系。
/// </summary> /// </summary>
public Dictionary<string, int> tileID = new(); public Dictionary<string, int> tileID = new();
// 移除了 TileManager 内部的 Reload() 方法,因为它将被 Launcher 的 Clear() + Init() 流程取代。 // 移除了 TileManager 内部的 Reload() 方法,因为它将被 Launcher 的 Clear() + Init() 流程取代。
/// <summary> /// <summary>

View File

@ -1,5 +1,3 @@
using System;
using Managers;
using UnityEngine; using UnityEngine;
namespace Map namespace Map
@ -12,11 +10,12 @@ namespace Map
{ {
[SerializeField] private bool defaultOpen = false; [SerializeField] private bool defaultOpen = false;
[SerializeField] [Tooltip("此维度的唯一标识符。如果为空将使用GameObject的名称。")] [SerializeField]
[Tooltip("此维度的唯一标识符。如果为空将使用GameObject的名称。")]
private string _dimensionId; private string _dimensionId;
[SerializeField] public MapGenerator mapGenerator; [SerializeField] public MapGenerator mapGenerator;
public Vector3 cameraPosition; public Vector3 cameraPosition;
/// <summary> /// <summary>
/// 获取此维度的唯一标识符。 /// 获取此维度的唯一标识符。
@ -43,7 +42,7 @@ namespace Map
private void Awake() private void Awake()
{ {
// 1. 确保 DimensionId 已初始化,这会触发 DimensionId 属性的 getter 逻辑 // 1. 确保 DimensionId 已初始化,这会触发 DimensionId 属性的 getter 逻辑
var id = DimensionId; var id = DimensionId;
// 2. 创建一个用于存放此维度下所有实体的根GameObject方便管理 // 2. 创建一个用于存放此维度下所有实体的根GameObject方便管理
@ -60,7 +59,7 @@ namespace Map
Debug.LogError( Debug.LogError(
"[Dimension] Program.Instance is null during Dimension Awake. Cannot register dimension.", this); "[Dimension] Program.Instance is null during Dimension Awake. Cannot register dimension.", this);
} }
// 5. 处理 defaultOpen 逻辑设置Program的焦点维度 // 5. 处理 defaultOpen 逻辑设置Program的焦点维度
// 确保在自身注册到 Program 之后再设置焦点,这样 Program 内部才能找到它 // 确保在自身注册到 Program 之后再设置焦点,这样 Program 内部才能找到它
@ -74,7 +73,7 @@ namespace Map
private void Start() private void Start()
{ {
var size = mapGenerator.baseMap.GetSize(); var size = mapGenerator.baseMap.GetSize();
cameraPosition = new Vector3(size.x / 2f, size.y / 2f, -10)+transform.position; cameraPosition = new Vector3(size.x / 2f, size.y / 2f, -10) + transform.position;
} }
private void OnDestroy() private void OnDestroy()

View File

@ -1,8 +1,6 @@
using System; using Managers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Data;
using Managers;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps; using UnityEngine.Tilemaps;
@ -13,7 +11,7 @@ namespace Map
public List<List<int>> mapData = new(); public List<List<int>> mapData = new();
public Tilemap textureLevel; public Tilemap textureLevel;
// public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量 - 已删除 // public Vector2Int dataOffset = Vector2Int.zero; // 数据起始点偏移变量 - 已删除
// 初始化地图数据大小 // 初始化地图数据大小
public void InitializeData(int width, int height, int defaultValue = 0) public void InitializeData(int width, int height, int defaultValue = 0)

View File

@ -1,10 +1,9 @@
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Tilemaps;
namespace Map namespace Map
{ {
public class MapGenerator:MonoBehaviour public class MapGenerator : MonoBehaviour
{ {
public DoubleMap baseMap; public DoubleMap baseMap;
@ -29,6 +28,6 @@ namespace Map
baseMap.RefreshAllTiles(); baseMap.RefreshAllTiles();
CameraControl.CameraControl.Instance.SetPosition(new Vector3(size * 0.5f, size * 0.5f, -10)); CameraControl.CameraControl.Instance.SetPosition(new Vector3(size * 0.5f, size * 0.5f, -10));
} }
} }
} }

View File

@ -4,7 +4,7 @@ using UnityEngine.UI;
namespace Map namespace Map
{ {
public class MiniMap : MonoBehaviour,ITickUI public class MiniMap : MonoBehaviour, ITickUI
{ {
public Image background; public Image background;
public RawImage texture; public RawImage texture;

View File

@ -1,8 +1,9 @@
using System.Net.Http;
using System.Threading.Tasks;
using Grpc.Net.Client; using Grpc.Net.Client;
using Grpc.Net.Client.Web; using Grpc.Net.Client.Web;
using Protocol; using Protocol;
using System.Net.Http;
using System.Threading.Tasks;
using UnityEngine;
using Utils; using Utils;
namespace Network namespace Network
@ -18,21 +19,17 @@ namespace Network
public GrpcClient() public GrpcClient()
{ {
var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler());
var channelOptions = new GrpcChannelOptions var channelOptions = new GrpcChannelOptions
{ {
HttpHandler = httpHandler HttpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler())
}; };
_channel = GrpcChannel.ForAddress(ServerAddress, channelOptions); _channel = GrpcChannel.ForAddress(ServerAddress, channelOptions);
_general = new GeneralService.GeneralServiceClient(_channel); _general = new GeneralService.GeneralServiceClient(_channel);
_game = new GameService.GameServiceClient(_channel); _game = new GameService.GameServiceClient(_channel);
}
~GrpcClient() Application.quitting += () => _channel.ShutdownAsync().Wait();
{
_channel.ShutdownAsync().Wait();
} }
public async Task<ServerInfo> GetServerInfo() public async Task<ServerInfo> GetServerInfo()

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ef7f384f3b5dc0049ba97561d579cd03
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,7 +5,7 @@ using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace AI namespace Parsing
{ {
public static class ConditionDelegateFactory public static class ConditionDelegateFactory
{ {

View File

@ -1,9 +1,4 @@
using System; namespace Parsing
using Data;
using Managers;
using UnityEngine;
namespace AI
{ {
public static class ConditionFunctions public static class ConditionFunctions
{ {
@ -11,11 +6,10 @@ namespace AI
{ {
return entity.attributes.health >= minHealth; return entity.attributes.health >= minHealth;
} }
public static bool HasEnemyInSight(Entity.Entity entity) public static bool HasEnemyInSight(Entity.Entity entity)
{ {
return Managers.EntityManage.Instance.ExistsHostile(entity.currentDimensionId,entity.entityPrefab); return Managers.EntityManage.Instance.ExistsHostile(entity.currentDimensionId, entity.entityPrefab);
} }
} }
} }

View File

@ -2,7 +2,7 @@ using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace Utils namespace Parsing
{ {
public static class Resolver public static class Resolver
{ {

View File

@ -5,15 +5,15 @@ using UnityEngine.UI;
namespace Prefab namespace Prefab
{ {
public class ButtonPrefab:MonoBehaviour public class ButtonPrefab : MonoBehaviour
{ {
public Button button; public Button button;
public TMP_Text text; public TMP_Text text;
public string Label public string Label
{ {
get{return text.text;} get { return text.text; }
set{text.text = value;} set { text.text = value; }
} }
public void AddListener(UnityAction callback) public void AddListener(UnityAction callback)

View File

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AI;
using Base; using Base;
using Data; using Data;
using Entity; using Entity;
using Unity.VisualScripting; using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
namespace Prefab namespace Prefab

View File

@ -1,4 +1,3 @@
using System;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -6,7 +5,7 @@ using UnityEngine.UI;
namespace Prefab namespace Prefab
{ {
// [RequireComponent(typeof(CircleCollider2D))] // [RequireComponent(typeof(CircleCollider2D))]
public class HoverButtonPrefab:MonoBehaviour public class HoverButtonPrefab : MonoBehaviour
{ {
public TMP_Text text; public TMP_Text text;
public Button button; public Button button;
@ -23,8 +22,8 @@ namespace Prefab
public void OnMouseOver() public void OnMouseOver()
{ {
var dir= (Input.mousePosition - transform.position).magnitude; var dir = (Input.mousePosition - transform.position).magnitude;
var color = button.image.color; var color = button.image.color;
color.a = Mathf.Min((startRadius - dir) / (startRadius - endRadius), 1); color.a = Mathf.Min((startRadius - dir) / (startRadius - endRadius), 1);
button.image.color = color; button.image.color = color;

View File

@ -1,10 +1,9 @@
using Base;
using UnityEngine; using UnityEngine;
namespace Prefab namespace Prefab
{ {
[RequireComponent(typeof(SpriteRenderer))] [RequireComponent(typeof(SpriteRenderer))]
public class ImagePrefab : MonoBehaviour public class ImagePrefab : MonoBehaviour
{ {
public Sprite defaultSprite; public Sprite defaultSprite;

View File

@ -2,7 +2,7 @@ using UnityEngine;
namespace Prefab namespace Prefab
{ {
public class ProgressBarPrefab:MonoBehaviour public class ProgressBarPrefab : MonoBehaviour
{ {
public GameObject _progress; public GameObject _progress;
public float Progress public float Progress
@ -10,7 +10,7 @@ namespace Prefab
get => _progress.transform.localScale.x; get => _progress.transform.localScale.x;
set set
{ {
var x=Mathf.Clamp01(value); var x = Mathf.Clamp01(value);
_progress.transform.localScale = new Vector3(x, _progress.transform.localScale.y, _progress.transform.localScale.z); _progress.transform.localScale = new Vector3(x, _progress.transform.localScale.y, _progress.transform.localScale.z);
} }
} }

View File

@ -5,7 +5,7 @@ using UnityEngine.EventSystems;
namespace Prefab namespace Prefab
{ {
public class RightMenuPrefab: MonoBehaviour,IPointerExitHandler public class RightMenuPrefab : MonoBehaviour, IPointerExitHandler
{ {
public GameObject menu; public GameObject menu;
public ButtonPrefab buttonPrefab; public ButtonPrefab buttonPrefab;

View File

@ -1,4 +1,3 @@
using System;
using Base; using Base;
using UnityEngine; using UnityEngine;
@ -26,7 +25,7 @@ namespace Prefab
// ITick接口实现 // ITick接口实现
public void Tick() public void Tick()
{ {
var deltaTime=Time.deltaTime; var deltaTime = Time.deltaTime;
if (_isPaused) if (_isPaused)
{ {
HandlePausedState(); HandlePausedState();

View File

@ -6,11 +6,11 @@ namespace Prefab
public class TextPrefab : MonoBehaviour public class TextPrefab : MonoBehaviour
{ {
public TMP_Text text; public TMP_Text text;
public string Label public string Label
{ {
get{return text.text;} get { return text.text; }
set{text.text = value;} set { text.text = value; }
} }
} }

View File

@ -1,7 +1,7 @@
using Map;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Map;
using UnityEngine; using UnityEngine;
using Utils; using Utils;
@ -33,12 +33,12 @@ public class Program : Singleton<Program>
/// 变更为属性并私有化setter确保通过 SetFocusedDimension 方法集中管理其更新。 /// 变更为属性并私有化setter确保通过 SetFocusedDimension 方法集中管理其更新。
/// </summary> /// </summary>
// 逻辑修改1修正属性名 'focuseDimensionId' 为 'focusedDimensionId' // 逻辑修改1修正属性名 'focuseDimensionId' 为 'focusedDimensionId'
public string FocusedDimensionId { get; private set; } = null; public string FocusedDimensionId { get; private set; } = null;
/// <summary> /// <summary>
/// 当前聚焦的维度对象实例。当 <see cref="FocusedDimensionId"/> 不为空时,此属性指向对应的维度实例。 /// 当前聚焦的维度对象实例。当 <see cref="FocusedDimensionId"/> 不为空时,此属性指向对应的维度实例。
/// </summary> /// </summary>
public Dimension FocusedDimension { get; private set; } public Dimension FocusedDimension { get; private set; }
/// <summary> /// <summary>
/// 维护所有已注册的维度实例的字典,键是维度的唯一标识符 (ID)。 /// 维护所有已注册的维度实例的字典,键是维度的唯一标识符 (ID)。
@ -82,7 +82,7 @@ public class Program : Singleton<Program>
return; return;
} }
_registeredDimensions.Add(id, dimension); _registeredDimensions.Add(id, dimension);
// 逻辑修改此处不需要if语句包裹_registeredDimensions.Add因为前置的ContainsKey已确保不会抛异常。 // 逻辑修改此处不需要if语句包裹_registeredDimensions.Add因为前置的ContainsKey已确保不会抛异常。
// 确保任何对焦点的潜在更新都通过 SetFocusedDimension 进行, // 确保任何对焦点的潜在更新都通过 SetFocusedDimension 进行,
// 从而集中管理焦点状态的同步和事件的触发。 // 从而集中管理焦点状态的同步和事件的触发。
@ -179,7 +179,7 @@ public class Program : Singleton<Program>
// 3. 更新内部状态 // 3. 更新内部状态
FocusedDimensionId = newFocusedDimensionId; // 逻辑修改1修正属性名 FocusedDimensionId = newFocusedDimensionId; // 逻辑修改1修正属性名
FocusedDimension = newFocusedDimension; FocusedDimension = newFocusedDimension;
// 逻辑修改2功能缺失修复 - 切换维度时,焦点实体应该置为空 // 逻辑修改2功能缺失修复 - 切换维度时,焦点实体应该置为空
// 确保功能一致性:当维度焦点改变(或被清除)时,任何实体焦点也应被清除。 // 确保功能一致性:当维度焦点改变(或被清除)时,任何实体焦点也应被清除。
SetFocusedEntity(null); SetFocusedEntity(null);
@ -187,7 +187,7 @@ public class Program : Singleton<Program>
// 4. 触发事件 // 4. 触发事件
OnFocusedDimensionChanged?.Invoke(FocusedDimension); OnFocusedDimensionChanged?.Invoke(FocusedDimension);
} }
/// <summary> /// <summary>
/// 设置当前聚焦的实体。 /// 设置当前聚焦的实体。
/// 这是更改焦点实体的唯一官方入口,并会在实体改变时触发 OnFocusedEntityChanged 事件。 /// 这是更改焦点实体的唯一官方入口,并会在实体改变时触发 OnFocusedEntityChanged 事件。

View File

@ -3,7 +3,7 @@ using UnityEngine.UI;
namespace UI namespace UI
{ {
public class BarUI:MonoBehaviour public class BarUI : MonoBehaviour
{ {
[SerializeField] private Image image; [SerializeField] private Image image;

View File

@ -64,7 +64,7 @@ namespace UI
var button = InstantiatePrefab(buttonTemplate, menuContent.transform); var button = InstantiatePrefab(buttonTemplate, menuContent.transform);
button.Label = buttonTextSelector(def); button.Label = buttonTextSelector(def);
// 确保 lambda 捕获的是循环当前迭代的 def 变量,而不是循环变量本身 // 确保 lambda 捕获的是循环当前迭代的 def 变量,而不是循环变量本身
var currentDef = def; var currentDef = def;
button.AddListener(() => buttonAction(currentDef)); button.AddListener(() => buttonAction(currentDef));
} }
} }
@ -78,8 +78,8 @@ namespace UI
"事件菜单", "事件菜单",
"未定义任何事件", "未定义任何事件",
// 假设 EventDef 也有 label 字段作为按钮文本 // 假设 EventDef 也有 label 字段作为按钮文本
def => def.label, def => def.label,
eventDef => eventDef =>
{ {
// TODO: 在这里实现事件触发逻辑 // TODO: 在这里实现事件触发逻辑
Debug.Log($"触发事件: {eventDef.label}"); Debug.Log($"触发事件: {eventDef.label}");
@ -165,7 +165,7 @@ namespace UI
{ {
entityPlacementUI.currentAction = () => entityPlacementUI.currentAction = () =>
{ {
Managers.EntityManage.Instance.GenerateEntity(Program.Instance.FocusedDimensionId,entityDef, Utils.MousePosition.GetWorldPosition()); Managers.EntityManage.Instance.GenerateEntity(Program.Instance.FocusedDimensionId, entityDef, Utils.MousePosition.GetWorldPosition());
}; };
entityPlacementUI.Prompt = $"当前生成器:\n名称{entityDef.label}\n描述{entityDef.description}"; entityPlacementUI.Prompt = $"当前生成器:\n名称{entityDef.label}\n描述{entityDef.description}";
entityPlacementUI.snapEnabled = false; entityPlacementUI.snapEnabled = false;
@ -175,7 +175,7 @@ namespace UI
{ {
entityPlacementUI.currentAction = () => entityPlacementUI.currentAction = () =>
{ {
Managers.EntityManage.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId,monsterDef, Utils.MousePosition.GetWorldPosition()); Managers.EntityManage.Instance.GenerateMonsterEntity(Program.Instance.FocusedDimensionId, monsterDef, Utils.MousePosition.GetWorldPosition());
}; };
entityPlacementUI.Prompt = $"当前生成器:\n名称{monsterDef.label}\n描述{monsterDef.description}"; entityPlacementUI.Prompt = $"当前生成器:\n名称{monsterDef.label}\n描述{monsterDef.description}";
entityPlacementUI.snapEnabled = false; entityPlacementUI.snapEnabled = false;
@ -185,7 +185,7 @@ namespace UI
{ {
entityPlacementUI.currentAction = () => entityPlacementUI.currentAction = () =>
{ {
Managers.EntityManage.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId,def, Utils.MousePosition.GetSnappedWorldPosition()); Managers.EntityManage.Instance.GenerateBuildingEntity(Program.Instance.FocusedDimensionId, def, Utils.MousePosition.GetSnappedWorldPosition());
}; };
entityPlacementUI.Prompt = $"当前生成器:\n名称{def.label}\n描述{def.description}"; entityPlacementUI.Prompt = $"当前生成器:\n名称{def.label}\n描述{def.description}";
entityPlacementUI.snapEnabled = true; entityPlacementUI.snapEnabled = true;
@ -195,7 +195,7 @@ namespace UI
{ {
entityPlacementUI.currentAction = () => entityPlacementUI.currentAction = () =>
{ {
Managers.EntityManage.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId,itemDef, Utils.MousePosition.GetWorldPosition()); Managers.EntityManage.Instance.GeneratePickupEntity(Program.Instance.FocusedDimensionId, itemDef, Utils.MousePosition.GetWorldPosition());
}; };
entityPlacementUI.Prompt = $"当前生成器:\n名称{itemDef.label}\n描述{itemDef.description}"; entityPlacementUI.Prompt = $"当前生成器:\n名称{itemDef.label}\n描述{itemDef.description}";
entityPlacementUI.snapEnabled = false; entityPlacementUI.snapEnabled = false;

View File

@ -1,16 +1,15 @@
using Base; using Base;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.Events;
namespace UI namespace UI
{ {
public delegate void NonReturnCallback(); public delegate void NonReturnCallback();
public class EntityPlacementUI:UIBase,ITickUI public class EntityPlacementUI : UIBase, ITickUI
{ {
public TMP_Text promptText; public TMP_Text promptText;
public NonReturnCallback currentAction; public NonReturnCallback currentAction;
public GameObject focusBox; public GameObject focusBox;
@ -29,7 +28,7 @@ namespace UI
{ {
Base.UIInputControl.Instance.Hide(this); Base.UIInputControl.Instance.Hide(this);
} }
if (currentAction!=null&&Input.GetMouseButtonDown(0)) if (currentAction != null && Input.GetMouseButtonDown(0))
{ {
currentAction(); currentAction();
} }

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Base; using Base;
using Entity; using Entity;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// 确保 Character 类在此命名空间下 // 确保 Character 类在此命名空间下
@ -103,7 +103,7 @@ namespace UI
// 立即更新UI以反映新的关注实体或没有关注实体的状态。 // 立即更新UI以反映新的关注实体或没有关注实体的状态。
UpdateUI(); UpdateUI();
// 在更新UI后确保UI的选中状态与角色当前选中字段同步 // 在更新UI后确保UI的选中状态与角色当前选中字段同步
// 只有当有焦点角色且库存不为空时才更新选中状态 // 只有当有焦点角色且库存不为空时才更新选中状态
if (focusedEntity != null && focusedEntity.Inventory != null && focusedEntity.Inventory.Capacity > 0) if (focusedEntity != null && focusedEntity.Inventory != null && focusedEntity.Inventory.Capacity > 0)
@ -187,7 +187,7 @@ namespace UI
} }
} }
uiParent.SetActive(true); uiParent.SetActive(true);
// 首次更新UI时或者当Inventory改变时需要确保 CurrentSelected 的UI状态是正确的 // 首次更新UI时或者当Inventory改变时需要确保 CurrentSelected 的UI状态是正确的
// 但如果 UpdateFocusedEntity 已经处理了,这里可以省略,或者确保只在必要时调用 // 但如果 UpdateFocusedEntity 已经处理了,这里可以省略,或者确保只在必要时调用
// 考虑到 UpdateUI 也会被 Inventory.OnInventoryChanged 调用,这里再次确保同步是合理的。 // 考虑到 UpdateUI 也会被 Inventory.OnInventoryChanged 调用,这里再次确保同步是合理的。

View File

@ -1,10 +1,9 @@
using Base; using Base;
using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace UI namespace UI
{ {
public class EscUI:UIBase public class EscUI : UIBase
{ {
public void ContinueButton() public void ContinueButton()
{ {

View File

@ -1,5 +1,5 @@
using System;
using Base; using Base;
using System;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@ -7,20 +7,20 @@ using UnityEngine.UI;
namespace UI namespace UI
{ {
public class ItemUI:MonoBehaviour,IPointerEnterHandler,IPointerExitHandler,IPointerClickHandler,ITick public class ItemUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, ITick
{ {
[SerializeField] private Image textureUI; [SerializeField] private Image textureUI;
[SerializeField] private TMP_Text countUI; [SerializeField] private TMP_Text countUI;
[SerializeField] private TMP_Text nameUI; [SerializeField] private TMP_Text nameUI;
[SerializeField] private GameObject selectedOutline; [SerializeField] private GameObject selectedOutline;
private Entity.InventorySlot _item; private Entity.InventorySlot _item;
private float timer = 0; private float timer = 0;
private float switchTime = 0; private float switchTime = 0;
private int texturePtr = 0; private int texturePtr = 0;
public event Action OnPlayerSelect; public event Action OnPlayerSelect;
public bool Select public bool Select
{ {
get => selectedOutline.activeSelf; get => selectedOutline.activeSelf;
@ -29,7 +29,7 @@ namespace UI
public int SlotIndex { get; private set; } = -1; public int SlotIndex { get; private set; } = -1;
public void Init(Entity.InventorySlot item,int index) public void Init(Entity.InventorySlot item, int index)
{ {
if (item == null) if (item == null)
{ {
@ -75,17 +75,17 @@ namespace UI
{ {
if (switchTime > 0) if (switchTime > 0)
{ {
timer+=Time.deltaTime; timer += Time.deltaTime;
if (timer >= switchTime) if (timer >= switchTime)
{ {
timer-=switchTime; timer -= switchTime;
texturePtr++; texturePtr++;
texturePtr%=_item.Item.Icon.Count; texturePtr %= _item.Item.Icon.Count;
textureUI.sprite=_item.Item.Icon[texturePtr]; textureUI.sprite = _item.Item.Icon[texturePtr];
} }
} }
} }
} }
} }

View File

@ -1,6 +1,6 @@
using Prefab;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Prefab;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;

View File

@ -1,14 +1,12 @@
using System;
using TMPro;
using UnityEngine; using UnityEngine;
namespace UI namespace UI
{ {
public class PlayerStateUI:MonoBehaviour,Base.ITick public class PlayerStateUI : MonoBehaviour, Base.ITick
{ {
[SerializeField] private BarUI focusedEntityHP; [SerializeField] private BarUI focusedEntityHP;
[SerializeField] private BarUI lastEntityHP; [SerializeField] private BarUI lastEntityHP;
public void Tick() public void Tick()
{ {
@ -19,6 +17,6 @@ namespace UI
(float)focusedEntity.attributes.health / focusedEntity.entityDef.attributes.health; (float)focusedEntity.attributes.health / focusedEntity.entityDef.attributes.health;
} }
} }
} }
} }

View File

@ -1,5 +1,5 @@
using System.Globalization;
using Base; using Base;
using System.Globalization;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;

View File

@ -2,20 +2,18 @@ using System;
namespace Utils namespace Utils
{ {
public class PerlinNoise : Utils.Singleton<PerlinNoise> public class PerlinNoise : Singleton<PerlinNoise>
{ {
private int[] _p; // 混淆表 private readonly int[] _p = new int[512]; // 混淆表
private const int DefaultSeed = 0; // 默认种子
public PerlinNoise() public PerlinNoise()
{ {
Initialize(DefaultSeed); Initialize();
} }
// 初始化混淆表 // 初始化混淆表
private void Initialize(int seed) private void Initialize(int seed = 0)
{ {
_p = new int[512]; // 混淆表加倍以方便使用
var permutation = new int[256]; var permutation = new int[256];
var random = new Random(seed); var random = new Random(seed);
@ -26,9 +24,8 @@ namespace Utils
for (var i = 0; i < 256; i++) for (var i = 0; i < 256; i++)
{ {
var swapIndex = random.Next(256); var swapIndex = random.Next(256);
var temp = permutation[i];
permutation[i] = permutation[swapIndex]; (permutation[i], permutation[swapIndex]) = (permutation[swapIndex], permutation[i]);
permutation[swapIndex] = temp;
} }
// 将打乱后的数组复制两次生成512个元素的混淆表 // 将打乱后的数组复制两次生成512个元素的混淆表
@ -86,7 +83,7 @@ namespace Utils
/// 为给定的(x, y, z)坐标生成3D Perlin噪声。 /// 为给定的(x, y, z)坐标生成3D Perlin噪声。
/// 输出值通常在-1到1之间。 /// 输出值通常在-1到1之间。
/// </summary> /// </summary>
public double Noise(double x, double y=0, double z = 0) public double Noise(double x, double y = 0, double z = 0)
{ {
var X = (int)Math.Floor(x) & 255; var X = (int)Math.Floor(x) & 255;
var Y = (int)Math.Floor(y) & 255; var Y = (int)Math.Floor(y) & 255;

File diff suppressed because one or more lines are too long