(client) chore:Clean code

This commit is contained in:
2025-08-28 16:20:24 +08:00
parent 909e995e15
commit c3bff1cf88
76 changed files with 5689 additions and 445 deletions

View File

@ -195,6 +195,8 @@ TilemapRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
@ -216,6 +218,7 @@ TilemapRenderer:
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
@ -242,37 +245,6 @@ Transform:
m_Children: []
m_Father: {fileID: 613797070}
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
GameObject:
m_ObjectHideFlags: 0
@ -290,7 +262,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &613797068
MonoBehaviour:
m_ObjectHideFlags: 0
@ -388,7 +360,6 @@ MonoBehaviour:
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
m_TaaSettings:
m_Quality: 3
m_FrameInfluence: 0.1
@ -396,6 +367,7 @@ MonoBehaviour:
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!81 &1057087088
AudioListener:
m_ObjectHideFlags: 0
@ -546,6 +518,8 @@ TilemapRenderer:
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
@ -567,6 +541,7 @@ TilemapRenderer:
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
@ -593,51 +568,6 @@ Transform:
m_Children: []
m_Father: {fileID: 613797070}
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
GameObject:
m_ObjectHideFlags: 0
@ -655,7 +585,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &2036983432
Transform:
m_ObjectHideFlags: 0
@ -684,8 +614,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
isGlobal: 1
entityLevel: {fileID: 309861628}
entityPrefab: {fileID: 3332598847335032684, guid: 6cd8b01a0f57372438dc30c864ae1530, type: 3}
characterPrefab: {fileID: 0}
monsterPrefab: {fileID: 0}
buildingPrefab: {fileID: 0}
bulletPrefab: {fileID: 0}
pickupPrefab: {fileID: 0}
defaultEntityPrefab: {fileID: 7975757421877276383, guid: 89661daa5f100c64783f0ad9cd37a7ff, type: 3}
--- !u!114 &2036983434
MonoBehaviour:
@ -716,7 +649,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!114 &2104915507
MonoBehaviour:
m_ObjectHideFlags: 0
@ -751,6 +684,4 @@ SceneRoots:
- {fileID: 1057087090}
- {fileID: 613797070}
- {fileID: 2104915508}
- {fileID: 309861630}
- {fileID: 2036983432}
- {fileID: 1371068282}

View File

