(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

@ -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);
}