unity3d各种OpenFileDialog操作
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);
}
以上操作需要添加 System.Windows.Forms.dll,放在Plugins文件夹下,同时需要更改.net 2.0 Subset为.net2.0
3、unity3d调用win32打开对话框
DllTestusing 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_NOCHANGEDIRif(DllTest.GetOpenFileName( ofn )){StartCoroutine(WaitLoad(ofn.file));//加载图片到panleDebug.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%292、http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx3、C#和win32类型对应4、http://blog.csdn.net/wanfang323/article/details/6372995
unity3d各种OpenFileDialog操作相关推荐
- Unity3D界面功能操作讲解
转载自 脱莫柔Unity3D学习之旅 本文链接地址: Unity3D 界面功能操作讲解 Hierarchy 层次视图: 显示当前打开场景文件(Scene)在场景视图(Scene View)中的显示或隐 ...
- Unity3D之日常操作-Aspose.Words.dll-U3D读写word_文本内容写入
记录日常操作. 网上没有找到相关内容,也没有搜索到Aspose提供的示例项目,可能是我没有仔细找的原因,无奈到Aspose官方找到脚本手册开始翻阅,最终的写出一下方法,还挺方便. dll: Aspos ...
- Unity3D基础2:新建模型
前文:https://blog.csdn.net/Jaihk662/article/details/86743037(Unity3D基础操作) 一.尺寸与方向 尺寸:默认的方块(Cube)长宽高都是1 ...
- 【Unity3D】协同程序
1 简介 1)协程概念 协同程序(Coroutine)简称协程,是伴随主线程一起运行的程序片段,是一个能够暂停执行的函数,用于解决程序并行问题.协程是 C# 中的概念,由于 Unity3D 的渲染操 ...
- [Unity3D]Unity3D游戏开发之Unity与Android交互调用研究
各位朋友,大家好,我是秦元培,欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.在前一篇文章中,我们研究了Android平台上Unity3D的手势操作并在之前的基础 ...
- bim 导入unity_一种基于BIM和Unity3d的3D物联网可视化人机交互方法与流程
本发明涉及到建筑工程领域和计算机软件领域,采用目前较为成熟的autodeskrevit平台进行3d模型的建立,unity3d平台进行交互设计,具体设计为一种基于unity3d和bim的3d物联网可视化 ...
- unity3d 加载iges_浅析几种三维模型格式导入Unity3D的途径
浅析几种三维模型格式导入Unity3D的途径 作者:未知 摘 要:Unity3D是现阶段应用最为广泛.功能最为强大的虚拟现实软件之一,但是引入的三维模型通常是由不同软件形成的.现阶段,市面上众多三维建 ...
- Unity技能工厂——字体替换工具功能的实现!
在平常我们做任何项目的时候,工具类对于我们来说是必不可少的组成部分,因为工具类可以解决实际问题或者是优化我们已经实现的功能. 当你在做项目的时候,搭建完场景后,前场景中你所创建的UI组件中的Text的 ...
- Unity 3D 菜单栏快捷键详解
nity 3D菜单栏及快捷键详解 File 菜单 Edit 菜单 Assets 菜单 GameObject 菜单 Component 菜单 Window 菜单 Help 菜单 其他快捷键 Unity ...
最新文章
- 无法执行 FunctionImport“entitys.xx”,因为未将它映射到存储函数。EF
- 我非要捅穿这 Neutron(三)架构分析与代码实现篇(基于 OpenStack Rocky)
- linux下创建用户及组
- 2021牛客多校6 - Gambling Monster(分治FWT优化期望dp)
- 如何使用Javascript 访问local部署的YAAS service
- A Story of One Country (Hard)(中途相遇法/启发式分裂)
- html5 服务器手机编程,html5实现服务器发送事件
- day4 终止条件continue和break和return的区别
- 基于JAVA+SpringBoot+Mybatis+MYSQL的药店进销存管理系统
- 一篇关于Dataset与泛型、自定义集合的讨论
- 【转】子弹短信内部技术分享:Redis
- 12 个开源后台管理系统
- 数字信号处理_巴特沃斯低通滤波器实验
- 【基础】华为设备RIP协议原理及配置全集
- java调用斑马证卡打印机制卡机ZXP Series 3C打印彩色工作证
- 【OpenCV】—图像对比度、亮度值调整
- (转)原生与胶水之争!CPU和GPU真假大论战
- springboot 批量生成条形码图片,并下载
- png转ico图标的方法
- Linux基础之vim
热门文章
- Java定时器(实现每月1号、每日、每15分钟自动执行任务)
- 电脑上使用计算机命令行,我的电脑运行命令_我的电脑什么运行命令
- 深入浅出:FFmpeg 音频解码与处理AVFrame全解析
- 5g的八大关键指标_5G关键性能指标解析
- wordrpress静态缓存插件WP Super Cache 使用教程
- 机器人操作系统ROS(3)工作空间
- html meta标签大全
- 豆豆趣事[2013年10月]
- Cache Maintenance-关于cache 清除(invalidate)和清理(clean)操作的基础知识
- SQL SERVER系统表