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 ...
随机推荐
- ecshop---京东手机模板js的eval产生冲突的解决方法。
今天弄ecshop手机模板的时候,发现首页的广告图出不来,js报错
- gridview列前加复选框需要注意的一点
前言 获取gridview每一列前面的复选框,然后获取选中的这一行的id.aspx页面,我不喜欢用这个,有的公司用自己封装的,基本上都是用封装的,这是我知道的.也有用Repeater的.可能是因为gr ...
- easy UI demo 含数据库加载示例
easyUI 部分代码在Googlecode 托管时而被抢此文件包含了所有官方demo,作为备份 下载地址http://pan.baidu.com/s/1pJ9hS5H
- 查看yum包安装地址
首先找到包含版本号在内的全包名 rpm -qa|grep t_dp_apsara_exstoret_dp_apsara_exstore-1.0.5-56 然后就可以查询到了 rpm -ql t_dp_ ...
- WebApi学习总结系列第三篇(Http)此篇持续更新...
越了解Http对WebApi开发就越有帮助,因为WebApi就是建立在Http基础之上的. 一.Http: 通过 <ASP.NET Web API 2 框架揭秘>一书中 了解到 什么叫We ...
- 从UI Automation看Windows平台自动化测试原理
前言 楼主在2013年初研究Android自动化测试的时候,就分享了几篇文章 Android ViewTree and DecorView Android自动化追本溯源系列(1): 获取页面元素 An ...
- bzoj 3624: [Apio2008]免费道路 生成树的构造
3624: [Apio2008]免费道路 Time Limit: 2 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 111 Solved: 4 ...
- Matlab读取cifar10 train_quick.sh输出txt中信息
感谢 网友 Vagrant的提醒.之前 一直就看个最后的accuracy.这个应该并不靠谱.最好把说有的信息都看一下.而一个一个看.根本记不住.只能把数据读取在图片中显示一下,才比较直观. 本文就是读 ...
- CPU再烂,俺也支持虚拟化呀,再附送64位WINDOWS的IIS上配置支持PHP的注意事项
原来要对IIS进行降权,让他可以支持32位程式 cscript.exe %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/App ...
- Principles of Motion Sensing
Principlesof Motion Sensing Various sensors capable of detecting motionin free space have been comme ...