当前位置:网站首页>Unity customized gadget "export atlas pictures"
Unity customized gadget "export atlas pictures"
2022-07-21 23:01:00 【A shuttle keyboard, Ren lifetime】
public class TestSaveSprite
{
[MenuItem("Tools/ Export Wizard ")]
static void SaveSprite()
{
string resourcesPath1 = "Assets/ResourcesOut/ui/atlas";
foreach (Object obj in Selection.objects)
{
string selectionPath = AssetDatabase.GetAssetPath(obj);
if (selectionPath.StartsWith(resourcesPath1))
{
string selectionExt = System.IO.Path.GetExtension(selectionPath);
if (!selectionExt.Equals(".prefab"))
{
continue;
}
UIAtlas Atlas = UnityEditor.AssetDatabase.LoadAssetAtPath<UIAtlas>(selectionPath);
string outPath = Application.dataPath + "/outSprite/" + Atlas.name;
ExportTexturePNGFromAtlas(outPath, Atlas);
AssetDatabase.Refresh();
}
}
Debug.Log("SaveSprite Finished");
}
static void ExportTexturePNGFromAtlas(string folderPath, UIAtlas atlas)
{
List<UISpriteData> exitSpritesList = atlas.spriteList;
Texture2D atlasTexture = NGUIEditorTools.ImportTexture(atlas.texture, true, false, !atlas.premultipliedAlpha);
int oldwith = atlasTexture.width;
int oldHeight = atlasTexture.height;
Color32[] oldPixels = null;
foreach (var es in exitSpritesList)
{
// Limit es.x stay 0 ~ oldwith Between
int xmin = Mathf.Clamp(es.x, 0, oldwith);
// Limit es.y stay 0 ~ oldHeight Between
int ymin = Mathf.Clamp(es.y, 0, oldHeight);
// Limit es.width stay 0 ~ oldwith Between
int newWidth = Mathf.Clamp(es.width, 0, oldwith);
// Limit es.width stay 0 ~ oldHeight Between
int newHeight = Mathf.Clamp(es.height, 0, oldHeight);
if (newWidth == 0 || newHeight == 0) continue;
// obtain 32 Bit pixel color list
if (oldPixels == null) oldPixels = atlasTexture.GetPixels32();
Color32[] newPixels = new Color32[newWidth * newHeight];
for (int y = 0; y < newHeight; ++y)
{
for (int x = 0; x < newWidth; ++x)
{
int newIndex = (newHeight - 1 - y) * newWidth + x;
int oldIndex = (oldHeight - 1 - (ymin + y)) * oldwith + (xmin + x);
newPixels[newIndex] = oldPixels[oldIndex];
}
}
Texture2D t = new Texture2D(newWidth, newHeight);
t.SetPixels32(newPixels);
t.Apply();
byte[] bytes = t.EncodeToPNG();
Texture2D.DestroyImmediate(t);
t = null;
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using (FileStream fs = new FileStream(folderPath + "/" + es.name + ".png", FileMode.CreateNew))
{
BinaryWriter writer = new BinaryWriter(fs);
writer.Write(bytes);
}
}
}
}
边栏推荐
- Redis sentinel mechanism and configuration process
- 一套十万级TPS的IM综合消息系统的架构实践与思考
- HCIP 第四天
- What is the difference between outgoing and incoming calls in okcc call center
- [oops framework] resource management
- Windows MySQL 5.7+ modify the case sensitive attribute of table name
- eyebeam电话呼叫软件使用及配置方法
- Directx11-- window initialization (Win32)
- 企业应该如何搭建客服机器人
- MySql the first
猜你喜欢
FXS and FXO: what is the difference and how it works
HCIP 第四天
VolP terminal and gateway
Special topic on long connection Gateway Technology (VIII): evolution of microservice based API gateway in station B from 0 to 1
阿里IM技术分享(七):闲鱼IM的在线、离线聊天数据同步机制优化实践
Directx-- draw hexagon (entity type)
HCIP 第七天
MySql the first
VolP终端与网关
Directx11--窗口初始化(win32)
随机推荐
HCIP 第八天
C implementation of balanced tree of binary tree
Visual learning: introduction, advantages and disadvantages of visual layout method
windows mysql 5.7+ 修改表名大小写敏感属性
Force deduction record: dynamic programming 5 subsequence problem (1) -- 300 longest ascending subsequence, 1143 longest common subsequence, 1035 disjoint lines, 674 longest continuous increasing sequ
Comparison between VoIP soft switch and line selection
Why does okcc call center introduce voice into the web?
Decryption of social software red envelope technology (12): technical design and practice behind decryption of Tiktok Spring Festival red envelopes
What are the ways to build a call center? Is okcc's manual outbound call suitable for your enterprise?
D3D function description
Force deduction record: dynamic programming 1 basic topic - 509 Fibonacci number, 70 climbing stairs, 746 climbing stairs with minimum cost, 62 different paths, 63 different paths II, 343 integer spli
OSI参考模型总结
微信团队分享:微信后台在海量并发请求下是如何做到不崩溃的
Sharing of live video technology: understand the push-pull streaming architecture and transmission protocols of mainstream live video systems
unity 模型从相机外进入相机 没有播放指定动作
What is SIP Protocol?
OSPF irregular area, LSA and serial number
Cocos creator 3.2 realizes the complete effect of 2D map 3D character 45 degree RPG game
长连接网关技术专题(七):小米小爱单机120万长连接接入层的架构演进
视频直播技术分享:一文读懂主流视频直播系统的推拉流架构、传输协议等