unity3d各种OpenFileDialog操作
http://www.cnblogs.com/U-tansuo/archive/2012/07/10/GetOpenFileName.html
1 编辑模式(Editor)下:
- string path = EditorUtility.OpenFilePanel("Load png Textures of Directory", "", "");
- WWW ww=new WWW("file:///"+path);
- print(ww.url);
- yield return ww;
- gui.texture=ww.texture;
2.非编辑模式:

- OpenFileDialog ofd = new OpenFileDialog(); //new一个方法
- ofd.InitialDirectory ="file://"+UnityEngine.Application.dataPath; //定义打开的默认文件夹位置//定义打开的默认文件夹位置
- if(ofd.ShowDialog()==DialogResult.OK)
- {
- //显示打开文件的窗口
- Debug.Log( ofd.FileName);
- }

3、unity3d调用win32打开对话框

- using UnityEngine;
- using System.Collections;
- using System;
- using System.Runtime.InteropServices;
- [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
- public class OpenFileName
- {
- 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;
- }
- public class DllTest
- {
- [DllImport("Comdlg32.dll",SetLastError=true,ThrowOnUnmappableChar=true, CharSet = CharSet.Auto)]
- public static extern bool GetOpenFileName([ In, Out ] OpenFileName ofn );
- public static bool GetOpenFileName1([ In, Out ] OpenFileName ofn )
- {
- return GetOpenFileName(ofn);
- }
- }


- using UnityEngine;
- using System.Collections;
- using System.Text;
- using System.Runtime.InteropServices;
- using System;
- public class Test : MonoBehaviour {
- public GameObject plane;
- void OnGUI()
- {
- if(GUI.Button(new Rect(0,0,100,35),"OpenDialog"))
- {
- OpenFileName ofn = new OpenFileName();
- ofn.structSize = Marshal.SizeOf(ofn);
- ofn.filter = "All Files\0*.*\0\0";
- 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(DllTest.GetOpenFileName( ofn ))
- {
- StartCoroutine(WaitLoad(ofn.file));//加载图片到panle
- Debug.Log( "Selected file with full path: {0}"+ofn.file );
- }
- }
- }
- IEnumerator WaitLoad(string fileName)
- {
- WWW wwwTexture=new WWW("file://"+fileName);
- Debug.Log(wwwTexture.url);
- yield return wwwTexture;
- plane.renderer.material.mainTexture=wwwTexture.texture;
- }
- }
参考知识:1、http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.inattribute%28v=vs.85%29
2、http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx
3、C#和win32类型对应
4、http://blog.csdn.net/wanfang323/article/details/6372995

unity3d各种OpenFileDialog操作的更多相关文章
- unity3d触屏操作对象运动
using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...
- Unity3D使用OpenFileDialog后崩溃
http://ask.unitymanual.com/question/24922 找了很久,原来是我的dll文件引错了,名字都一样,应该引用unity安装目录下的System.Window.Form
- [Unity3D]Unity3D游戏开发之Unity与Android交互调用研究
各位朋友,大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.在前一篇文章中,我们研究了Android平台上Unity3D的手势操作并在之前的基础 ...
- [转载]Unity3D游戏引擎最详尽基础教程
原文地址:Unity3D游戏引擎最详尽基础教程作者:ShangShang 我一直向所有想做游戏的朋友推荐Unity3D,为什么呢?首先是因为专业,Unity3D非常强大,用它创建一个类似MiniGor ...
- Unity3D游戏开发之Unity与Android交互调用研究
各位朋友,大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.在前一篇文章中,我们研究了Android平台上Unity3D的手势操作并在之前的基础 ...
- 解决wpf项目中无法添加OpenFileDialog 实例的问题
直接添加引用:using Microsoft.Win32; 或者放置鼠标于OpenFileDialog OpenFileDialog ofd = new OpenFileDialog(); 操作点击
- Unity3D连接sqlite数据库操作C#版
unity3d有自己对应的sqlite.dll分别需要三个文件 1.Mono.Data.Sqlite.dll 在unity安装文件“Unity\Editor\Data\MonoBleedingEdge ...
- Unity3D手势及重力加速度(神庙逃亡操作)
Unity实现神庙逃亡操作 现在特别火的跑酷游戏<神庙逃亡>是用Unity3D引擎开发的 游戏的操作:用手指拨动(划动)人物就转向,利用手机的重力感应进行人物左右调整. 今天用Unity来 ...
- 【淡墨Unity3D Shader计划】五 圣诞用品: Unity在Shader三种形式的控制&混合操作编译
本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/42060963 作者:毛星云(浅墨) ...
随机推荐
- API的理解和使用——字符串的命令
字符串的命令复习表 命令 作用 set setex setnx get mset mget incr decs incrby decrby incrbyfloa ...
- yum安装软件出错解决方法
造成yum下载安装时语法出错, 一般是由于python多个版本共存的原因.所以,只需将yum 设置文件固定python 版本,也就是python2 下面的操作能解决版本冲突问题. 1.sudo vim ...
- LeetCode:寻找旋转排序数组中的最小值【153】
LeetCode:寻找旋转排序数组中的最小值[153] 题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0 ...
- 5.1 《锋利的jQuery》jQuery对表单的操作
获取焦点和失去焦点改变样式 改变文本框/滚动条高度 复选框应用 下拉框应用 表单验证 tip1: 注意使用<label>的for标签,对应input的id.(for 属性规定 label ...
- hihocoder 微软编程之美2015 初赛 第一场 (树算法 + 暴力思想 + 搜索思想)
题目1 : 彩色的树 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个节点的树,节点编号为1, 2, …, n.树中有n - 1条边,任意两个节点间恰好有一条路 ...
- 如何识别真Microsoft服务与非Microsoft服务来定位病毒自己的服务
在我当网管的那段时间,发现有病毒入侵客户服务器,该病毒伪装自己的进程名,我们在服务中发现其也有伪装成系统服务的服务在运行,占用客户服务器的性能,使得CPU与内存的利用率达到90%以上,并持续时间长,甚 ...
- RQNOJ 117 最佳课题选择:多重背包
题目链接:https://www.rqnoj.cn/problem/117 题意: NaCN_JDavidQ要在下个月交给老师n篇论文,论文的内容可以从m个课题中选择. 由于课题数有限,NaCN_JD ...
- canvas刮刮卡
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- c语言字符串 数字转换函数大全
最近学数据结构老是做实验 常用到字符串和数字的转换 想找却发现网上的资料太散 所以搜集整理一下 方便以后再用 atof(将字符串转换成浮点型数) atoi(将字符串转换成整型数) atol(将字符串转 ...
- highChart数据动态更新
highChart官网上通过ajax加载数据的例子 上面是第一次生成图表的时候使用 我想动态更新,在已经生成的图表上动态更新 chartBS.series[0].setData(sugarListDa ...