NGUI图集切割代码
原地址:http://blog.csdn.net/u011440375/article/details/9707491
因为最近工作用NGUI比较多,修改图集时还没原图,有时候需要把图集重新切割开来,用代码会比较方便,一下贴出主要代码 首先读取NGUI图集的信息 [csharp] view plaincopy
UIAtlas mAtlas ;
GameObject[] SelectedAsset=Selection.gameObjects;
if (SelectedAsset.Length == )
{
mAtlas = SelectedAsset[].GetComponent<UIAtlas>(); if (mAtlas != null)
{
string atlasFile = string.Format("{0}.txt", mAtlas.name);
string atlasPng = string.Format("{0}.png", mAtlas.name);
char[] ch = { '.' };
string path = AssetDatabase.GetAssetPath(SelectedAsset[]);
FileInfo aFileinfo = new FileInfo(path);
string th = aFileinfo.DirectoryName;
string[] strs = path.Split(ch); if (File.Exists(atlasFile))
{
File.Delete(atlasFile);
}
StreamWriter sw = new StreamWriter(strs[] + ".txt");
StringBuilder sb = new StringBuilder();
foreach (UIAtlas.Sprite sprite in mAtlas.spriteList)
{
sb.AppendLine(string.Format("name:{0}, coordinate:{1}", sprite.name, sprite.outer));
} sw.Write(sb.ToString());
sw.Close(); string[] arg = new string[];
arg[] = atlasPng;
arg[] = th;
//print(arg[0]);
//print(arg[1]);
string path_2 = AssetDatabase.GetAssetPath(Resources.Load("CutAltas/output"));
FileInfo aFileinfo_2 = new FileInfo(path_2);
string th_2 = aFileinfo_2.DirectoryName;
print(th_2);
string s = th_2 + "\\Start.exe";
这是主要的代码,接下来用vs编写一个程序切割图集,主要代码如下
[csharp] view plaincopy
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string[] p;
string path = string.Empty;
public Form1(string[] s)
{
InitializeComponent();
p = s;
ImageName.Text = p[];
path = p[];
} private void button1_Click(object sender, EventArgs e)
{
CutImage(path);
Application.Exit(); } void CutImage(string p)
{
string path=@"c:\Documents and Settings\Administrator\桌面\";
string savePath=string.Empty;
string imagePath = p + "\\"+ImageName.Text;
string textPath = string.Empty;
Image img = Image.FromFile(imagePath); char[] c = { '.' };
string st= ImageName.Text;
string[] sts = st.Split(c);
savePath = path + sts[];
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
textPath = p + "\\"+sts[]+".txt";
StreamReader sr = new StreamReader(textPath); while (!sr.EndOfStream)
{
string newLine = sr.ReadLine();
// Regex reg = new Regex(@"name:(?P<name>.+), coordinate:\(x:(?P<x>\d+)\.00, y:(?P<y>\d+)\.00, width:(?P<width>\d+)\.00, height:(?P<height>\d+)\.00\)");
// Regex regName = new Regex(@"\bname:\.*");
string patternName = @"\bname:\w*";
string patternX = @"\bcoordinate:\(x:\w*\.\d\d";
string patternY = @"\by:\d*\.\d\d";
string patternWidth = @"\bwidth:\d*\.\d\d";
string patternHeight = @"\bheight:\d*\.\d\d";
string name = savePath+"\\";
float x=,y=,width=,height=;
char[] maoHao = { ':' }; MatchCollection imageName = Regex.Matches(newLine, patternName, RegexOptions.ExplicitCapture); foreach (Match nextMatch in imageName)
{
int index = nextMatch.Index;
string result = nextMatch.ToString(); string[] re = result.Split(maoHao);
name += re[re.Length - ];
name += ".png";
// MessageBox.Show(re[1]);
}
MatchCollection positionX = Regex.Matches(newLine, patternX, RegexOptions.ExplicitCapture);
foreach (Match nextMatch in positionX)
{
int index = nextMatch.Index;
string result = nextMatch.ToString(); string[] re = result.Split(maoHao);
x = float.Parse(re[re.Length - ]);
// MessageBox.Show(x.ToString());
}
MatchCollection positionY = Regex.Matches(newLine, patternY, RegexOptions.ExplicitCapture);
foreach (Match nextMatch in positionY)
{
int index = nextMatch.Index;
string result = nextMatch.ToString(); string[] re = result.Split(maoHao);
y = float.Parse(re[re.Length-]);
// MessageBox.Show(y.ToString());
}
MatchCollection widths = Regex.Matches(newLine, patternWidth, RegexOptions.ExplicitCapture);
foreach (Match nextMatch in widths)
{
int index = nextMatch.Index;
string result = nextMatch.ToString(); string[] re = result.Split(maoHao);
width = float.Parse(re[re.Length - ]);
// MessageBox.Show(width.ToString());
}
MatchCollection heights = Regex.Matches(newLine, patternHeight, RegexOptions.ExplicitCapture);
foreach (Match nextMatch in heights)
{
int index = nextMatch.Index;
string result = nextMatch.ToString(); string[] re = result.Split(maoHao);
height = float.Parse(re[re.Length - ]);
// MessageBox.Show(height.ToString());
// MessageBox.Show("Name: " + name + "x :" + x.ToString() + "y :" + y.ToString() + "width :" + width.ToString() + "height :" + height.ToString());
}
// MessageBox.Show("Name: "+name+"x :"+x.ToString()+"y :"+y.ToString()+"width :"+width.ToString()+"height :"+height.ToString());
Bitmap bmp = new Bitmap(img);
Rectangle rec = new Rectangle((int)x, (int)y, (int)width, (int)height);
bmp = bmp.Clone(rec, bmp.PixelFormat);
bmp.Save(name, System.Drawing.Imaging.ImageFormat.Png);
} MessageBox.Show("切割完成,返回桌面查看!");
// Bitmap bmp = new Bitmap(img, 100, 100);
// bmp.Save(path + "newImage.jpg");
}
}
}
最后unity要调用vs生成的程序,并且传进参数
static bool StartProcess(string filename, string[] args)
{
//print("wwww");
try
{
string s="";
foreach(string arg in args)
{
s += string.Format("\"{0}\" ", arg);
}
s = s.Trim();
print(s);
Process myprocess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(filename,s);
myprocess.StartInfo = startInfo;
myprocess.StartInfo.UseShellExecute = false;
myprocess.Start();
return true;
}
catch (Exception ex)
{
UnityEngine.Debug.Log("出错原因:" + ex.Message);
}
return false; }
NGUI图集切割代码的更多相关文章
- Unity3d通用工具类之NGUI图集分解
---恢复内容开始--- Unity3d通用工具类之NGUI图集分解 由于最近需要一些美术资源吗,但是无奈自己不会制作UI,所以就打算去网上的项目中直接找几张可以使用的贴图资源. 但是发现这些资源已经 ...
- 解决切换场景时NGUI图集资源未释放的问题
使用unity3d编辑器,在切换场景的时候.NGUI的图集没有释放造成内存不足游戏闪退的问题. 默认情况下,unity3d切换场景之后会释放不用的内存,即内部会调用Resources.UnloadUn ...
- python实现gabor滤波器提取纹理特征 提取指静脉纹理特征 指静脉切割代码
参考博客:https://blog.csdn.net/xue_wenyuan/article/details/51533953 https://blog.csdn.net/jinshengtao/ar ...
- NGUI 图集生成 图片Sprite 有撕裂边的问题
修改 Dimensions 的 X 和 Y值进行调整. 在生成图集时 选择Padding 设置1以上 应该不会出现这个问题.
- Unity NGUI 图集Atlas制作
unity版本:4.5 NGUI版本:3.6.5 1.选择要制作的图片放到对应目录下,在Asset下新建一个文件夹Picture用于放置图片: 2.选中一张图片,打开Atlas Maker: 3.单击 ...
- NGUI图集字体
UIFont里使用Symbols来指定字体时用Sprite前缀和名字自动分配的工具,前段时间工作需要时写的,具体用法有空时再写. using UnityEngine; using UnityEdito ...
- 【java】【mybatis】在使用mybatis进行批量插入,批量更新等批量操作时,切割In集合List进行分批批量操作的java中的切割代码
红字部分代表mybatis的批量操作调用方法: int num = 0; int maxLength = 200; int size = usableCodes.size(); if (size &l ...
- 新闻门户网站图集相册JS代码
新闻网站jQuery图集相册代码,支持键盘方向键切换,支持点击图片左右区域切换,支持自动轮播,带缩略图.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class= ...
- NGUI中Button与原生2D精灵的混合使用
一些废话 每一篇的首段都是这个“一些废话”,原因是我太能逼逼了,不逼逼一些废话我就觉得难受.这是我第四篇关于Unity的博文,前两篇还是去年写的,“从一点儿不会开始”系列,类似教程和学习笔记的博文,这 ...
随机推荐
- go chapter 8 - 初始化对象
http://blog.haohtml.com/archives/14239 struct定义的属性如果是小写开头的,那么该属性不是public的,不能跨包调用 (implicit assignmen ...
- 【Bzoj3527】【Luogu3338】[Zjoi2014]力(FFT)
题面 Bzoj Luogu 题解 先来颓柿子 $$ F_i=\sum_{j<i}\frac{q_iq_j}{(i-j)^2}-\sum_{j>i}\frac{q_iq_j}{(i-j)^2 ...
- Sqli-labs介绍、下载、安装
SQLI和sqli-labs介绍 SQLI,sql injection,我们称之为sql注入.何为sql,英文:Structured Query Language,叫做结构化查询语言.常见的结构化数据 ...
- 【BZOJ 1901】【ZJU 2112】Dynamic Rankings
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 重新用整体二分写了一下. 整体二分的思想详见论文. 貌似带修区间k大和静态区间k大都是\(O( ...
- 【BZOJ 3309】DZY Loves Math
http://www.lydsy.com/JudgeOnline/problem.php?id=3309 \[\sum_{T=1}^{min(a,b)}\sum_{d|T}f(d)\mu(\frac ...
- BZOJ 4589 Hard Nim(FWT+博弈论+快速幂)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4589 [题目大意] 有n堆石子,每堆都是m以内的质数,请问后手必胜的局面有几种 [题解 ...
- 【数论】【二次剩余】【map】hdu6128 Inverse of sum
部分引用自:http://blog.csdn.net/v5zsq/article/details/77255048 所以假设方程 x^2+x+1=0 在模p意义下的解为d,则答案就是满足(ai/aj) ...
- 【预处理】【分类讨论】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
分几种情况讨论: (1)仅用C或D买两个 ①买两个代价相同的(实际不同)(排个序) ②买两个代价不同的(因为买两个代价相同的情况已经考虑过了,所以此时对于同一个代价,只需要保存美丽度最高的喷泉即可)( ...
- 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon
普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...
- 创建Django与项目介绍
主流web框架总结 a socket b 路由关系 c 模板字符串替换(模板语言) 主流web框架 djange a用别人的 b自己写 c自己写 flask a用别人的 b自己写 c用别人的(jinj ...