unity工具开发
1.EditorWindow通过拖拽获取文件夹或者文件路径
#region 拖拽相关
Rect rect4 = EditorGUILayout.GetControlRect();
//将上面的框作为文本输入框
selectPath = EditorGUI.TextField(rect4, selectPath);
//subPath = EditorGUILayout.TextField(subPath);
//如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在的位置在文本输入框内
if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragExited) && rect4.Contains(Event.current.mousePosition))
{
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
{
selectPath = DragAndDrop.paths[0];
}
}
#endregion
2.反序列化
public static Object GetObjectFromBytes(byte[] datas)
{
if (datas == null || datas.Length == 0)
return null;
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream stream = new MemoryStream(datas, 0, datas.Length))
{
Object obj = bf.Deserialize(stream) as Object;
stream.Dispose();
return obj;
}
}
3.保存到文件
bool SaveLocalFile(string path, byte[] data)
{
if (File.Exists(path))
File.Delete(path);
using (FileStream fs = new FileStream(path, FileMode.CreateNew))
{
if (fs == null)
return false;
fs.Write(data, 0, data.Length);
AssetDatabase.Refresh();
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
return true;
}
}
4.取文件
public byte[] GetLocalFile(string path)
{
if (File.Exists(path) == false)
return null;
using (FileStream fs = new FileStream(path, FileMode.Open))
{
if (fs == null || fs.Length == 0)
return null;
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
return data;
}
}
5.调用windows系统dialog 选择文件夹
#region 调用windows系统dialog 选择文件夹
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenDialogFile
{
public int structSize = 0;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public String filter = null;
public String customFilter = null;
public int maxCustFilter = 0;
public int filterIndex = 0;
public String file = null;
public int maxFile = 0;
public String fileTitle = null;
public int maxFileTitle = 0;
public String initialDir = null;
public String title = null;
public int flags = 0;
public short fileOffset = 0;
public short fileExtension = 0;
public String defExt = null;
public IntPtr custData = IntPtr.Zero;
public IntPtr hook = IntPtr.Zero;
public String templateName = null;
public IntPtr reservedPtr = IntPtr.Zero;
public int reservedInt = 0;
public int flagsEx = 0;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenDialogDir
{
public IntPtr hwndOwner = IntPtr.Zero;
public IntPtr pidlRoot = IntPtr.Zero;
public String pszDisplayName = null;
public String lpszTitle = null;
public UInt32 ulFlags = 0;
public IntPtr lpfn = IntPtr.Zero;
public IntPtr lParam = IntPtr.Zero;
public int iImage = 0;
}
public class DllOpenFileDialog
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenDialogFile ofn);
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([In, Out] OpenDialogFile ofn);
[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern IntPtr SHBrowseForFolder([In, Out] OpenDialogDir ofn);
[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool SHGetPathFromIDList([In] IntPtr pidl, [In, Out] char[] fileName);
}
public string OpenWindowsDialog()
{
OpenDialogDir ofn2 = new OpenDialogDir();
ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
ofn2.lpszTitle = "Open Project";// 标题
//ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
char[] charArray = new char[2000];
for (int i = 0; i < 2000; i++)
charArray[i] = '\0';
DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
string fullDirPath = new String(charArray);
fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
return fullDirPath;//这个就是选择的目录路径。
}
#endregion
voidOnGUI(){
targetGo =(GameObject)EditorGUILayout.ObjectField(targetGo,typeof(GameObject),true);
subPath = targetGo ==null? subPath : targetGo.name;EditorGUILayout.LabelField(string.Format("保存路径output path:{0}",Path.Combine(path, subPath)));//获得一个长300的框 Rect rect =EditorGUILayout.GetControlRect(GUILayout.Width(300));//将上面的框作为文本输入框
path =EditorGUI.TextField(rect, path);
subPath =EditorGUILayout.TextField(subPath);//如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内 if((Event.current.type==EventType.DragUpdated||Event.current.type==EventType.DragExited)&& rect.Contains(Event.current.mousePosition)){//改变鼠标的外表 DragAndDrop.visualMode=DragAndDropVisualMode.Generic;if(DragAndDrop.paths!=null&&DragAndDrop.paths.Length>0){
path =DragAndDrop.paths[0];}}……}
unity工具开发的更多相关文章
- unity 工具开发基础
using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; usin ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (三)
本帖是延续的:C# Unity游戏开发——Excel中的数据是如何到游戏中的 (二) 前几天有点事情所以没有继续更新,今天我们接着说.上个帖子中我们看到已经把Excel数据生成了.bin的文件,不过其 ...
- C# Unity游戏开发——Excel中的数据是如何到游戏中的 (四)2018.4.3更新
本帖是延续的:C# Unity游戏开发--Excel中的数据是如何到游戏中的 (三) 最近项目不算太忙,终于有时间更新博客了.关于数据处理这个主题前面的(一)(二)(三)基本上算是一个完整的静态数据处 ...
- 【Unity】开发WebGL内存概念具体解释和遇到的问题
自增加unity WebGL平台以来.Unity的开发团队就一直致力于优化WebGL的内存消耗. 我们已经在Unity使用手冊上有对于WebGL内存管理的详尽分析,甚至在Unite Europe 20 ...
- unity开发android游戏(一)搭建Unity安卓开发环境
unity开发android游戏(一)搭建Unity安卓开发环境 分类: Unity2014-03-23 16:14 5626人阅读 评论(2) 收藏 举报 unity开发androidunity安卓 ...
- unity 3d开发的大型网络游戏
unity 3d开发的大型网络游戏 一.总结 1.unity的官网上面应该有游戏列表 2.unity3D是很好的3d游戏引擎,也支持2d,也能做很多画面精良的3A级游戏 3.范围:电脑游戏,手机游戏, ...
- 【远程文件浏览器】Unity+Lua开发调试利器
Remote File Explorer是一个跨平台的远程文件浏览器,用户通过Unity Editor就能操作运行在手机上的游戏或是应用的的目录文件.比如当项目打包运行到设备上时,可通过Remote ...
- Unity3d入门 - 关于unity工具的熟悉
上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...
- 关于Unity游戏开发方向找工作方面的一些个人看法
这是个老生常谈,却又是谁绕不过去的话题,而对于每个人来说,所遇到的情况又不尽相同,别人的求职方式和路线不一定适合你,即使是背景很相似的两个人,有时候机遇也很重要. 我本人的工作经验只有一年,就业方式 ...
随机推荐
- v-model绑定一个对象,组件内部分别负责不同字段的场景实现
我们知道v-model对于单个property双向数据绑定非常有用,保持父子组件之间的数据传递和同步,但也有很多场景下希望一个组件能够处理多个数据字段,这时就有一些小小技巧了. https://sim ...
- python 排序 拓扑排序
在计算机科学领域中,有向图的拓扑排序是其顶点的先行排序,对于每个从顶点u到顶点v的有向边uv,在排序的结果中u都在v之前. 如果图是有向无环图,则拓扑排序是可能的(为什么不说一定呢?) 任何DAG具有 ...
- python网络编程-1
1.网络基础 回顾计算IP所处网段方式 #128 64 32 16 8 4 2 1 #IP1 = 192.168.9.1/24 # 11000000 10101000 00001001 0000000 ...
- Linux存储管理
一.存储基础知识 从工作原理区分: 机械 HDD 固态 SSD SSD的优势: SSD是摒弃传统磁介质,采用电子存储介质进行数据存储和读取的一种技术,突破了传统机械硬盘的性能瓶颈,拥有极高的存储性能, ...
- CTF必备技能丨Linux Pwn入门教程——ShellCode
这是一套Linux Pwn入门教程系列,作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的一些题目和文章整理出一份相对完整的Linux Pwn教程. 课程回顾>> Linu ...
- [TCP/IP] TCP关闭连接为什么四次挥手
1.建立连接的时候, 服务器在LISTEN状态下,收到建立连接请求的SYN报文后,把ACK和SYN放在一个报文里发送给客户端. 2.而关闭连接时,服务器收到对方的FIN报文时,仅仅表示对方不再发送数据 ...
- STM32F429驱动SDRAM
1 SDRAM控制原理 1.1 SDRAM信号线 1.2 SDRAM地址线 SDRAM包含有“A”以及“BA”两类地址线: A:行(Row)与列(Column)共用的地址线 BA:独立的用于指定SDR ...
- LGBMClassifier参数
本文链接:https://blog.csdn.net/starmoth/article/details/845867091.boosting_type=‘gbdt’# 提升树的类型 gbdt,dart ...
- JAVA的toString方法的一个小例子
Object是一个抽象类,他有很有方法,其中的toString方法是我们常见的一个方法,我们可以看这段代码 package com.com.day1; public class ToStringTes ...
- [数据结构与算法] 字符串匹配 - BF算法
BF(Brute Force)算法 又称暴力匹配算法,是一种朴素的模式匹配算法 给定主串 S : Bilibili 和子串 T :Bilididi 步骤: 1. 主串 S 第一位开始与子串 T 第一位 ...