意见反馈 修改细节
This commit is contained in:
1 parent
1c712ff7d5
commit
dd08f916eb
41 files changed
+7043
-1134
No files matched your search
@@ -4,9 +4,11 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
@@ -169,5 +171,52 @@ namespace Assets.Scripts
|
||||
return str;
|
||||
}
|
||||
|
||||
/*文件转精灵*/
|
||||
public static Sprite PngToSprite(string fullPath, int x, int y)
|
||||
{
|
||||
using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read)) //自动双清
|
||||
{
|
||||
fs.Seek(0, SeekOrigin.Begin); //设定当前流的位置
|
||||
byte[] bytes = new byte[fs.Length]; //创建文件长度缓冲区
|
||||
fs.Read(bytes, 0, (int)fs.Length); //读取文件
|
||||
Texture2D texture = new Texture2D(x, y); //创建Texture
|
||||
texture.LoadImage(bytes);
|
||||
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one / 2);
|
||||
}
|
||||
}
|
||||
/*文件转精灵*/
|
||||
/*打开文件*/
|
||||
public delegate void OpenFileCallBack(string path);
|
||||
public static void OpenFile(OpenFileCallBack callBack,string filter = null)
|
||||
{
|
||||
OpenFileName ofn = new OpenFileName();
|
||||
|
||||
ofn.structSize = Marshal.SizeOf(ofn);
|
||||
|
||||
ofn.filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)\0*.jpg;*.png;*.jpeg;*.bmp\0";
|
||||
if (filter != null) ofn.filter = filter;
|
||||
ofn.file = new string(new char[256]);
|
||||
|
||||
ofn.maxFile = ofn.file.Length;
|
||||
|
||||
ofn.fileTitle = new string(new char[64]);
|
||||
|
||||
ofn.maxFileTitle = ofn.fileTitle.Length;
|
||||
|
||||
ofn.initialDir = UnityEngine.Application.dataPath;//默认路径
|
||||
|
||||
ofn.title = "Open Project";
|
||||
|
||||
ofn.defExt = "JPG";//显示文件的类型
|
||||
//注意 一下项目不一定要全选 但是0x00000008项不要缺少
|
||||
ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
|
||||
|
||||
|
||||
if (Win32.GetOpenFileName(ofn))
|
||||
{
|
||||
callBack(ofn.file);
|
||||
}
|
||||
}
|
||||
/*打开文件*/
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user