(client) chore:Clean code
This commit is contained in:
@ -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"/> 对象。
|
||||
@ -28,7 +28,7 @@ namespace Managers
|
||||
// 如果管理器已经初始化,则直接返回,避免重复加载。
|
||||
if (_affiliations.Count > 0)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
var affiliationList = Managers.DefineManager.Instance.QueryDefinesByType<AffiliationDef>();
|
||||
@ -80,7 +80,7 @@ namespace Managers
|
||||
// 如果任一阵营定义为空,则返回中立关系。
|
||||
if (affiliation1 == null || affiliation2 == null)
|
||||
{
|
||||
return Relation.Neutral;
|
||||
return Relation.Neutral;
|
||||
}
|
||||
return GetRelation(affiliation1.defName, affiliation2.defName);
|
||||
}
|
||||
@ -136,7 +136,7 @@ namespace Managers
|
||||
// 如果 faction1 没有明确设置与 faction2 的关系,则使用 faction1 的默认关系。
|
||||
return faction1.defaultRelation;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置两个阵营之间的关系。
|
||||
/// </summary>
|
||||
@ -187,7 +187,7 @@ namespace Managers
|
||||
throw new ArgumentOutOfRangeException(nameof(relation), relation, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查并修复所有阵营之间的关系,以确保没有冲突。
|
||||
/// 修复遵循优先级规则:友好关系优先于敌对关系,敌对关系优先于中立关系。
|
||||
|
@ -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>
|
||||
/// 数据集文件路径数组,用于指定定义包的根目录。
|
||||
@ -84,7 +84,7 @@ namespace Managers
|
||||
// 存储需要进行链接的定义引用信息。
|
||||
// Tuple的元素依次代表:被引用的定义(Define),引用该定义的字段(FieldInfo),以及引用占位符(Define)。
|
||||
List<Tuple<Define, FieldInfo, Define>> defineCache = new();
|
||||
|
||||
|
||||
string currentPackID;
|
||||
|
||||
// 递归处理定义对象及其内部的嵌套定义和引用。
|
||||
@ -100,7 +100,7 @@ namespace Managers
|
||||
{
|
||||
// 获取所有公共实例字段。
|
||||
defineFields = def.GetType()
|
||||
.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
// 缓存当前类型的字段信息。
|
||||
fieldCache[def.GetType()] = defineFields;
|
||||
@ -181,7 +181,7 @@ namespace Managers
|
||||
{
|
||||
if (!defines.ContainsKey(typeName))
|
||||
defines[typeName] = new Dictionary<string, Define>();
|
||||
|
||||
|
||||
foreach (var def in defList)
|
||||
{
|
||||
defines[typeName][def.defName] = def;
|
||||
@ -321,7 +321,7 @@ namespace Managers
|
||||
}
|
||||
return defineList.ToArray();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定类型下的所有 <see cref="Define"/> 对象(包括命名定义和匿名定义)。
|
||||
/// </summary>
|
||||
@ -399,7 +399,7 @@ namespace Managers
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定类型下的所有命名 <see cref="Define"/> 对象(不包括匿名定义)。
|
||||
/// </summary>
|
||||
@ -481,9 +481,9 @@ namespace Managers
|
||||
if (packs == null || packs.Count == 0)
|
||||
{
|
||||
// 如果集合为空或为 null,返回默认信息。
|
||||
return "No packs available";
|
||||
return "No packs available";
|
||||
}
|
||||
|
||||
|
||||
var result = new System.Text.StringBuilder();
|
||||
|
||||
foreach (var definePack in packs)
|
||||
@ -492,7 +492,7 @@ namespace Managers
|
||||
result.AppendLine(definePack.ToString());
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -45,7 +45,7 @@ namespace Managers
|
||||
|
||||
/// <summary> 子弹实体的预制体。 </summary>
|
||||
public EntityPrefab bulletPrefab;
|
||||
|
||||
|
||||
public EntityPrefab pickupPrefab;
|
||||
|
||||
/// <summary> 默认实体的预制体,用于生成失败时的回退。 </summary>
|
||||
@ -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);
|
||||
|
||||
@ -504,14 +504,14 @@ namespace Managers
|
||||
Debug.LogError($"实体管理器:无法在维度 '{dimensionId}' 中获取或创建实体的父层。");
|
||||
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);
|
||||
if (result == null) GenerateDefaultEntity(dimensionId, pos);
|
||||
_pendingAdditions.Add(Tuple.Create(dimensionId, "default", result));
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 在指定维度和位置生成一个默认实体(通常作为回退选项)。
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using EventType = Data.EventType;
|
||||
|
||||
|
@ -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>();
|
||||
|
||||
@ -38,7 +38,7 @@ namespace Managers
|
||||
$"ItemResourceManager: Duplicate itemDef.defName found: {def.defName}. Skipping this item.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Item.ItemResource itemResource;
|
||||
|
||||
if (def is WeaponDef currentWeaponDef)
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Managers
|
||||
@ -51,7 +51,7 @@ namespace Managers
|
||||
{
|
||||
// 如果已经加载过,直接返回。
|
||||
StepDescription = "包图像管理器已初始化。";
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
StepDescription = "正在加载默认精灵..."; // 更新加载步骤描述
|
||||
@ -73,7 +73,7 @@ namespace Managers
|
||||
{
|
||||
var textureCache = new Dictionary<string, Texture2D>();
|
||||
var imageDef = Managers.DefineManager.Instance.QueryDefinesByType<ImageDef>();
|
||||
|
||||
|
||||
if (imageDef == null || !imageDef.Any())
|
||||
{
|
||||
Debug.Log($"在 DefineManager 中未找到任何 ImageDef 定义。({typeof(ImageDef).Name})");
|
||||
@ -91,9 +91,9 @@ namespace Managers
|
||||
try
|
||||
{
|
||||
string cacheKey;
|
||||
Texture2D texture = null;
|
||||
|
||||
if (ima.path.StartsWith("res:"))
|
||||
Texture2D texture = null;
|
||||
|
||||
if (ima.path.StartsWith("res:"))
|
||||
{
|
||||
// 处理 Resources 路径
|
||||
var resPath = ima.path.Substring(4).Replace('\\', '/').TrimStart('/');
|
||||
@ -243,7 +243,7 @@ namespace Managers
|
||||
Debug.LogError($"包 '{packId}' 中 '{baseName}' 的纹理尺寸 ({textureWidth}x{textureHeight}) 不能被指定的行数 ({rows}) 和列数 ({cols}) 完美整除。子精灵将不会生成或可能不正确。仅显示完整精灵。");
|
||||
return; // 终止子精灵分割,只保留完整的精灵
|
||||
}
|
||||
|
||||
|
||||
var tileWidth = textureWidth / cols;
|
||||
var tileHeight = textureHeight / rows;
|
||||
|
||||
@ -251,11 +251,11 @@ namespace Managers
|
||||
{
|
||||
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 index = (rows - row - 1) * cols + col;
|
||||
var index = (rows - row - 1) * cols + col;
|
||||
var spriteName = $"{baseName}_{index}";
|
||||
sprite.name = spriteName;
|
||||
|
||||
@ -268,7 +268,7 @@ namespace Managers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有已加载的纹理和精灵数据。
|
||||
/// </summary>
|
||||
@ -291,8 +291,8 @@ namespace Managers
|
||||
/// </remarks>
|
||||
public void Reload()
|
||||
{
|
||||
Clear();
|
||||
Init();
|
||||
Clear();
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
@ -303,7 +303,7 @@ namespace Managers
|
||||
/// <returns>如果找到对应的精灵,则返回该精灵;否则返回 <see cref="defaultSprite"/>。</returns>
|
||||
public Sprite GetSprite(ImageDef ima)
|
||||
{
|
||||
if (ima == null) return defaultSprite;
|
||||
if (ima == null) return defaultSprite;
|
||||
return GetSprite(ima.packID, ima.name);
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
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]
|
||||
[SerializeField]
|
||||
private GameObject _canvas;
|
||||
|
||||
[SerializeField]
|
||||
|
||||
[SerializeField]
|
||||
private RightMenuPrefab _rightMenuPrefab;
|
||||
|
||||
public GameObject Canvas
|
||||
@ -35,7 +35,7 @@ namespace Managers
|
||||
{
|
||||
if (_rightMenuPrefab == null)
|
||||
{
|
||||
_rightMenuPrefab = Resources.Load<RightMenuPrefab>("Prefab/RightMenu");
|
||||
_rightMenuPrefab = Resources.Load<RightMenuPrefab>("Prefab/RightMenu");
|
||||
if (_rightMenuPrefab == null)
|
||||
{
|
||||
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,
|
||||
RightMenuManager.Instance.Canvas.transform);
|
||||
var rightMenu=rightMenuObj.GetComponent<RightMenuPrefab>();
|
||||
var rightMenu = rightMenuObj.GetComponent<RightMenuPrefab>();
|
||||
rightMenu.Init(buttons);
|
||||
rightMenu.transform.position = position;
|
||||
rightMenu.Show();
|
||||
@ -57,7 +57,7 @@ namespace Managers
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Tilemaps;
|
||||
using Utils;
|
||||
@ -35,15 +35,15 @@ namespace Managers
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 确保依赖的 PackagesImageManager 已初始化。
|
||||
// 虽然 Launcher 会按顺序初始化,但这里做一次检查和调用,
|
||||
// 可以防止其他地方直接调用 TileManager.Instance.Init() 时,
|
||||
// 其依赖未准备好的情况。PackagesImageManager 也应该是幂等的。
|
||||
PackagesImageManager.Instance.Init();
|
||||
|
||||
|
||||
var imagePack = Managers.PackagesImageManager.Instance;
|
||||
|
||||
|
||||
// 获取所有瓦片定义
|
||||
var tileDefs = DefineManager.Instance.QueryDefinesByType<TileDef>();
|
||||
for (var i = 0; i < tileDefs.Length; i++)
|
||||
@ -54,7 +54,7 @@ namespace Managers
|
||||
Debug.LogWarning($"<color=orange>瓦片定义 '{tileDefs[i].name}' 的名称重复。</color> 将忽略后续定义。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理瓦片纹理映射表定义
|
||||
var tileTextureMappingDefs = DefineManager.Instance.QueryDefinesByType<TileMappingTableDef>();
|
||||
foreach (var mappingTableDef in tileTextureMappingDefs)
|
||||
@ -94,9 +94,9 @@ namespace Managers
|
||||
continue;
|
||||
}
|
||||
// 创建瓦片实例并存储到映射表中
|
||||
var newTile = CreateTileInstance(sprite);
|
||||
var newTile = CreateTileInstance(sprite);
|
||||
tileToTileBaseMapping[tileKey] = newTile;
|
||||
|
||||
|
||||
// 同样检查 tileBaseMapping 的重复性
|
||||
if (tileBaseMapping.ContainsKey(spriteName))
|
||||
{
|
||||
@ -139,29 +139,29 @@ namespace Managers
|
||||
Object.Destroy(tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tileBaseMapping.Clear();
|
||||
tileToTileBaseMapping.Clear();
|
||||
tileID.Clear();
|
||||
}
|
||||
// ------------- ILaunchManager 接口实现结束 -------------
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 存储瓦片名称与 <see cref="TileBase"/> 对象的映射关系。
|
||||
/// </summary>
|
||||
public Dictionary<string, TileBase> tileBaseMapping = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 存储瓦片组合索引与 <see cref="TileBase"/> 对象的映射关系。
|
||||
/// 索引由四个整数组成,表示瓦片的组合方式。
|
||||
/// </summary>
|
||||
public Dictionary<(int, int, int, int), TileBase> tileToTileBaseMapping = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 存储瓦片名称与唯一 ID 的映射关系。
|
||||
/// </summary>
|
||||
public Dictionary<string, int> tileID = new();
|
||||
|
||||
|
||||
// 移除了 TileManager 内部的 Reload() 方法,因为它将被 Launcher 的 Clear() + Init() 流程取代。
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user