调用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的更多相关文章

  1. Unity引用System.Windows.Forms遇到的一些坑

    这两天在做一个unity打开文件选择框的功能.网上找到两种方法, 第一种是调用win32打开对话框,这个挺好,但是有个致命的问题,没办法多选!!!多选的话返回的是根目录的路径,文件名返回不了,找了半天 ...

  2. System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....

    #region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...

  3. System.Windows.Forms.ListView : Control

    #region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ...

  4. WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常

    WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...

  5. C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。

    一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...

  6. 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别

    原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...

  7. .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll

    这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...

  8. System.Windows.Forms.Help

    在开发过程中,基本都需要实现帮助功能,而一般帮助功能就是打开一个帮助文档,System.Windows.Forms提供了Help类用于打开帮助文档,挺方便的. Help类提供的方法如下:   Name ...

  9. System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)

    .NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...

随机推荐

  1. Android学习4—短信发送器的实现

    界面预览: 由图中可以看出,此APP需要的组件有:两个TextView,一个用于显示手机号码的标题,另一个用于显示短信内容的标题.                                    ...

  2. 《玩转shutdown》-linux命令五分钟系列之十三

    1 我想立即关机! $shutdown -h now 2 我想立即重启 $shutdown -r now 3 我想在23:30分准时关机 $shutdown -h 23:30 4 我想在15分钟后关机 ...

  3. git的使用方法总结

    一.创建版本库 $ cd D:   进入d盘 $ cd wamp/www 进入相应目录 $ mkdir test 创建目录 $ git init 把目录变为git可以管理的仓库 二.提交文件到版本库 ...

  4. Python核心编程2第三章课后练习

    1. 标识符.为什么Python 中不需要变量名和变量类型声明? Python中的变量不需要声明,变量的赋值操作既是变量声明和定义的过程.每个变量在内存中创建,都包括变量的标识,名称和数据这些信息.每 ...

  5. iOS:Swift界面实例1, 简单界面

    Apple推出了基于Objective-C的新语言Swift. 通过实例, 我们可以很好的感受这门新语言 注意事项: 在XCode6_Beta中, 如果有中文, IDE的自动补全功能就会失效, 所以开 ...

  6. 当xcode里点运行出现treating unicode character as whites

    可能是由于粘贴网页上的代码的时候两行之间的回车引起的,两行之间重新输入回车就行......删掉重新写一遍就ok了 引入网页上的回车时  可能  网页对其格式做了处理,所以Xcode  不认识了

  7. bzoj 1034: [ZJOI2008]泡泡堂BNB 貪心

    1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1398  Solved: 727[Submit][Sta ...

  8. 使用lombok

    Lombok是一种JavaArchive(JAR)文件,可用来消除Java代码的冗长.通过在开发环境中实现Lombok,开发人 员可以节省构建诸如hashCode()和equals()这样的方法以及以 ...

  9. TEdit,TMemo背景透明

    The component below works perfectly, except for the following problem: 1) Saves the component below ...

  10. Android MAVEN项目标准目录结构

    1.标准目录结构: src -main      –bin 脚本库      –java java源代码文件      –resources 资源库,会自动复制到classes目录里      –fi ...