Unity調(diào)用Window窗口
本文提供全流程,中文翻譯。
Chinar 堅(jiān)持將簡(jiǎn)單的生活方式,帶給世人!
(擁有更好的閱讀體驗(yàn) —— 高分辨率用戶請(qǐng)根據(jù)需求調(diào)整網(wǎng)頁縮放比例) |
Chinar —— 心分享、心創(chuàng)新!
助力快速完成 Unity調(diào)用 Window api 執(zhí)行保存/打開操作
為新手節(jié)省寶貴的時(shí)間,避免采坑! |
Chinar 教程效果:
- 1
- File Controller —— 文件控制腳本
- 2
- 支持
- May Be —— 搞開發(fā),總有一天要做的事!
全文高清圖片,點(diǎn)擊即可放大觀看 (很多人竟然不知道)
1
File Controller —— 文件控制腳本
晚會(huì)兒修改
用來控制打開/保存項(xiàng)目文件
將兩個(gè)腳本放到項(xiàng)目中,分別綁定2個(gè)按鈕 打開/保存
ChinarFileController 腳本需要掛載到空物體上
即可正常調(diào)用
具體需求,需要自己來定,保存到某個(gè)路徑下
using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class ChinarFileController : MonoBehaviour
{
public void OpenProject(){OpenFileDlg pth =
new OpenFileDlg();pth.structSize = Marshal.SizeOf(pth);pth.filter =
"All files (*.*)|*.*";pth.file =
new string(
new char[
256]);pth.maxFile = pth.file.Length;pth.fileTitle =
new string(
new char[
64]);pth.maxFileTitle = pth.fileTitle.Length;pth.initialDir = Application.dataPath.Replace(
"/",
"\\") +
"\\Resources"; pth.title =
"打開項(xiàng)目";pth.defExt =
"dat";pth.flags =
0x00080000 |
0x00001000 |
0x00000800 |
0x00000200 |
0x00000008;
if (OpenFileDialog.GetOpenFileName(pth)){
string filepath = pth.file; Debug.Log(filepath);}}
public void SaveProject(){SaveFileDlg pth =
new SaveFileDlg();pth.structSize = Marshal.SizeOf(pth);pth.filter =
"All files (*.*)|*.*";pth.file =
new string(
new char[
256]);pth.maxFile = pth.file.Length;pth.fileTitle =
new string(
new char[
64]);pth.maxFileTitle = pth.fileTitle.Length;pth.initialDir = Application.dataPath; pth.title =
"保存項(xiàng)目";pth.defExt =
"dat";pth.flags =
0x00080000 |
0x00001000 |
0x00000800 |
0x00000200 |
0x00000008;
if (SaveFileDialog.GetSaveFileName(pth)){
string filepath = pth.file; Debug.Log(filepath);}}
}
2
FileDlog —— 文件日志
無需掛載到空物體上
using System.Runtime.InteropServices;
using System;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class ChinarFileDlog
{
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;
}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenFileDlg : ChinarFileDlog
{
}
public class OpenFileDialog
{[DllImport(
"Comdlg32.dll", SetLastError =
true, ThrowOnUnmappableChar =
true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenFileDlg ofd);
}
public class SaveFileDialog
{[DllImport(
"Comdlg32.dll", SetLastError =
true, ThrowOnUnmappableChar =
true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([In, Out] SaveFileDlg ofd);
}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class SaveFileDlg : ChinarFileDlog
{
}
運(yùn)行效果:
支持
May Be —— 搞開發(fā),總有一天要做的事!
擁有自己的服務(wù)器,無需再找攻略!
Chinar 提供一站式教程,閉眼式創(chuàng)建!
為新手節(jié)省寶貴時(shí)間,避免采坑! |
先點(diǎn)擊領(lǐng)取 —— 阿里全產(chǎn)品優(yōu)惠券 (享受最低優(yōu)惠)
1 —— 云服務(wù)器超全購買流程 (新手必備!)
2 —— 阿里ECS云服務(wù)器自定義配置 - 購買教程(新手必備!)
3—— Windows 服務(wù)器配置、運(yùn)行、建站一條龍 !
4 —— Linux 服務(wù)器配置、運(yùn)行、建站一條龍 !
技術(shù)交流群:806091680 ! Chinar 歡迎你的加入
END
本博客為非營利性個(gè)人原創(chuàng),除部分有明確署名的作品外,所刊登的所有作品的著作權(quán)均為本人所擁有,本人保留所有法定權(quán)利。違者必究
對(duì)于需要復(fù)制、轉(zhuǎn)載、鏈接和傳播博客文章或內(nèi)容的,請(qǐng)及時(shí)和本博主進(jìn)行聯(lián)系,留言,Email: ichinar@icloud.com
對(duì)于經(jīng)本博主明確授權(quán)和許可使用文章及內(nèi)容的,使用時(shí)請(qǐng)注明文章或內(nèi)容出處并注明網(wǎng)址>
總結(jié)
以上是生活随笔為你收集整理的unity 实现调用Windows窗口/对话框交互的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。