diff --git a/Client/Assets/Scripts/Entity/Entity.cs b/Client/Assets/Scripts/Entity/Entity.cs index c098ce0..465d887 100644 --- a/Client/Assets/Scripts/Entity/Entity.cs +++ b/Client/Assets/Scripts/Entity/Entity.cs @@ -30,9 +30,7 @@ namespace Entity } private bool _isPlayerControlled = false; - - private const int WarningInterval = 5000; - private int _warningTicks = 0; + private bool _warning = false; public void Tick() { @@ -85,13 +83,11 @@ namespace Entity currentJob = aiTree.GetJob(this); if (currentJob == null) { - if (_warningTicks<=0) + if (!_warning) { Debug.LogWarning($"{GetType().Name}类型的{name}没有分配到任何工作,给行为树末尾添加等待行为,避免由于没有工作导致无意义的反复查找工作导致性能问题"); - _warningTicks += WarningInterval; + _warning = true; } - - _warningTicks--; return; } currentJob.StartJob(this); diff --git a/Client/Assets/Scripts/Managers/PackagesImageManager.cs b/Client/Assets/Scripts/Managers/PackagesImageManager.cs index a0d019b..e6f43b4 100644 --- a/Client/Assets/Scripts/Managers/PackagesImageManager.cs +++ b/Client/Assets/Scripts/Managers/PackagesImageManager.cs @@ -7,29 +7,42 @@ namespace Managers { public class PackagesImageManager : Utils.Singleton { - public Dictionary packagesImages = new(); - public Dictionary sprites = new(); + public Dictionary> packagesImages = new(); + public Dictionary> sprites = new(); public void Init() { if (packagesImages.Count > 0) return; + var imageDef = Managers.DefineManager.Instance.QueryDefinesByType(); foreach (var ima in imageDef) { - if (ima.path == null) + if (ima.path == null || ima.packID == null) continue; var pack = Managers.DefineManager.Instance.GetDefinePackage(ima); var path = Path.Combine(pack.packRootPath, ima.path); var texture = Configs.ConfigProcessor.LoadTextureByIO(path); if (texture == null) - continue; - packagesImages.Add(ima.name, texture); - SplitTextureIntoSprites(ima.name, texture, ima.hCount, ima.wCount, ima.pixelsPerUnit); + continue; + + var packId = ima.packID; + + if (!packagesImages.ContainsKey(packId)) + packagesImages[packId] = new Dictionary(); + packagesImages[packId].Add(ima.name, texture); + + SplitTextureIntoSprites(packId, ima.name, texture, ima.hCount, ima.wCount, ima.pixelsPerUnit); } } - void SplitTextureIntoSprites(string name, Texture2D texture, int rows, int cols, int pixelsPerUnit) + private void SplitTextureIntoSprites( + string packId, + string baseName, + Texture2D texture, + int rows, + int cols, + int pixelsPerUnit) { if (texture == null || rows <= 0 || cols <= 0) { @@ -43,26 +56,26 @@ namespace Managers var tileWidth = textureWidth / cols; var tileHeight = textureHeight / rows; - // 确保纹理可以被整除 if (tileWidth * cols != textureWidth || tileHeight * rows != textureHeight) { Debug.LogError("Texture dimensions are not divisible by the specified rows and columns."); return; } + + if (!sprites.ContainsKey(packId)) + sprites[packId] = new Dictionary(); - // 遍历每一行和每一列 for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { - // 计算当前小块的矩形区域 - var spriteRect = new Rect(col * tileWidth, row * tileHeight, tileWidth, tileHeight); - - // 创建Sprite - var sprite = Sprite.Create(texture, (Rect)spriteRect, new Vector2(0.5f, 0.5f), pixelsPerUnit); - + 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; - sprites[name + $"_{index}"] = sprite; + var spriteName = $"{baseName}_{index}"; + + sprites[packId][spriteName] = sprite; } } } @@ -70,18 +83,34 @@ namespace Managers public void Reload() { packagesImages.Clear(); + sprites.Clear(); Init(); } - - public Sprite GetSprite(string name) + + public Sprite GetSprite(string packID, string name) { - return sprites.GetValueOrDefault(name, null); + if (string.IsNullOrEmpty(packID)) + { + foreach (var kvp in sprites) + { + if (kvp.Value.TryGetValue(name, out var sprite)) + return sprite; + } + } + else + { + if (!sprites.TryGetValue(packID, out var dict)) return null; + dict.TryGetValue(name, out var sprite); + return sprite; + } + + return null; } - public Sprite GetSprite(string name, int index) + public Sprite GetSprite(string packID, string name, int index) { - name += $"_{index}"; - return GetSprite(name); + var fullName = $"{name}_{index}"; + return GetSprite(packID, fullName); } } } \ No newline at end of file diff --git a/Client/Assets/Scripts/Map/DoubleMap.cs b/Client/Assets/Scripts/Map/DoubleMap.cs index 84d77fa..7d47346 100644 --- a/Client/Assets/Scripts/Map/DoubleMap.cs +++ b/Client/Assets/Scripts/Map/DoubleMap.cs @@ -142,7 +142,7 @@ namespace Map continue; } - var sprite = imagePack.GetSprite(val); + var sprite = imagePack.GetSprite(mappingTableDef.packID,val); if (sprite == null) { var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef);