Unity 读取、写入自定义路径文件,调用System.Windows.Forms
调用System.Windows.Forms DLL
首先在Unity新建Plugins文件夹添加System.Windows.Forms.dll
然后代码中添加引用
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO; public class FileMenu : MonoBehaviour
{
#region Public
public UIButton BtnNew;
public UIButton BtnOpen;
public UIButton BtnSave;
public UIButton BtnSaveAs;
public UIButton BtnClose;
#endregion #region private SaveFileDialog saveLog;
StreamReader sr;
StreamWriter sw;
string strSendTxt;
UIPaneAuto uiPanelAuto;//一个显示文本和输入文本的文本框所在的类
#endregion void Awake()
{
uiPanelAuto = transform.GetComponent<UIPaneAuto>();
BtnNew = GameObject.Find("UI Root/Camera/PanelTop/LstBtn/BtnNew").GetComponent<UIButton>();
BtnOpen = GameObject.Find("UI Root/Camera/PanelTop/LstBtn/BtnOpen").GetComponent<UIButton>();
BtnSave = GameObject.Find("UI Root/Camera/PanelTop/LstBtn/BtnSave").GetComponent<UIButton>();
BtnSaveAs = GameObject.Find("UI Root/Camera/PanelTop/LstBtn/BtnSaveAs").GetComponent<UIButton>();
BtnClose = GameObject.Find("UI Root/Camera/PanelTop/LstBtn/BtnClose").GetComponent<UIButton>();
EventDelegate.Add(BtnNew.onClick, fnNew);
EventDelegate.Add(BtnOpen.onClick, fnOpen);
EventDelegate.Add(BtnSave.onClick, fnSave);
EventDelegate.Add(BtnSaveAs.onClick, fnSave);
EventDelegate.Add(BtnClose.onClick, fnClose);
} void fnNew()
{
Debug.Log("New");
uiPanelAuto.fnSetInputTxt("");
} void fnOpen()
{
Debug.Log("Open");
try
{
OpenFileDialog opLog = new OpenFileDialog();
opLog.InitialDirectory = UnityEngine.Application.dataPath;
opLog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
DialogResult result = opLog.ShowDialog();
if (result == DialogResult.OK)
{
string path = opLog.FileName;
Debug.Log(path);
sr = File.OpenText(path); string line;
BetterList<string> lst = new BetterList<string>();
strSendTxt = "";
while ((line = sr.ReadLine()) != null)
{
lst.Add(line);
}
foreach (string s in lst)
{
strSendTxt += s+"\n";
}
uiPanelAuto.fnSetInputTxt(strSendTxt);
sr.Close();
sr.Dispose();
}
}
catch(Exception e)
{
Debug.Log("打开错误:"+e.Message);
return;
}
} void fnSave()
{
Debug.Log("Save");
SaveFileDialog saveLog = new SaveFileDialog();
saveLog.InitialDirectory = UnityEngine.Application.dataPath;
saveLog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
DialogResult result = saveLog.ShowDialog();
if (result == DialogResult.OK)
{
Debug.Log(saveLog.FileName);
FileInfo f = new FileInfo(saveLog.FileName);
if (f.Exists)
{
f.Delete();//如果存在同名文本,就删除它重新建一个
f = new FileInfo(saveLog.FileName);
sw = f.AppendText();
//将LstIptChect中的数据添加到Txt中
foreach (string s in uiPanelAuto.lstIptCheck)
{
Debug.Log(s);
sw.WriteLine(s);
}
sw.Close();
sw.Dispose();
}
else
{
sw = f.AppendText();
foreach (string s in uiPanelAuto.lstIptCheck)
{
Debug.Log(s);
if(s!="")
sw.WriteLine(s);
}
sw.Close();
sw.Dispose();
}
}
}
} void fnClose()
{
Application.Quit();
}
}
</pre><pre class="csharp" name="code"></pre><pre class="csharp" name="code">
Unity 读取、写入自定义路径文件,调用System.Windows.Forms的更多相关文章
- Unity引用System.Windows.Forms遇到的一些坑
这两天在做一个unity打开文件选择框的功能.网上找到两种方法, 第一种是调用win32打开对话框,这个挺好,但是有个致命的问题,没办法多选!!!多选的话返回的是根目录的路径,文件名返回不了,找了半天 ...
- System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- System.Windows.Forms.ListView : Control
#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...
- WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常
WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...
- C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。
一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...
- .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll
这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...
- System.Windows.Forms.Help
在开发过程中,基本都需要实现帮助功能,而一般帮助功能就是打开一个帮助文档,System.Windows.Forms提供了Help类用于打开帮助文档,挺方便的. Help类提供的方法如下: Name ...
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
随机推荐
- Linux 特殊权限位
特殊权限位 LINUX 基本权限有9位但是还有三位特殊权限. suid s(有x权限) S(没有x权限) 4 在用户权限的第三位 sgid s(有x权限) S(没有x权限) 2 在用户组权限的第三位 ...
- node初步二 小爬虫
小爬拉勾网 获取想要的信息: 一.分三步 1 获得数据 2 处理数据 3展示数据 二 .代码 :创建文件reptile.js;写入 var http=require('http'); var chee ...
- 百度劫持js代码
js代码为: var myDate=new Date(); //返回一日期对象,可以调用getDate(),内容为当前时间,这句是新建一个对象d建好对象后d就有函数date()中的所有特性 var h ...
- JavaScript学习心得(二)
一选择DOCTYPE DOCTYPE是一种标准通用标记语言的文档类型声明,目的是告诉标准通用标记语言解析器使用什么样的文档类型定义(DTD)来解析文档. 网页从DOCTYPE开始,即<!DOCT ...
- InstallShield自定义图片资源
DialogSetInfo ( nInfoType, szInfoString, nParameter ); nInfoType: DLG_INFO_ALTIMAGE-Specifies an a ...
- InstallShield:自己备份
LIST listData;//声明listData listData = ListCreate(STRINGLIST);//创建一个空的实际字符串或数字列表. //参数都是在上个界面中赋值,然后在下 ...
- Django如何设置proxy
设置porxy的原因 一般情况下我们代理设置是针对与浏览器而言,通常只需在浏览器设置中进行配置,但它只针对浏览器有效,对我们自己编写的程序并任何效果,这时就需要我们在软件编码中加入代理设置. --- ...
- sourceInsight的技巧
在用sourceInsight看代码...在这里积累技巧,慢慢积累吧 1.如何高亮显示所有要搜的东西,例如 1.aaaaaa 2. bbbbbbbbaaaaaaa 3. ccccccc 4. aaaa ...
- Asp.net MVC中三大描述对象之ActionDescriptor 以及继承类ReflectedControllerDescriptor
ActionDescriptor抽象类中几个基本的属性: ControllerName:被描述的Controller名称,去除后缀Controller的名称.例如:HomeController则为Ho ...
- JSP中使用的模式——JSP+Servlet+JavaBean
上一篇博文写到模式一:JSP+JavaBean 链接地址:http://wxmimperio.coding.io/?p=155 JSP中两种模式的总结 链接地址:http://wxmimperio.c ...