|
@@ -8,6 +8,7 @@
|
|
|
* GraphicData.cs 图档解析类
|
|
|
*/
|
|
|
|
|
|
+using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
@@ -121,13 +122,24 @@ namespace CrossgateToolkit
|
|
|
}
|
|
|
|
|
|
#region 地图合批
|
|
|
+
|
|
|
private class BatchData
|
|
|
{
|
|
|
public int BatchOffsetX;
|
|
|
public int BatchOffsetY;
|
|
|
public GraphicDetail GraphicDetail;
|
|
|
}
|
|
|
+
|
|
|
+ private class TextureData
|
|
|
+ {
|
|
|
+ public int MaxHeight;
|
|
|
+ public int MaxWidth;
|
|
|
+ public List<BatchData> BatchDatas = new List<BatchData>();
|
|
|
+ public List<GraphicInfoData> GraphicInfoDatas = new List<GraphicInfoData>();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ [Obsolete("该方法已废弃,请使用BakeGraphics方法")]
|
|
|
public static Dictionary<uint, GraphicDetail> BakeAsGround(List<GraphicInfoData> groundInfos,int palet=0)
|
|
|
{
|
|
|
|
|
@@ -227,25 +239,26 @@ namespace CrossgateToolkit
|
|
|
return graphicDataDic;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private class TextureData
|
|
|
- {
|
|
|
- public int MaxHeight;
|
|
|
- public int MaxWidth;
|
|
|
- public List<BatchData> BatchDatas = new List<BatchData>();
|
|
|
- public List<GraphicInfoData> GraphicInfoDatas = new List<GraphicInfoData>();
|
|
|
- }
|
|
|
- public static Dictionary<uint, GraphicDetail> BakeAsObject(List<GraphicInfoData> objectInfos,int palet = 0)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static Dictionary<uint, GraphicDetail> BakeGraphics(List<GraphicInfoData> graphicInfoDatas,int palet = 0, int maxTextureSize = 2048,int padding = 0)
|
|
|
{
|
|
|
|
|
|
- int maxWidth = 4096;
|
|
|
- int maxHeight = 4096;
|
|
|
+ int maxWidth = maxTextureSize;
|
|
|
+ int maxHeight = maxTextureSize;
|
|
|
|
|
|
List<TextureData> textureDatas = new List<TextureData>();
|
|
|
Dictionary<uint, GraphicDetail> graphicDataDic = new Dictionary<uint, GraphicDetail>();
|
|
|
|
|
|
|
|
|
- objectInfos = objectInfos.OrderBy(obj => obj.Width).ThenBy(obj => obj.Height).ToList();
|
|
|
+ graphicInfoDatas = graphicInfoDatas.OrderBy(obj => obj.Width).ThenBy(obj => obj.Height).ToList();
|
|
|
|
|
|
int offsetX = 0;
|
|
|
int offsetY = 0;
|
|
@@ -253,14 +266,14 @@ namespace CrossgateToolkit
|
|
|
|
|
|
TextureData textureData = new TextureData();
|
|
|
|
|
|
- for (var i = 0; i < objectInfos.Count; i++)
|
|
|
+ for (var i = 0; i < graphicInfoDatas.Count; i++)
|
|
|
{
|
|
|
- GraphicInfoData graphicInfoData = objectInfos[i];
|
|
|
+ GraphicInfoData graphicInfoData = graphicInfoDatas[i];
|
|
|
|
|
|
if((graphicInfoData.Width + offsetX) > maxWidth)
|
|
|
{
|
|
|
offsetX = 0;
|
|
|
- offsetY = offsetY + maxRowHeight + 5;
|
|
|
+ offsetY = offsetY + maxRowHeight + padding;
|
|
|
maxRowHeight = 0;
|
|
|
}
|
|
|
|
|
@@ -287,7 +300,7 @@ namespace CrossgateToolkit
|
|
|
maxRowHeight = Mathf.Max(maxRowHeight, (int) graphicInfoData.Height);
|
|
|
textureData.MaxHeight = Mathf.Max(textureData.MaxHeight, offsetY + maxRowHeight);
|
|
|
textureData.MaxWidth = Mathf.Max(textureData.MaxWidth, offsetX + (int) graphicInfoData.Width);
|
|
|
- offsetX += (int) graphicInfoData.Width + 5;
|
|
|
+ offsetX += (int) graphicInfoData.Width + padding;
|
|
|
}
|
|
|
|
|
|
|