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 作者:毛星云(浅墨) ...
随机推荐
- ubuntu中设置wireshark抓包
安装wireshark软件后,打开进行抓包的时候会提示权限不足.原因是普通用户没有执行权限,也打不开网络端口捕捉,因为dumpcap需要root权限. 产生这种问题的原因:比如:wireshark在进 ...
- win7计划任务定时执行PHP脚本设置图解
做php开发的朋友有时候会希望自己的电脑能每天定时的运行一下某个脚本,但定时执行php脚本这种概念似乎多半是在linux中才提到,下面这篇文章主要和大家分享一下在win7下如何设置计划任务,以实现定时 ...
- 常用BAPI list
2017-03-25 MD 主数据 1.创建物料主数据 CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' 2.创建供应商 CALL METHOD VMD_EI_API=&g ...
- (转)CentOS 5.5 64bit 编译安装Adobe FlashMediaServer 3.5
http://download.macromedia.com/pub/flashmediaserver/updates/4_0_2/Linux_32bit/FlashMediaServer4.tar. ...
- java多线程---基础
一, java多线程----线程与进程 进程: 程序(任务)的执行过程,拥有资源(共享内存,共享资源)和线程(一个或者多个,至少一个). 例如:打开任务管理器,qq,chrome,都属于进程. 线程 ...
- 可视化工具与pymongo
可视化工具 链接:https://robomongo.org/ pymongo 官网:http://api.mongodb.com/python/current/tutorial.html from ...
- A. Drazil and Date
这是codeforces#292 div2 的一道题,因为本人比较水,目前只能做div2了.问题简化版就是: 从 (0,0) 走到 (a, b) ,s 步能不能走完.每次能向上下左右走,且只能走一步. ...
- 9.2 NOIP提高组试题精解(2)
9-18 fruit.c #include <stdio.h> #define MAXN 10000 int Queue1[MAXN], Queue2[MAXN]; void Insert ...
- leetcode 66. Plus One(高精度加法)
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- C++中两个类相互包含引用问题
在构造自己的类时,有可能会碰到两个类之间的相互引用问题,例如:定义了类A类B,A中使用了B定义的类型,B中也使用了A定义的类型 class A { int i; B b; } class B { in ...