http://www.cnblogs.com/U-tansuo/archive/2012/07/10/GetOpenFileName.html

1 编辑模式(Editor)下:

  1. string path = EditorUtility.OpenFilePanel("Load png Textures of Directory", "", "");
  2. WWW ww=new WWW("file:///"+path);
  3. print(ww.url);
  4. yield return ww;
  5. gui.texture=ww.texture;

2.非编辑模式:

  1. OpenFileDialog ofd = new OpenFileDialog(); //new一个方法
  2.  ofd.InitialDirectory ="file://"+UnityEngine.Application.dataPath;  //定义打开的默认文件夹位置//定义打开的默认文件夹位置
  3. if(ofd.ShowDialog()==DialogResult.OK)
  4. {
  5. //显示打开文件的窗口
  6. Debug.Log( ofd.FileName);
  7. }
以上操作需要添加 System.Windows.Forms.dll,放在Plugins文件夹下,同时需要更改.net 2.0 Subset为.net2.0 

3、unity3d调用win32打开对话框

  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Runtime.InteropServices;
  5.  
  6. [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
  7.  
  8. public class OpenFileName
  9. {
  10. public int structSize = 0;
  11. public IntPtr dlgOwner = IntPtr.Zero;
  12. public IntPtr instance = IntPtr.Zero;
  13. public String filter = null;
  14. public String customFilter = null;
  15. public int maxCustFilter = 0;
  16. public int filterIndex = 0;
  17. public String file = null;
  18. public int maxFile = 0;
  19. public String fileTitle = null;
  20. public int maxFileTitle = 0;
  21. public String initialDir = null;
  22. public String title = null;
  23. public int flags = 0;
  24. public short fileOffset = 0;
  25. public short fileExtension = 0;
  26. public String defExt = null;
  27. public IntPtr custData = IntPtr.Zero;
  28. public IntPtr hook = IntPtr.Zero;
  29. public String templateName = null;
  30. public IntPtr reservedPtr = IntPtr.Zero;
  31. public int reservedInt = 0;
  32. public int flagsEx = 0;
  33. }
  34.  
  35. public class DllTest
  36. {
  37. [DllImport("Comdlg32.dll",SetLastError=true,ThrowOnUnmappableChar=true, CharSet = CharSet.Auto)]
  38. public static extern bool GetOpenFileName([ In, Out ] OpenFileName ofn );
  39. public static bool GetOpenFileName1([ In, Out ] OpenFileName ofn )
  40.  
  41. {
  42. return GetOpenFileName(ofn);
  43. }
  44. }
  1. using UnityEngine;
  2.  
  3. using System.Collections;
  4.  
  5. using System.Text;
  6.  
  7. using System.Runtime.InteropServices;
  8.  
  9. using System;
  10.  
  11. public class Test : MonoBehaviour {
  12.  
  13. public GameObject plane;
  14.  
  15. void OnGUI()
  16. {
  17. if(GUI.Button(new Rect(0,0,100,35),"OpenDialog"))
  18. {
  19. OpenFileName ofn = new OpenFileName();
  20.  
  21. ofn.structSize = Marshal.SizeOf(ofn);
  22.  
  23. ofn.filter = "All Files\0*.*\0\0";
  24.  
  25. ofn.file = new string(new char[256]);
  26.  
  27. ofn.maxFile = ofn.file.Length;
  28.  
  29. ofn.fileTitle = new string(new char[64]);
  30.  
  31. ofn.maxFileTitle = ofn.fileTitle.Length;
  32.  
  33. ofn.initialDir =UnityEngine.Application.dataPath;//默认路径
  34.  
  35. ofn.title = "Open Project";
  36.  
  37. ofn.defExt = "JPG";//显示文件的类型
  38. //注意 一下项目不一定要全选 但是0x00000008项不要缺少
  39. ofn.flags=0x00080000|0x00001000|0x00000800|0x00000200|0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
  40.  
  41. if(DllTest.GetOpenFileName( ofn ))
  42. {
  43.  
  44. StartCoroutine(WaitLoad(ofn.file));//加载图片到panle
  45.  
  46. Debug.Log( "Selected file with full path: {0}"+ofn.file );
  47.  
  48. }
  49.  
  50. }
  51.  
  52. }
  53.  
  54. IEnumerator WaitLoad(string fileName)
  55. {
  56. WWW wwwTexture=new WWW("file://"+fileName);
  57.  
  58. Debug.Log(wwwTexture.url);
  59.  
  60. yield return wwwTexture;
  61.  
  62. plane.renderer.material.mainTexture=wwwTexture.texture;
  63. }
  64. }

    参考知识:1http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.inattribute%28v=vs.85%29
    2http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx
    3C#和win32类型对应
    4http://blog.csdn.net/wanfang323/article/details/6372995

  1.  

unity3d各种OpenFileDialog操作的更多相关文章

  1. unity3d触屏操作对象运动

    using UnityEngine; using System.Collections; public class robot : MonoBehaviour { private GameObject ...

  2. Unity3D使用OpenFileDialog后崩溃

    http://ask.unitymanual.com/question/24922 找了很久,原来是我的dll文件引错了,名字都一样,应该引用unity安装目录下的System.Window.Form

  3. [Unity3D]Unity3D游戏开发之Unity与Android交互调用研究

    各位朋友,大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.在前一篇文章中,我们研究了Android平台上Unity3D的手势操作并在之前的基础 ...

  4. [转载]Unity3D游戏引擎最详尽基础教程

    原文地址:Unity3D游戏引擎最详尽基础教程作者:ShangShang 我一直向所有想做游戏的朋友推荐Unity3D,为什么呢?首先是因为专业,Unity3D非常强大,用它创建一个类似MiniGor ...

  5. Unity3D游戏开发之Unity与Android交互调用研究

    各位朋友,大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.在前一篇文章中,我们研究了Android平台上Unity3D的手势操作并在之前的基础 ...

  6. 解决wpf项目中无法添加OpenFileDialog 实例的问题

    直接添加引用:using Microsoft.Win32; 或者放置鼠标于OpenFileDialog OpenFileDialog ofd = new OpenFileDialog(); 操作点击

  7. Unity3D连接sqlite数据库操作C#版

    unity3d有自己对应的sqlite.dll分别需要三个文件 1.Mono.Data.Sqlite.dll 在unity安装文件“Unity\Editor\Data\MonoBleedingEdge ...

  8. Unity3D手势及重力加速度(神庙逃亡操作)

    Unity实现神庙逃亡操作 现在特别火的跑酷游戏<神庙逃亡>是用Unity3D引擎开发的 游戏的操作:用手指拨动(划动)人物就转向,利用手机的重力感应进行人物左右调整. 今天用Unity来 ...

  9. 【淡墨Unity3D Shader计划】五 圣诞用品: Unity在Shader三种形式的控制&amp;混合操作编译

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/42060963 作者:毛星云(浅墨)  ...

随机推荐

  1. API的理解和使用——字符串的命令

    字符串的命令复习表 命令 作用 set   setex   setnx   get   mset   mget   incr   decs   incrby   decrby   incrbyfloa ...

  2. yum安装软件出错解决方法

    造成yum下载安装时语法出错, 一般是由于python多个版本共存的原因.所以,只需将yum 设置文件固定python 版本,也就是python2 下面的操作能解决版本冲突问题. 1.sudo vim ...

  3. LeetCode:寻找旋转排序数组中的最小值【153】

    LeetCode:寻找旋转排序数组中的最小值[153] 题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0 ...

  4. 5.1 《锋利的jQuery》jQuery对表单的操作

    获取焦点和失去焦点改变样式 改变文本框/滚动条高度 复选框应用 下拉框应用 表单验证 tip1: 注意使用<label>的for标签,对应input的id.(for 属性规定 label ...

  5. hihocoder 微软编程之美2015 初赛 第一场 (树算法 + 暴力思想 + 搜索思想)

    题目1 : 彩色的树 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定一棵n个节点的树,节点编号为1, 2, …, n.树中有n - 1条边,任意两个节点间恰好有一条路 ...

  6. 如何识别真Microsoft服务与非Microsoft服务来定位病毒自己的服务

    在我当网管的那段时间,发现有病毒入侵客户服务器,该病毒伪装自己的进程名,我们在服务中发现其也有伪装成系统服务的服务在运行,占用客户服务器的性能,使得CPU与内存的利用率达到90%以上,并持续时间长,甚 ...

  7. RQNOJ 117 最佳课题选择:多重背包

    题目链接:https://www.rqnoj.cn/problem/117 题意: NaCN_JDavidQ要在下个月交给老师n篇论文,论文的内容可以从m个课题中选择. 由于课题数有限,NaCN_JD ...

  8. canvas刮刮卡

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  9. c语言字符串 数字转换函数大全

    最近学数据结构老是做实验 常用到字符串和数字的转换 想找却发现网上的资料太散 所以搜集整理一下 方便以后再用 atof(将字符串转换成浮点型数) atoi(将字符串转换成整型数) atol(将字符串转 ...

  10. highChart数据动态更新

    highChart官网上通过ajax加载数据的例子 上面是第一次生成图表的时候使用 我想动态更新,在已经生成的图表上动态更新 chartBS.series[0].setData(sugarListDa ...