GJM : Unity调用系统窗口选择本地文件
- 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 WindowDll
- {
- [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.Runtime.InteropServices;
- using System.Reflection;
- public class CameraTest : MonoBehaviour
- {
- public WebCamTexture cameraTexture;
- public string cameraName = "";
- private bool isPlay = false;
- // Use this for initialization
- void Start()
- {
- //StartCoroutine(OpenCamera());
- }
- // Update is called once per frame
- void Update()
- {
- }
- /// <summary>
- /// 获取权限打开摄像头
- /// </summary>
- /// <returns></returns>
- IEnumerator OpenCamera()
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- cameraName = devices[0].name;
- cameraTexture = new WebCamTexture(cameraName, 320, 240, 15);
- cameraTexture.Play();
- isPlay = true;
- }
- }
- void OnGUI()
- {
- if (isPlay)
- {
- GUI.DrawTexture(new Rect(0, 0, 320, 240), cameraTexture, ScaleMode.ScaleAndCrop);
- }
- 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;
- string path = Application.streamingAssetsPath;
- path = path.Replace('/','\\');
- //默认路径
- ofn.InitialDirectory = path;
- //ofn.InitialDirectory = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets";
- 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 (WindowDll.GetOpenFileName(ofn))
- {
- Debug.Log("Selected file with full path: {0}" + ofn.file);
- }
- }
- }
- }
文件的类型设置
- ofn.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png";

GJM : Unity调用系统窗口选择本地文件的更多相关文章
- (转)在WinForm中选择本地文件
相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...
- 【.Net】在WinForm中选择本地文件
相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...
- 选择本地文件上传控件 input标签
当要通过控件来选择本地文件上传的时候的一种方式 <input type="file" id="input-file"/> 注意 type类型一定要是 ...
- JS调用activeX实现浏览本地文件夹功能 wekit内核只需要<input type="file" id="files" name="files[]" webkitdirectory/>即可,IE内核比较麻烦
研究了一天,js访问本地文件本身是不可能的,只能借助于插件.植入正题,IE仅支持ActiveX插件. function openDialog() { try { var Message = " ...
- Google调用explorer.exe打开本地文件
给IE浏览器地址栏输个本地文件路径,会自动用explorer.exe打开,这个挺好的,但是IE对jQuery稍微高点的版本不怎么待见,只好自己给Google折腾一个调用explorer的功能----- ...
- Android调用相机拍照并返回路径和调用系统图库选择图片
调用系统图库: Intent intent = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI); ...
- Unity中调用Windows窗口选择文件
1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...
- iOS 调用拍照、选择本地相册、上传功能---未完善。
1.新建viewController 拖入一个Button,添加点击事件,使用代理方法 <UIActionSheetDelegate,UIImagePickerControllerDelegat ...
- Android WebView选择本地文件上传
This sample demonstrate android webview choose file to upload. I just implement the client code ,the ...
随机推荐
- C#设计模式-桥接模式
这里以电视遥控器的一个例子来引出桥接模式解决的问题,首先,我们每个牌子的电视机都有一个遥控器,此时我们能想到的一个设计是——把遥控器做为一个抽象类,抽象类中提供遥控器的所有实现,其他具体电视品牌的遥控 ...
- Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>
在用maven命令启动storm时候,命令行是:mvn exec:java -Dexec.mainClass="TopologyMain" -Dexec.args="sr ...
- IDEA设置代码大小以及菜单栏大小
IntelliJ IDEA设置菜单栏大小的方法:File --Settings --Appearance & Behavior -- Appearance ,右边Override defaul ...
- 设置 iOS 应用的图标和名称
Xcode 8.1 设置 iOS 应用的图标和名称的方法: 设置应用图标: 1.在 Resources 中添加图片: 2.在 Icon file 的属性值填写图标文件的名称. 设置应用名: 1.修改 ...
- 深入理解JSON对象
× 目录 [1]语法规则 [2]stringify [3]parse[4]eval 前面的话 json(javascript object notation)全称是javascript对象表示法,它是 ...
- Android之TabActivity的使用
TabActivity实现多页显示效果 由于手机屏幕有限,所以我们要尽量充分利用屏幕资源.在我们的应用程序中通常有多个Activity,而且会经常切换显示,这样我们就可以用TabActivity来显示 ...
- 两张图总结 Neutron 架构 - 每天5分钟玩转 OpenStack(74)
前面我们详细讨论了 Neutron 架构,包括 Neutron Server,Core 和 Service Agent.现在用两张图做个总结.先看第一张: 与 OpenStack 其他服务一样,Neu ...
- Cinder 组件详解 - 每天5分钟玩转 OpenStack(47)
本节我们将详细讲解 Cinder 的各个子服务. cinder-api cinder-api 是整个 Cinder 组件的门户,所有 cinder 的请求都首先由 nova-api 处理.cinder ...
- JQuery EasyUI datagrid 复杂表头处理
下面是我项目中和网上收集的EasyUI的表头处理的,合适的拿去用吧. 例子1: $('#day_health').datagrid({ url: "sqb_b ...
- 【记录】JS 获取 URL 中文参数编码
比如 URL:http://www.xxxx.com/中文参数 这个在 js 获取"中文参数"的时候会出现乱码. 解决方法:decodeURIComponent(获取的中文参数);