(client) feat:定义瓦片地图映射
This commit is contained in:
40
Client/Assets/Scripts/Data/MapDefine.cs
Normal file
40
Client/Assets/Scripts/Data/MapDefine.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class TileDef : Define
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class TileMappingTableDef : Define
|
||||
{
|
||||
public Dictionary<string, string> tileDict = new();
|
||||
public override bool Init(XElement xmlDef)
|
||||
{
|
||||
base.Init(xmlDef);
|
||||
// 清空字典以确保没有遗留数据
|
||||
tileDict.Clear();
|
||||
// 检查 xmlDef 是否为空
|
||||
if (xmlDef == null)
|
||||
return false;
|
||||
foreach (var element in xmlDef.Elements())
|
||||
{
|
||||
// 获取子元素的名称作为键
|
||||
var key = element.Name.LocalName;
|
||||
// 获取子元素的 value 属性作为值
|
||||
var value = element.Attribute("value")?.Value;
|
||||
// 检查 value 是否存在
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
tileDict[key] = value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/MapDefine.cs.meta
Normal file
3
Client/Assets/Scripts/Data/MapDefine.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67d4d2ac30e641189cdf018ad6769f0e
|
||||
timeCreated: 1752496329
|
Reference in New Issue
Block a user