From 44cfb559853ad984687e42abaddab1d53ab5fcaa Mon Sep 17 00:00:00 2001 From: zzdxxz <2079238449@qq.com> Date: Thu, 17 Jul 2025 15:42:24 +0800 Subject: [PATCH] =?UTF-8?q?(client)=20feat:=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=93=A6=E7=89=87=E5=92=8C=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com> --- .../Assets/Scripts/Configs/ConfigProcessor.cs | 55 +++++ Client/Assets/Scripts/Data/Define.cs | 19 +- Client/Assets/Scripts/Data/DefinePack.cs | 17 +- Client/Assets/Scripts/Data/MapDefine.cs | 5 +- Client/Assets/Scripts/Data/ResourcesDefine.cs | 20 ++ .../Scripts/Data/ResourcesDefine.cs.meta | 3 + Client/Assets/Scripts/Entity/Monster.cs | 6 +- .../Assets/Scripts/Managers/DefineManager.cs | 188 +++++++++++++++--- .../Scripts/Managers/PackagesImageManager.cs | 87 ++++++++ .../Managers/PackagesImageManager.cs.meta | 3 + .../Assets/Scripts/Managers/TileMapManager.cs | 7 - .../Scripts/Managers/TileMapManager.cs.meta | 3 - Client/Assets/Scripts/Map/DoubleMap.cs | 100 +++++++++- Client/Data/Core/Define/Map/Map.xml | 16 ++ Client/Data/Core/Define/Player/CatGirl.xml | 2 +- .../Character/CatGirl/body/east.png | Bin .../Character/CatGirl/body/north.png | Bin .../Character/CatGirl/body/south.png | Bin .../Character/CatGirl/clothing/east.png | Bin .../Character/CatGirl/clothing/north.png | Bin .../Character/CatGirl/clothing/south.png | Bin .../CatGirl/hair/KiiroHair5_east.png | Bin .../CatGirl/hair/KiiroHair5_north.png | Bin .../CatGirl/hair/KiiroHair5_south.png | Bin .../hairBackground/KiiroHairBG5_east.png | Bin .../hairBackground/KiiroHairBG5_north.png | Bin .../hairBackground/KiiroHairBG5_south.png | Bin .../CatGirl/head/KiiroHeadH1_north.png | Bin .../CatGirl/head/KiiroHeadH1_south.png | Bin .../CatGirl/head/KiiroHeadH1_west.png | Bin .../CatGirl/leftEar/LeftEar_north.png | Bin .../CatGirl/leftEar/LeftEar_south.png | Bin .../CatGirl/leftEar/LeftEar_west.png | Bin .../CatGirl/rightEar/RightEar_east.png | Bin .../CatGirl/rightEar/RightEar_north.png | Bin .../CatGirl/rightEar/RightEar_south.png | Bin .../Core/Resources/Map/GrassDirtDirtWater.png | Bin 0 -> 656 bytes .../Resources/Map/GrassDirtWaterWater.png | Bin 0 -> 680 bytes .../Resources/Map/GrassGrassDirtWater.png | Bin 0 -> 876 bytes Client/Data/Core/Resources/Map/GrassSoild.png | Bin 0 -> 1001 bytes Client/Data/Core/Resources/Map/GrassWater.png | Bin 0 -> 1037 bytes Client/Data/Core/Resources/Map/SoildWater.png | Bin 0 -> 915 bytes 42 files changed, 461 insertions(+), 70 deletions(-) create mode 100644 Client/Assets/Scripts/Data/ResourcesDefine.cs create mode 100644 Client/Assets/Scripts/Data/ResourcesDefine.cs.meta create mode 100644 Client/Assets/Scripts/Managers/PackagesImageManager.cs create mode 100644 Client/Assets/Scripts/Managers/PackagesImageManager.cs.meta delete mode 100644 Client/Assets/Scripts/Managers/TileMapManager.cs delete mode 100644 Client/Assets/Scripts/Managers/TileMapManager.cs.meta rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/body/east.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/body/north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/body/south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/clothing/east.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/clothing/north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/clothing/south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hair/KiiroHair5_east.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hair/KiiroHair5_north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hair/KiiroHair5_south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hairBackground/KiiroHairBG5_east.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hairBackground/KiiroHairBG5_north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/hairBackground/KiiroHairBG5_south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/head/KiiroHeadH1_north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/head/KiiroHeadH1_south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/head/KiiroHeadH1_west.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/leftEar/LeftEar_north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/leftEar/LeftEar_south.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/leftEar/LeftEar_west.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/rightEar/RightEar_east.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/rightEar/RightEar_north.png (100%) rename Client/Data/Core/{Resource => Resources}/Character/CatGirl/rightEar/RightEar_south.png (100%) create mode 100644 Client/Data/Core/Resources/Map/GrassDirtDirtWater.png create mode 100644 Client/Data/Core/Resources/Map/GrassDirtWaterWater.png create mode 100644 Client/Data/Core/Resources/Map/GrassGrassDirtWater.png create mode 100644 Client/Data/Core/Resources/Map/GrassSoild.png create mode 100644 Client/Data/Core/Resources/Map/GrassWater.png create mode 100644 Client/Data/Core/Resources/Map/SoildWater.png diff --git a/Client/Assets/Scripts/Configs/ConfigProcessor.cs b/Client/Assets/Scripts/Configs/ConfigProcessor.cs index 3cafbd3..9dc772a 100644 --- a/Client/Assets/Scripts/Configs/ConfigProcessor.cs +++ b/Client/Assets/Scripts/Configs/ConfigProcessor.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +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 @@ -284,5 +287,57 @@ namespace Configs return resourceDict; } + + /// + /// 从外部指定文件中加载图片 + /// + /// 图片文件的完整路径 + /// 加载成功的 Texture2D 对象,或加载失败时返回 null + public static Texture2D LoadTextureByIO(string filePath) + { + if (string.IsNullOrEmpty(filePath)) + { + Debug.LogError("文件路径为空,请检查输入!"); + return null; + } + + // 检查文件是否存在 + if (!System.IO.File.Exists(filePath)) + { + Debug.LogError($"文件不存在: {filePath}"); + return null; + } + + byte[] bytes = null; + + try + { + // 使用 using 自动管理 FileStream 的生命周期 + using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + { + fs.Seek(0, SeekOrigin.Begin); // 将游标移动到文件开头(可选) + bytes = new byte[fs.Length]; // 创建一个字节数组来存储文件内容 + fs.Read(bytes, 0, bytes.Length); // 读取文件内容到字节数组 + } + } + catch (Exception e) + { + Debug.LogError($"读取文件时发生错误: {e.Message}"); + return null; + } + + // 创建一个默认大小的 Texture2D 对象 + Texture2D texture = new Texture2D(2, 2); // 初始大小为 2x2,LoadImage 会自动调整大小 + + if (texture.LoadImage(bytes)) // 加载图片数据 + { + return texture; // 返回加载成功的 Texture2D 对象 + } + else + { + Debug.LogError("图片加载失败,请检查文件格式是否正确!"); + return null; + } + } } } \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/Define.cs b/Client/Assets/Scripts/Data/Define.cs index db15281..11940b5 100644 --- a/Client/Assets/Scripts/Data/Define.cs +++ b/Client/Assets/Scripts/Data/Define.cs @@ -8,13 +8,15 @@ using System.Xml.Linq; namespace Data { - public abstract class Define + public class Define { public string defName; public string description; public string label; public string packID; + public bool isReferene=false; + /// /// 初始化方法,根据传入的 XML 元素 () 进行处理。 /// @@ -112,18 +114,5 @@ namespace Data return string.Join(Environment.NewLine, text.Split('\n').Select(line => prefix + line)); } } - - public class DefineReference : Define - { - public Define def; - public string className; - public string fieldName; - - public DefineReference(string className, string defName, string fieldName) - { - this.defName = defName; - this.className = className; - this.fieldName = fieldName; - } - } + } \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/DefinePack.cs b/Client/Assets/Scripts/Data/DefinePack.cs index b729adf..74968a1 100644 --- a/Client/Assets/Scripts/Data/DefinePack.cs +++ b/Client/Assets/Scripts/Data/DefinePack.cs @@ -107,10 +107,19 @@ namespace Data public PackAbout packAbout; public string packID; + public string packRootPath; + public string Name + { + get + { + return packAbout.name; + } + } public bool LoadPack(string packPath) { + packRootPath=System.IO.Path.GetFullPath(packPath);; var packDatas = ConfigProcessor.LoadXmlFromPath(packPath); var aboutXmls = FindDocumentsWithRootName(packDatas, "About"); if (aboutXmls == null || aboutXmls.Count < 1) @@ -262,8 +271,12 @@ namespace Data } else { - value = new DefineReference(field.FieldType.Name, element.Value, field.Name); - + var reference = (Define)Activator.CreateInstance(field.FieldType); + reference.isReferene = true; + reference.description=field.FieldType.Name; + reference.label = field.Name; + reference.defName = element.Value; + value = reference; } } else diff --git a/Client/Assets/Scripts/Data/MapDefine.cs b/Client/Assets/Scripts/Data/MapDefine.cs index 2cedc51..aaac497 100644 --- a/Client/Assets/Scripts/Data/MapDefine.cs +++ b/Client/Assets/Scripts/Data/MapDefine.cs @@ -8,7 +8,7 @@ namespace Data { public class TileDef : Define { - public string texturePath = ""; + public ImageDef texture; public string name = ""; public override bool Init(XElement xmlDef) @@ -45,6 +45,7 @@ namespace Data return true; } } - + + } \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/ResourcesDefine.cs b/Client/Assets/Scripts/Data/ResourcesDefine.cs new file mode 100644 index 0000000..72ab58c --- /dev/null +++ b/Client/Assets/Scripts/Data/ResourcesDefine.cs @@ -0,0 +1,20 @@ +using System.Xml.Linq; + +namespace Data +{ + public class ImageDef : Define + { + public string name; + public string path; + public int wCount; + public int hCount; + public int pixelsPerUnit = 16; + + public override bool Init(XElement xmlDef) + { + base.Init(xmlDef); + name = defName; + return false; + } + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/ResourcesDefine.cs.meta b/Client/Assets/Scripts/Data/ResourcesDefine.cs.meta new file mode 100644 index 0000000..370a88b --- /dev/null +++ b/Client/Assets/Scripts/Data/ResourcesDefine.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8988509c3c0f4525871f5ccd7ef28363 +timeCreated: 1752672894 \ No newline at end of file diff --git a/Client/Assets/Scripts/Entity/Monster.cs b/Client/Assets/Scripts/Entity/Monster.cs index 33af0b8..59be189 100644 --- a/Client/Assets/Scripts/Entity/Monster.cs +++ b/Client/Assets/Scripts/Entity/Monster.cs @@ -2,7 +2,11 @@ namespace Entity { public class Monster { - + public Protocol.MonsterPack ToPack() + { + var pack= new Protocol.MonsterPack(); + return pack; + } } public class MonsterAttributes diff --git a/Client/Assets/Scripts/Managers/DefineManager.cs b/Client/Assets/Scripts/Managers/DefineManager.cs index 7af89ce..0c521c6 100644 --- a/Client/Assets/Scripts/Managers/DefineManager.cs +++ b/Client/Assets/Scripts/Managers/DefineManager.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; using Data; using UnityEngine; using Utils; @@ -30,52 +32,53 @@ namespace Managers var pack = new DefinePack(); if (pack.LoadPack(folder)) packs.Add(pack.packID, pack); } - List> defineRefs = new(); + + Dictionary fieldCache = new(); + //不优化到循环里面是因为要先建立索引再链接 + List> defineCache = new(); + foreach (var pack in packs) { foreach (var define in pack.Value.defines) { - var typeName=define.Key; - var defList=define.Value; + var typeName = define.Key; + var defList = define.Value; + if (!defines.ContainsKey(typeName)) defines[typeName] = new Dictionary(); + foreach (var def in defList) { defines[typeName][def.defName] = def; - if (def is DefineReference reference) + + // 如果字段信息已经缓存,则直接使用缓存 + if (!fieldCache.TryGetValue(def.GetType(), out var defineFields)) { - defineRefs.Add(new(def,reference)); + // 获取所有字段类型为 Define 或其派生类型的字段 + defineFields = def.GetType() + .GetFields(BindingFlags.Public | BindingFlags.Instance) + .Where(field => typeof(Define).IsAssignableFrom(field.FieldType)) + .ToArray(); + // 缓存字段信息 + fieldCache[def.GetType()] = defineFields; + } + + foreach (var defineField in defineFields) + { + var defRef=(Define)defineField.GetValue(def); + if (defRef==null || !defRef.isReferene) + continue; + defineCache.Add(new(def, defineField, defRef)); } } } } - foreach (var defineRef in defineRefs) + foreach (var defRef in defineCache) { - var define = defineRef.Item1; - var reference = defineRef.Item2; - var referenceDef=FindDefine(reference.className,define.defName); - - var property = define.GetType().GetProperty(reference.fieldName); - if (property != null && property.CanWrite) - { - property.SetValue(define, referenceDef); - } - else - { - // 如果是字段而不是属性 - var field = define.GetType().GetField(reference.fieldName); - if (field != null) - { - field.SetValue(define, referenceDef); - } - else - { - // 处理找不到成员的情况 - Debug.LogError($"Could not find field or property '{reference.fieldName}' in type {define.GetType().Name}"); - } - } + defRef.Item2.SetValue(defRef.Item1, FindDefine(defRef.Item3.description, defRef.Item3.defName)); } + } /// /// 查找指定定义类型的定义名对应的 Define 对象。 @@ -94,6 +97,133 @@ namespace Managers } return null; } + + public DefinePack GetDefinePackage(Define define) + { + if (define == null || define.packID == null) + return null; + packs.TryGetValue(define.packID, out var pack); + return pack; + } + + public string GetDefinePackageName(Define define) + { + return GetDefinePackage(define)?.Name; + } + public string GetPackagePath(string packID) + { + if (packs.TryGetValue(packID, out var pack)) + { + return pack.packRootPath; + } + return null; + } + + public Define[] GetAllDefine() + { + List defineList = new(); + foreach (var define in defines.Values) + { + defineList.AddRange(define.Values); + } + return defineList.ToArray(); + } + + /// + /// 查询 Define 对象。 + /// + /// 定义类型(外层字典的键)。 + /// 定义名(内层字典的键)。 + /// 如果找到,则返回 Define 对象;否则返回 null。 + public Define QueryDefine(string defineType, string defineName) + { + if (string.IsNullOrEmpty(defineType)) + { + Debug.LogError("查询失败:定义类型参数不能为空!"); + return null; + } + if (string.IsNullOrEmpty(defineName)) + { + Debug.LogError("查询失败:定义名参数不能为空!"); + return null; + } + if (!defines.TryGetValue(defineType, out var typeDefinitions)) + { + Debug.LogWarning($"查询失败:未找到定义类型 '{defineType}'"); + return null; + } + if (!typeDefinitions.TryGetValue(defineName, out var targetDefine)) + { + Debug.LogWarning($"查询失败:定义类型 '{defineType}' 中未找到定义名 '{defineName}'"); + return null; + } + return targetDefine; + } + /// + /// 查询指定类型下的所有 Define 对象。 + /// + /// 定义类型(外层字典的键)。 + /// 该类型下的 Define 数组,如果未找到则返回 null。 + public Define[] QueryDefinesByType(string defineType) + { + if (string.IsNullOrEmpty(defineType)) + { + Debug.LogError("查询失败:定义类型参数不能为空!"); + return null; + } + + if (!defines.TryGetValue(defineType, out var typeDefinitions)) + { + Debug.LogWarning($"查询失败:未找到定义类型 '{defineType}'"); + return null; + } + + return typeDefinitions.Values.ToArray(); + } + /// + /// 查询指定类型下的所有 Define 对象,并尝试转换为目标类型。 + /// + /// 目标类型。 + /// 转换后的目标类型数组,如果未找到或转换失败则返回 null。 + public T[] QueryDefinesByType() + { + var defineType = typeof(T).Name; + if (string.IsNullOrEmpty(defineType)) + { + Debug.LogError("查询失败:定义类型参数不能为空!"); + return null; + } + + if (!defines.TryGetValue(defineType, out var typeDefinitions)) + { + Debug.LogWarning($"查询失败:未找到定义类型 '{defineType}'"); + return null; + } + + try + { + // 获取所有值并尝试转换为目标类型 + var result = new List(); + foreach (var item in typeDefinitions.Values) + { + if (item is T converted) + { + result.Add(converted); + } + else + { + Debug.LogError($"类型转换失败:无法将 {item.GetType().Name} 转换为 {typeof(T).Name}"); + return null; + } + } + return result.ToArray(); + } + catch (Exception ex) + { + Debug.LogError($"类型转换失败:从 Define 转换为 {typeof(T).Name} 时出错。错误信息:{ex.Message}"); + return null; + } + } public override string ToString() { if (packs == null || packs.Count == 0) diff --git a/Client/Assets/Scripts/Managers/PackagesImageManager.cs b/Client/Assets/Scripts/Managers/PackagesImageManager.cs new file mode 100644 index 0000000..b645994 --- /dev/null +++ b/Client/Assets/Scripts/Managers/PackagesImageManager.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using System.IO; +using Data; +using UnityEngine; + +namespace Managers +{ + public class PackagesImageManager : Utils.Singleton + { + 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) + 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); + } + } + + void SplitTextureIntoSprites(string name, Texture2D texture, int rows, int cols, int pixelsPerUnit) + { + if (texture == null || rows <= 0 || cols <= 0) + { + Debug.LogError("Invalid parameters for splitting texture."); + return; + } + + var textureWidth = texture.width; + var textureHeight = texture.height; + + 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; + } + + // 遍历每一行和每一列 + 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); + + var index = row * cols + col; + sprites[name + $"_{index}"] = sprite; + } + } + } + + public void Reload() + { + packagesImages.Clear(); + Init(); + } + + public Sprite GetSprite(string name) + { + return sprites.GetValueOrDefault(name, null); + } + + public Sprite GetSprite(string name, int index) + { + name += $"_{index}"; + return GetSprite(name); + } + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Managers/PackagesImageManager.cs.meta b/Client/Assets/Scripts/Managers/PackagesImageManager.cs.meta new file mode 100644 index 0000000..c310713 --- /dev/null +++ b/Client/Assets/Scripts/Managers/PackagesImageManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a3bbc0fa9efd4f018e27a6b9f2845140 +timeCreated: 1752672790 \ No newline at end of file diff --git a/Client/Assets/Scripts/Managers/TileMapManager.cs b/Client/Assets/Scripts/Managers/TileMapManager.cs deleted file mode 100644 index 5f7ecbb..0000000 --- a/Client/Assets/Scripts/Managers/TileMapManager.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Managers -{ - public class TileMapManager - { - - } -} \ No newline at end of file diff --git a/Client/Assets/Scripts/Managers/TileMapManager.cs.meta b/Client/Assets/Scripts/Managers/TileMapManager.cs.meta deleted file mode 100644 index 5e80be3..0000000 --- a/Client/Assets/Scripts/Managers/TileMapManager.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b9c65bbe278844978d49c3cd26c050ed -timeCreated: 1752248825 \ No newline at end of file diff --git a/Client/Assets/Scripts/Map/DoubleMap.cs b/Client/Assets/Scripts/Map/DoubleMap.cs index 2d88a58..093e6da 100644 --- a/Client/Assets/Scripts/Map/DoubleMap.cs +++ b/Client/Assets/Scripts/Map/DoubleMap.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Data; using UnityEngine; using UnityEngine.Tilemaps; @@ -7,26 +8,105 @@ namespace Map { public class DoubleMap : MonoBehaviour { - public Tilemap dataLevel; + public List> mapData = new(); + // public Tilemap dataLevel; public Tilemap textureLevel; public Dictionary tileDict = new(); void Start() { - tileDict = Configs.ConfigProcessor.LoadResources("TileMap"); - var tile= tileDict.Values; - for (int i = 0; i < 100; i++) + TileManager.Instance.Init(); + } + + public void UpdateTexture() + { + + } + + public void SetTile(int x, int y, string tileName) + { + + } + + public void SetTile(int x, int y, int id) + { + + } + + } + + public class TileManager:Utils.Singleton + { + public Dictionary<(int, int, int, int), TileBase> tileToTileBaseMapping = new(); + public Dictionary tileID = new(); + public void Init() + { + if (tileToTileBaseMapping.Count > 0) + return; + Managers.PackagesImageManager.Instance.Init(); + var imagePack = Managers.PackagesImageManager.Instance; + var tileType = Managers.DefineManager.Instance.QueryDefinesByType(); + for (var i = 1; i < tileType.Length; i++) { - for (int j = 0; j < 100; j++) + tileID.Add(tileType[i].name, i); + } + + var tileTextureMappingDef=Managers.DefineManager.Instance.QueryDefinesByType(); + foreach (var mappingTableDef in tileTextureMappingDef) + { + foreach (var keyVal in mappingTableDef.tileDict) { - textureLevel.SetTile(new(i,j),tile.First()); + var key = keyVal.Key; + var val=keyVal.Value; + var parts = key.Split('_'); + if (parts.Length != 4) + { + var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef); + Debug.LogError($"来自{packName}定义的TileMappingTableDef键值{key}内容不合法!\n应该为[瓦片名称_瓦片名称_瓦片名称_瓦片名称]的格式"); + continue; + } + + if (!(tileID.TryGetValue(parts[0], out var k1) && + tileID.TryGetValue(parts[1], out var k2) && + tileID.TryGetValue(parts[2], out var k3) && + tileID.TryGetValue(parts[3], out var k4))) + { + var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef); + Debug.LogError($"来自{packName}定义的TileMappingTableDef键值{key}中存在未定义的瓦片名称"); + continue; + } + var sprite = imagePack.GetSprite(val); + if (sprite == null) + { + var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef); + Debug.LogError($"来自{packName}定义的TileMappingTableDef键值{val}中存在未定义的图片名称"); + continue; + } + if (tileToTileBaseMapping.ContainsKey((k1, k2, k3, k4))) + { + var packName = Managers.DefineManager.Instance.GetDefinePackageName(mappingTableDef); + Debug.LogWarning($"来自{packName}定义的TileMappingTableDef键值{(k1, k2, k3, k4)}存在重复索引,将忽略重复项"); + continue; + } + var tile = LoadTile(sprite); + tileToTileBaseMapping.Add((k1, k2, k3, k4), tile); } } } - } - public class TileMappingTable:Utils.Singleton - { - + public void Reload() + { + tileToTileBaseMapping.Clear(); + Init(); + } + + public TileBase LoadTile(Sprite sprite) + { + var newTile = ScriptableObject.CreateInstance(); + newTile.sprite = sprite; + newTile.color = Color.white; + newTile.colliderType = Tile.ColliderType.Sprite; + return newTile; + } } } diff --git a/Client/Data/Core/Define/Map/Map.xml b/Client/Data/Core/Define/Map/Map.xml index 2c9384d..a9778d4 100644 --- a/Client/Data/Core/Define/Map/Map.xml +++ b/Client/Data/Core/Define/Map/Map.xml @@ -1,5 +1,21 @@ + + GrassDirt + Resources\Map\GrassSoild.png + 4 + 4 + + + + Grass + Grass + + + Dirt + Dirt + + GrassDirtTable diff --git a/Client/Data/Core/Define/Player/CatGirl.xml b/Client/Data/Core/Define/Player/CatGirl.xml index 5516c08..41b6a56 100644 --- a/Client/Data/Core/Define/Player/CatGirl.xml +++ b/Client/Data/Core/Define/Player/CatGirl.xml @@ -3,7 +3,7 @@ CatGirl 100 - 1.2 + 2 diff --git a/Client/Data/Core/Resource/Character/CatGirl/body/east.png b/Client/Data/Core/Resources/Character/CatGirl/body/east.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/body/east.png rename to Client/Data/Core/Resources/Character/CatGirl/body/east.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/body/north.png b/Client/Data/Core/Resources/Character/CatGirl/body/north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/body/north.png rename to Client/Data/Core/Resources/Character/CatGirl/body/north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/body/south.png b/Client/Data/Core/Resources/Character/CatGirl/body/south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/body/south.png rename to Client/Data/Core/Resources/Character/CatGirl/body/south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/clothing/east.png b/Client/Data/Core/Resources/Character/CatGirl/clothing/east.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/clothing/east.png rename to Client/Data/Core/Resources/Character/CatGirl/clothing/east.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/clothing/north.png b/Client/Data/Core/Resources/Character/CatGirl/clothing/north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/clothing/north.png rename to Client/Data/Core/Resources/Character/CatGirl/clothing/north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/clothing/south.png b/Client/Data/Core/Resources/Character/CatGirl/clothing/south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/clothing/south.png rename to Client/Data/Core/Resources/Character/CatGirl/clothing/south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_east.png b/Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_east.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_east.png rename to Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_east.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_north.png b/Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_north.png rename to Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_south.png b/Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hair/KiiroHair5_south.png rename to Client/Data/Core/Resources/Character/CatGirl/hair/KiiroHair5_south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_east.png b/Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_east.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_east.png rename to Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_east.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_north.png b/Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_north.png rename to Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_south.png b/Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/hairBackground/KiiroHairBG5_south.png rename to Client/Data/Core/Resources/Character/CatGirl/hairBackground/KiiroHairBG5_south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_north.png b/Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_north.png rename to Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_south.png b/Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_south.png rename to Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_west.png b/Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_west.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/head/KiiroHeadH1_west.png rename to Client/Data/Core/Resources/Character/CatGirl/head/KiiroHeadH1_west.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_north.png b/Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_north.png rename to Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_south.png b/Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_south.png rename to Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_south.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_west.png b/Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_west.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/leftEar/LeftEar_west.png rename to Client/Data/Core/Resources/Character/CatGirl/leftEar/LeftEar_west.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_east.png b/Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_east.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_east.png rename to Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_east.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_north.png b/Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_north.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_north.png rename to Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_north.png diff --git a/Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_south.png b/Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_south.png similarity index 100% rename from Client/Data/Core/Resource/Character/CatGirl/rightEar/RightEar_south.png rename to Client/Data/Core/Resources/Character/CatGirl/rightEar/RightEar_south.png diff --git a/Client/Data/Core/Resources/Map/GrassDirtDirtWater.png b/Client/Data/Core/Resources/Map/GrassDirtDirtWater.png new file mode 100644 index 0000000000000000000000000000000000000000..836210218720db66cf4308987b2493dccfb5358e GIT binary patch literal 656 zcmV;B0&o3^P)Px%N=ZaPRCt{2o3B>GFcikWaw;}~>Ju=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?d00001 diff --git a/Client/Data/Core/Resources/Map/GrassGrassDirtWater.png b/Client/Data/Core/Resources/Map/GrassGrassDirtWater.png new file mode 100644 index 0000000000000000000000000000000000000000..b12f6be44d39207212b8b1c942d4934f4998e38c GIT binary patch literal 876 zcmV-y1C#uTP)Px&CP_p=RCt{2Tfa{fK@|R$Orh~CjLo%oAy8tgEsaDQDiTbtv9rUOKtch?zF#y=DCuVX6SFYhkuU4NXaEF& zY}zcKVa^7zfI}W&b^$vRnhq{`0LWgwec@!l*7`DO-0OB`i>xB}$d8WCoZr;y$%Sk9 z?`jLdRkdl*#3`z}zF`k&WA$5bn9zRn_o0j2%8srIx~1w==~O1Z86q3BYj@Qk)R}$yvaMCy(-102pi!Guv)> zFt{6R4=1Zk%4S~BKB(9@5D6fG79mvo^Fj~-Vj!+TjsaEf$E$*mlOsTi^R-+Pfn;!&Q2Fdk-P@QO{Gkjg3Y(}$KuL<<03gxjS)6qCj%s}pqj8L zlEgr9Bf9`s1nIgv1h_HyIJJHZSO`#e0Ci&_K-~eWQBt?Z4H%LJ3W$vKw+ z(sI@qVRLl4K*}Oe+{jrVMG<_QT0af8UI5YC;j7#GrKi3E|KHEsHX$&rZ7MbnL>a(o zIOP5yg#S`qpb48G8)ai61xTe<@Z+Z+lfQkO905#2Nzri=v9-ROEApm9P^mm^E^NNp z`?a1^Ev{9I`RSX`)vnYx581b`?;HUn<>pPphd0l>@l$2LtS?4@;;QQ=K{9r+roouV z1NW)UE%Gj03EJd~-W>bR7=8P36Gb0QN&Fw~9I-N?FaspyeKs8O_W!8U8>xRzCa_n6 zlEMkomP?+pG4CzwzX+A>1|??Px&qe(k_H6=L9nO>RfRy}aG>rVAgSwLQSlTK zRSdQvwIn4cd!{+lOY089T&C06@7eeE6@E!`V)x#@`OU}9OsAbMub$n5GB&$C004}q zBe=fVMnC8B;vBwy`UU_1gMLrt-8jy&JT(!wcY4o4WtgBwfOODgwuH-z^WbMaeiVL| z2`qoZ$_cv{S z)&M3-F>b^m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