109 lines
3.3 KiB
C#
109 lines
3.3 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.Editor.Test
|
|||
|
{
|
|||
|
//图集打包信息
|
|||
|
public class PackDataInfo
|
|||
|
{
|
|||
|
public int PackImgWidth = 0;
|
|||
|
public int PackImgHeight = 0;
|
|||
|
public List<Rect> SourceRectList = new List<Rect>();
|
|||
|
public List<Rect> PackedRectList = new List<Rect>();
|
|||
|
public List<int> LightmapIndexList = new List<int>();
|
|||
|
public List<string> SaveFileNameList = new List<string>();
|
|||
|
public List<string> LightmapPathList = new List<string>();
|
|||
|
|
|||
|
public void Write(BinaryWriter bw)
|
|||
|
{
|
|||
|
bw.Write(PackImgWidth);
|
|||
|
bw.Write(PackImgHeight);
|
|||
|
WriteRectList(bw, SourceRectList);
|
|||
|
WriteRectList(bw, PackedRectList);
|
|||
|
WriteIntList(bw, LightmapIndexList);
|
|||
|
WriteStringList(bw, SaveFileNameList);
|
|||
|
WriteStringList(bw, LightmapPathList);
|
|||
|
}
|
|||
|
|
|||
|
public void Read(BinaryReader br)
|
|||
|
{
|
|||
|
PackImgWidth = br.ReadInt32();
|
|||
|
PackImgHeight = br.ReadInt32();
|
|||
|
SourceRectList = ReadRectList(br);
|
|||
|
PackedRectList = ReadRectList(br);
|
|||
|
LightmapIndexList = ReadIntList(br);
|
|||
|
SaveFileNameList = ReadStrList(br);
|
|||
|
LightmapPathList = ReadStrList(br);
|
|||
|
}
|
|||
|
|
|||
|
private static void WriteRectList(BinaryWriter bw, List<Rect> rectList)
|
|||
|
{
|
|||
|
int count = rectList.Count;
|
|||
|
bw.Write(count);
|
|||
|
for (int i = 0; i < rectList.Count; ++i)
|
|||
|
{
|
|||
|
bw.Write(Mathf.RoundToInt(rectList[i].x));
|
|||
|
bw.Write(Mathf.RoundToInt(rectList[i].y));
|
|||
|
bw.Write(Mathf.RoundToInt(rectList[i].width));
|
|||
|
bw.Write(Mathf.RoundToInt(rectList[i].height));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static List<Rect> ReadRectList(BinaryReader br)
|
|||
|
{
|
|||
|
var count = br.ReadInt32();
|
|||
|
List<Rect> rectList = new List<Rect>();
|
|||
|
for (int i = 0; i < count; ++i)
|
|||
|
{
|
|||
|
Rect rect = new Rect(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
|
|||
|
rectList.Add(rect);
|
|||
|
}
|
|||
|
|
|||
|
return rectList;
|
|||
|
}
|
|||
|
|
|||
|
private static void WriteStringList(BinaryWriter bw, List<string> strList)
|
|||
|
{
|
|||
|
bw.Write(strList.Count);
|
|||
|
for (int i = 0; i < strList.Count; ++i)
|
|||
|
{
|
|||
|
bw.Write(strList[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static List<string> ReadStrList(BinaryReader br)
|
|||
|
{
|
|||
|
var count = br.ReadInt32();
|
|||
|
List<string> strList = new List<string>();
|
|||
|
for (int i = 0; i < count; ++i)
|
|||
|
{
|
|||
|
strList.Add(br.ReadString());
|
|||
|
}
|
|||
|
|
|||
|
return strList;
|
|||
|
}
|
|||
|
|
|||
|
private static void WriteIntList(BinaryWriter bw, List<int> intList)
|
|||
|
{
|
|||
|
bw.Write(intList.Count);
|
|||
|
for (int i = 0; i < intList.Count; ++i)
|
|||
|
{
|
|||
|
bw.Write(intList[i]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static List<int> ReadIntList(BinaryReader br)
|
|||
|
{
|
|||
|
int count = br.ReadInt32();
|
|||
|
List<int> retList = new List<int>();
|
|||
|
for (int i = 0; i < count; ++i)
|
|||
|
{
|
|||
|
retList.Add(br.ReadInt32());
|
|||
|
}
|
|||
|
|
|||
|
return retList;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|