@ -1,9 +1,7 @@
using Data;
using Parsing;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using Data;
using UnityEngine;
namespace AI
{

View File

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

View File

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

View File

@ -1,6 +1,6 @@
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Base

View File

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

View File

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

View File

@ -1,13 +1,10 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Networking;
using Formatting = Newtonsoft.Json.Formatting;
namespace Configs

View File

@ -7,7 +7,7 @@ namespace Data
public class BehaviorTreeDef : Define
{
public BehaviorTreeDef[] childTree;
public string className= "ThinkNode_Selector";
public string className = "ThinkNode_Selector";
public string value;

View File

@ -1,6 +1,6 @@
namespace Data
{
public class BulletDef:EntityDef
public class BulletDef : EntityDef
{
public string className;
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
{
public class CharacterDef : EntityDef

View File

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

View File

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

View File

@ -237,7 +237,7 @@ namespace Data
{
base.Init(xmlDef);
nodeName = xmlDef.Attribute("name")?.Value??"noName";
nodeName = xmlDef.Attribute("name")?.Value ?? "noName";
position = StringToVector(xmlDef.Attribute("position")?.Value ?? "(0 0)");
FPS = float.TryParse(xmlDef.Attribute("FPS")?.Value, out var result) ? result : 1.0f;
return false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
using System;
using Base;
using Data;
using Prefab;
using UnityEngine;
namespace Entity
@ -20,7 +18,7 @@ namespace Entity
protected override void AutoBehave()
{
TryMove();
lifeTime-=Time.deltaTime;
lifeTime -= Time.deltaTime;
if (lifeTime <= 0)
{
Kill();

View File

@ -1,10 +1,6 @@
using System;
using System.Linq;
using Data;
using Item;
using Managers;
using UnityEngine;
using Utils;
// 添加 System 命名空间以使用 Action
namespace Entity

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Managers;
using Prefab;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
@ -17,7 +17,7 @@ namespace 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()
{
@ -116,7 +116,7 @@ namespace Entity
private void BecomeDefault()
{
entity.Kill();
EntityManage.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId,entity.Position);
EntityManage.Instance.GenerateDefaultEntity(Program.Instance.FocusedDimensionId, entity.Position);
}
private void StartControl()

View File

@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Base;
using Data;
using Item;
using Prefab;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Entity
{
public class Pickup:Entity
public class Pickup : Entity
{
public ItemResource itemResource;
protected override void AutoBehave()

View File

@ -1,12 +1,10 @@
using UnityEngine;
namespace Item
{
public class ItemBase
{
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 Managers;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Item

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq; // Added for LINQ
using Base;
using Data;
using Entity;
using Prefab;
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
@ -17,9 +16,9 @@ namespace Item
public WeaponType Type { 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>
/// 构造函数:通过 WeaponDef 对象初始化 WeaponResource。
@ -112,7 +111,7 @@ namespace Item
if (parent == null)
{
// 逻辑修改说明:这里直接返回 null 更合适,因为没有父节点无法创建实例。
// 逻辑修改说明:这里直接返回 null 更合适,因为没有父节点无法创建实例。
Debug.LogWarning($"CreateBodyPartGameObject: 父节点为null (节点名: {drawNode.nodeName ?? "Unnamed DrawNode"})");
return null;
}

View File

@ -27,8 +27,10 @@ namespace Logging
public static int MaxLogs
{
get => _maxLogs;
set {
lock (_lock) {
set
{
lock (_lock)
{
_maxLogs = Mathf.Max(value, 1); // 最小值为1
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 UnityEngine;
using Utils;
using SerilogLogger = Serilog.Core.Logger;
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")
.CreateLogger();
private static bool _initialized = false;
public static void Init()
public void Init()
{
if(_initialized)
return;
Application.logMessageReceived += OnLogMessageReceived;
if (_initialized) return;
Application.logMessageReceivedThreaded += OnLogMessageReceived;
_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)
{
case LogType.Assert:
{
Logger.Warning("\nContent: {0}", logString);
break;
}
{
_logger.Warning("\nContent: {0}", logString);
break;
}
case LogType.Log:
{
Logger.Information("\nContent: {0}", logString);
break;
}
{
_logger.Information("\nContent: {0}", logString);
break;
}
case LogType.Warning:
{
Logger.Warning("\nContent: {0}", logString);
break;
}
{
_logger.Warning("\nContent: {0}", logString);
break;
}
case LogType.Error:
{
Logger.Error("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break;
}
{
_logger.Error("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break;
}
case LogType.Exception:
{
Logger.Fatal("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break;
}
{
_logger.Fatal("\nContent: {0}\nStackTrace:\n{1}", logString, stackTrace[..^1]);
break;
}
default:
{
Logger.Information("\nContent: {0}", logString);
break;
}
{
_logger.Information("\nContent: {0}", logString);
break;
}
}
}
}

View File

@ -1,7 +1,7 @@
using Data;
using System;
using System.Collections.Generic;
using System.Linq;
using Data;
using UnityEngine;
namespace Managers
@ -10,7 +10,7 @@ namespace Managers
/// 阵营管理器,负责管理游戏中的所有阵营定义及其相互关系。
/// 继承自 <see cref="Utils.Singleton{T}"/> ,确保全局只有一个实例。
/// </summary>
public class AffiliationManager:Utils.Singleton<AffiliationManager>,ILaunchManager
public class AffiliationManager : Utils.Singleton<AffiliationManager>, ILaunchManager
{
/// <summary>
/// 存储所有已加载的阵营定义,键为阵营的唯一名称,值为对应的 <see cref="AffiliationDef"/> 对象。

View File

@ -1,9 +1,9 @@
using Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Data;
using UnityEngine;
using Utils;
@ -16,7 +16,7 @@ namespace Managers
/// 该管理器是一个单例,用于在应用程序中集中管理各种游戏或系统定义,
/// 包括从不同数据包Mods加载定义处理定义之间的引用以及提供多种查询方法。
/// </remarks>
public class DefineManager : Singleton<DefineManager>,ILaunchManager
public class DefineManager : Singleton<DefineManager>, ILaunchManager
{
/// <summary>
/// 数据集文件路径数组,用于指定定义包的根目录。

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Base;
using Data;
using Entity;
using Prefab;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -269,7 +269,7 @@ namespace Managers
throw new InvalidOperationException(
$"在 '{instantiatedEntity.name}' 上缺少 EntityPrefab 组件,无法完成实体初始化。");
}
entityComponent.entity.currentDimensionId=dimensionId;
entityComponent.entity.currentDimensionId = dimensionId;
entityComponent.Init(def);
extraInit?.Invoke(entityComponent);
@ -505,7 +505,7 @@ namespace Managers
return;
}
var result=Instantiate(pickupPrefab, pos, Quaternion.identity);
var result = Instantiate(pickupPrefab, pos, Quaternion.identity);
var pickup = result.GetComponent<Pickup>();
result.transform.SetParent(parentLayer);
pickup.Init(itemDef);

View File

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

View File

@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Data;
using Item;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Managers
{
public class ItemResourceManager : Utils.Singleton<ItemResourceManager>,ILaunchManager
public class ItemResourceManager : Utils.Singleton<ItemResourceManager>, ILaunchManager
{
private ItemResource defaultItem;
private readonly Dictionary<string, Item.ItemResource> _items = new();
@ -16,7 +16,7 @@ namespace Managers
public void Init()
{
defaultItem=ItemResource.GetDefault();
defaultItem = ItemResource.GetDefault();
var baseItemDefs = Managers.DefineManager.Instance.QueryDefinesByType<ItemDef>();
var weaponDefs = Managers.DefineManager.Instance.QueryDefinesByType<WeaponDef>();

View File

@ -1,8 +1,8 @@
using Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Data;
using UnityEngine;
namespace Managers

View File

@ -1,11 +1,11 @@
using System.Collections.Generic;
using Prefab;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace Managers
{
public class RightMenuManager:Utils.MonoSingleton<RightMenuManager>
public class RightMenuManager : Utils.MonoSingleton<RightMenuManager>
{
[SerializeField]
private GameObject _canvas;
@ -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,
RightMenuManager.Instance.Canvas.transform);
var rightMenu=rightMenuObj.GetComponent<RightMenuPrefab>();
var rightMenu = rightMenuObj.GetComponent<RightMenuPrefab>();
rightMenu.Init(buttons);
rightMenu.transform.position = position;
rightMenu.Show();

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Data;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
using Utils;

View File

@ -1,5 +1,3 @@
using System;
using Managers;
using UnityEngine;
namespace Map
@ -12,7 +10,8 @@ namespace Map
{
[SerializeField] private bool defaultOpen = false;
[SerializeField] [Tooltip("此维度的唯一标识符。如果为空将使用GameObject的名称。")]
[SerializeField]
[Tooltip("此维度的唯一标识符。如果为空将使用GameObject的名称。")]
private string _dimensionId;
[SerializeField] public MapGenerator mapGenerator;
@ -74,7 +73,7 @@ namespace Map
private void Start()
{
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()

View File

@ -1,8 +1,6 @@
using System;
using Managers;
using System.Collections.Generic;
using System.Linq;
using Data;
using Managers;
using UnityEngine;
using UnityEngine.Tilemaps;

View File

@ -1,10 +1,9 @@
using System;
using UnityEngine;
using UnityEngine.Tilemaps;
namespace Map
{
public class MapGenerator:MonoBehaviour
public class MapGenerator : MonoBehaviour
{
public DoubleMap baseMap;

View File

@ -4,7 +4,7 @@ using UnityEngine.UI;
namespace Map
{
public class MiniMap : MonoBehaviour,ITickUI
public class MiniMap : MonoBehaviour, ITickUI
{
public Image background;
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.Web;
using Protocol;
using System.Net.Http;
using System.Threading.Tasks;
using UnityEngine;
using Utils;
namespace Network
@ -18,21 +19,17 @@ namespace Network
public GrpcClient()
{
var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler());
var channelOptions = new GrpcChannelOptions
{
HttpHandler = httpHandler
HttpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler())
};
_channel = GrpcChannel.ForAddress(ServerAddress, channelOptions);
_general = new GeneralService.GeneralServiceClient(_channel);
_game = new GameService.GameServiceClient(_channel);
}
~GrpcClient()
{
_channel.ShutdownAsync().Wait();
Application.quitting += () => _channel.ShutdownAsync().Wait();
}
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.RegularExpressions;
namespace AI
namespace Parsing
{
public static class ConditionDelegateFactory
{

View File

@ -1,9 +1,4 @@
using System;
using Data;
using Managers;
using UnityEngine;
namespace AI
namespace Parsing
{
public static class ConditionFunctions
{
@ -12,10 +7,9 @@ namespace AI
return entity.attributes.health >= minHealth;
}
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.Expressions;
namespace Utils
namespace Parsing
{
public static class Resolver
{

View File

@ -5,15 +5,15 @@ using UnityEngine.UI;
namespace Prefab
{
public class ButtonPrefab:MonoBehaviour
public class ButtonPrefab : MonoBehaviour
{
public Button button;
public TMP_Text text;
public string Label
{
get{return text.text;}
set{text.text = value;}
get { return text.text; }
set { text.text = value; }
}
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 Data;
using Entity;
using Unity.VisualScripting;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Prefab

View File

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

View File

@ -1,4 +1,3 @@
using Base;
using UnityEngine;
namespace Prefab

View File

@ -2,7 +2,7 @@ using UnityEngine;
namespace Prefab
{
public class ProgressBarPrefab:MonoBehaviour
public class ProgressBarPrefab : MonoBehaviour
{
public GameObject _progress;
public float Progress
@ -10,7 +10,7 @@ namespace Prefab
get => _progress.transform.localScale.x;
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);
}
}

View File

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

View File

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

View File

@ -9,8 +9,8 @@ namespace Prefab
public string Label
{
get{return text.text;}
set{text.text = value;}
get { return text.text; }
set { text.text = value; }
}
}

View File

@ -1,7 +1,7 @@
using Map;
using System;
using System.Collections.Generic;
using System.Linq;
using Map;
using UnityEngine;
using Utils;

View File

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

View File

@ -165,7 +165,7 @@ namespace UI
{
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.snapEnabled = false;
@ -175,7 +175,7 @@ namespace UI
{
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.snapEnabled = false;
@ -185,7 +185,7 @@ namespace UI
{
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.snapEnabled = true;
@ -195,7 +195,7 @@ namespace UI
{
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.snapEnabled = false;

View File

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

View File

@ -1,6 +1,6 @@
using System.Collections.Generic;
using Base;
using Entity;
using System.Collections.Generic;
using UnityEngine;
// 确保 Character 类在此命名空间下

View File

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

View File

@ -1,5 +1,5 @@
using System;
using Base;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
@ -7,7 +7,7 @@ using UnityEngine.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 TMP_Text countUI;
@ -29,7 +29,7 @@ namespace UI
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)
{
@ -75,13 +75,13 @@ namespace UI
{
if (switchTime > 0)
{
timer+=Time.deltaTime;
timer += Time.deltaTime;
if (timer >= switchTime)
{
timer-=switchTime;
timer -= switchTime;
texturePtr++;
texturePtr%=_item.Item.Icon.Count;
textureUI.sprite=_item.Item.Icon[texturePtr];
texturePtr %= _item.Item.Icon.Count;
textureUI.sprite = _item.Item.Icon[texturePtr];
}
}
}

View File

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

View File

@ -1,10 +1,8 @@
using System;
using TMPro;
using UnityEngine;
namespace UI
{
public class PlayerStateUI:MonoBehaviour,Base.ITick
public class PlayerStateUI : MonoBehaviour, Base.ITick
{
[SerializeField] private BarUI focusedEntityHP;
[SerializeField] private BarUI lastEntityHP;

View File

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

View File

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

File diff suppressed because one or more lines are too long