(client) chore:支持unity的方式加载资源,调整文件名与定义的分布
This commit is contained in:
7
Client/Assets/Scripts/Data/AffiliationDef.cs
Normal file
7
Client/Assets/Scripts/Data/AffiliationDef.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Data
|
||||
{
|
||||
public class AffiliationDef : Define
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/AffiliationDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/AffiliationDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdca0abb717148269b84fe8884ebbf02
|
||||
timeCreated: 1754545405
|
@ -1,25 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class PawnDef : Define
|
||||
{
|
||||
public AttributesDef attributes;
|
||||
public DrawingOrderDef drawingOrder;
|
||||
|
||||
public BehaviorTreeDef behaviorTree;
|
||||
public string affiliation;
|
||||
|
||||
|
||||
}
|
||||
public class MonsterDef:PawnDef
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class BehaviorTreeDef : Define
|
||||
{
|
||||
public BehaviorTreeDef[] childTree;
|
||||
@ -53,8 +37,4 @@ namespace Data
|
||||
}
|
||||
}
|
||||
|
||||
public class AffiliationDef : Define
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/BehaviorTreeDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/BehaviorTreeDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8513d8eee75e4b9f92179e29f88221b3
|
||||
timeCreated: 1754545380
|
@ -2,6 +2,6 @@ namespace Data
|
||||
{
|
||||
public class BuildingDef:PawnDef
|
||||
{
|
||||
|
||||
public bool IsBlocked = true;
|
||||
}
|
||||
}
|
16
Client/Assets/Scripts/Data/CharacterDef.cs
Normal file
16
Client/Assets/Scripts/Data/CharacterDef.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class CharacterDef : PawnDef
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
@ -20,11 +19,6 @@ namespace Data
|
||||
Image,
|
||||
Animation
|
||||
}
|
||||
|
||||
public class CharacterDef : PawnDef
|
||||
{
|
||||
}
|
||||
|
||||
public class DrawingOrderDef : Define
|
||||
{
|
||||
public DrawNodeDef drawingOrder_down;
|
||||
@ -143,5 +137,4 @@ namespace Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
3
Client/Assets/Scripts/Data/DrawingOrderDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/DrawingOrderDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6360fb04b7a9454d9ac6d8f4864ee31f
|
||||
timeCreated: 1754545254
|
7
Client/Assets/Scripts/Data/MonsterDef.cs
Normal file
7
Client/Assets/Scripts/Data/MonsterDef.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Data
|
||||
{
|
||||
public class MonsterDef:PawnDef
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/MonsterDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/MonsterDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eeac50195bd94af4a21039131cdb77d6
|
||||
timeCreated: 1754545363
|
22
Client/Assets/Scripts/Data/PawnDef.cs
Normal file
22
Client/Assets/Scripts/Data/PawnDef.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class PawnDef : Define
|
||||
{
|
||||
public AttributesDef attributes;
|
||||
public DrawingOrderDef drawingOrder;
|
||||
|
||||
public BehaviorTreeDef behaviorTree;
|
||||
public string affiliation;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -89,32 +89,29 @@ namespace Managers
|
||||
packRootSite[drawOrder.packID] = packagePath;
|
||||
}
|
||||
|
||||
var rootPath = packRootSite[drawOrder.packID];
|
||||
var folderPath = Path.Combine(rootPath, drawOrder.texturePath);
|
||||
// 判断是否为 Unity 资源路径
|
||||
bool isUnityResource = drawOrder.texturePath.StartsWith("res:", StringComparison.OrdinalIgnoreCase);
|
||||
string rootPath = packRootSite[drawOrder.packID];
|
||||
|
||||
// 获取图像文件列表
|
||||
try
|
||||
if (isUnityResource)
|
||||
{
|
||||
var imagePath = Configs.ConfigProcessor.GetFilesByExtensions(folderPath,
|
||||
new[] { "jpg", "jpeg", "png", "tga", "tif", "tiff", "psd", "bmp" });
|
||||
// 移除 "res:" 前缀并适配 Unity 资源路径规则
|
||||
string resourceFolder = drawOrder.texturePath.Substring(4).TrimStart('/').Replace('\\', '/');
|
||||
|
||||
foreach (var path in imagePath)
|
||||
// 加载文件夹下的所有纹理资源
|
||||
Texture2D[] textures = Resources.LoadAll<Texture2D>(resourceFolder);
|
||||
if (textures == null || textures.Length == 0)
|
||||
{
|
||||
// 加载纹理
|
||||
Texture2D image = null;
|
||||
try
|
||||
{
|
||||
image = Configs.ConfigProcessor.LoadTextureByIO(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to load texture from path: {path}. Error: {ex.Message}");
|
||||
continue;
|
||||
}
|
||||
Debug.LogWarning($"No textures found in Unity resource folder: {resourceFolder}");
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var image in textures)
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
Debug.LogWarning($"Texture loaded from path: {path} is null.");
|
||||
Debug.LogWarning(
|
||||
$"Texture loaded from Unity resource folder: {resourceFolder} is null.");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -128,20 +125,75 @@ namespace Managers
|
||||
drawOrder.pixelsPerUnit
|
||||
);
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
var name = image.name;
|
||||
|
||||
// 插入纹理
|
||||
InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to create sprite from texture: {path}. Error: {ex.Message}");
|
||||
Debug.LogError(
|
||||
$"Failed to create sprite from Unity resource: {image.name}. Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Debug.LogError($"Failed to retrieve files from folder: {folderPath}. Error: {ex.Message}");
|
||||
// 文件系统路径处理
|
||||
var folderPath = Path.Combine(rootPath, drawOrder.texturePath);
|
||||
|
||||
// 获取图像文件列表
|
||||
try
|
||||
{
|
||||
var imagePath = Configs.ConfigProcessor.GetFilesByExtensions(folderPath,
|
||||
new[] { "jpg", "jpeg", "png", "tga", "tif", "tiff", "psd", "bmp" });
|
||||
|
||||
foreach (var path in imagePath)
|
||||
{
|
||||
// 加载纹理
|
||||
Texture2D image = null;
|
||||
try
|
||||
{
|
||||
image = Configs.ConfigProcessor.LoadTextureByIO(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to load texture from path: {path}. Error: {ex.Message}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (image == null)
|
||||
{
|
||||
Debug.LogWarning($"Texture loaded from path: {path} is null.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// 创建精灵
|
||||
try
|
||||
{
|
||||
var spr = Sprite.Create(
|
||||
image,
|
||||
new Rect(0, 0, image.width, image.height),
|
||||
new Vector2(0.5f, 0.5f), // 中心点
|
||||
drawOrder.pixelsPerUnit
|
||||
);
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
// 插入纹理
|
||||
InsertBodyTexture(drawOrder.packID, drawOrder.texturePath, name, spr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError(
|
||||
$"Failed to create sprite from texture: {path}. Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to retrieve files from folder: {folderPath}. Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,33 +19,7 @@ namespace Map
|
||||
|
||||
void Start()
|
||||
{
|
||||
TileManager.Instance.Init();
|
||||
var mapSize = 10;
|
||||
float noiseScale = 0.1f;
|
||||
|
||||
// 设置偏移量
|
||||
offsetX = -5; // 示例:地图数据从 (-5, -5) 开始
|
||||
offsetY = -5;
|
||||
|
||||
for (int x = 0; x < mapSize; x++)
|
||||
{
|
||||
List<int> col = new();
|
||||
for (int y = 0; y < mapSize; y++)
|
||||
{
|
||||
// 计算柏林噪声值
|
||||
float noiseValue = Mathf.PerlinNoise((x + offsetX) * noiseScale, (y + offsetY) * noiseScale);
|
||||
if (noiseValue < 0.5f) // 小于 0.5 表示 Dirt
|
||||
{
|
||||
col.Add(TileManager.Instance.tileID.GetValueOrDefault("Dirt"));
|
||||
}
|
||||
else // 大于等于 0.5 表示 Grass
|
||||
{
|
||||
col.Add(TileManager.Instance.tileID.GetValueOrDefault("Grass"));
|
||||
}
|
||||
}
|
||||
|
||||
mapData.Add(col);
|
||||
}
|
||||
|
||||
UpdateTexture();
|
||||
}
|
||||
|
Reference in New Issue
Block a user