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 作者:毛星云(浅墨) ...
随机推荐
- 第一个Vert.x程序
Jar依赖 <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-core</ar ...
- 同源策略 , CORS
一 . 同源策略 同源策略( Same origin policy ) 是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响,可以说Web是构建在同源 ...
- PAT天梯赛 L2-020. 功夫传人 【DFS】
题目链接 https://www.patest.cn/contests/gplt/L2-020 思路 从师父开始 一层一层往下搜 然后 搜到 得道者 就更新答案 AC代码 #include <c ...
- appium-andriod自动化实现注意项
注意项: 1.appium需要全局安装,否则run test case 报错“appium not installed” 2.启动appium命令 node /Applications/Appium. ...
- 最受欢迎的牛 usaco
题面网上到处都是: 主要来谈谈怎么做,首先利用tarjan求强连通分量缩点,缩点后找到出度为0的点,若不止一个,则输出0,否则输出这个点包含的缩点前的点的个数: 为什么这么做,是由这道题的问法决定的, ...
- Contiki 2.7 Makefile 文件(五)
4.第四部分 (1) oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}} 自定义函数,$(1)表示调用oname这个函数的第一个参数,patsub ...
- python- python内置模块 面向对象
1.configparser模块 configparser用于处理特定格式的文件,其本质上是利用open来操作文件 # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2 ...
- 【Codeforces】Gym 101156G Non-Attacking Queens 打表
题意 求$n\times n$的棋盘上放$3$个皇后使得互相不攻击的方案数 拓展是$m\times n$棋盘上放$k$皇后,暴力打表找到了公式 OEIS 代码 import java.math.Big ...
- hdu-5826 physics(数学)
题目链接: physics Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) P ...
- 小心transform
张老师总结的,感谢! <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...