调用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. Apache Virtual Include

    2.目录支持includes:     <Directory   />             Options   None             //不支持includes       ...

  2. red bottom shoes featured

    最近做了一个红底高根鞋的电商网站 Cheap Red Bottom Shoes Christian Louboutin Loafers Bestsellers Christian Louboutin ...

  3. SSD: Single Shot MultiBox Detector

    By Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexande ...

  4. 从一个标准 url 里取出文件的扩展名

    在php预定义函数中有一个叫做"pathinfo()"的函数,专门用于返回文件路径信息的. 那好,我们就来看一下它能为我们做些什么?       语法:pathinfo($url_ ...

  5. IS---InstallShield第二天

    在Setup.rul中,新增OnBegin函数 STRING str1,spath,szApplicationPath,szApplicationCmdLine,szCmdLine;function ...

  6. JSP内置对象(上)

    在JSP中为了简化页面的开发提供了一些内置的对象.这些对象不需要由JSP的编写者通过new关键字实例化,他们都由容器实现和管理,在所有的JSP页面中都可以使用内置对象. JSP中共有9大内置对象: o ...

  7. jQuery遍历对象、数组、集合实例

    1.jquery 遍历对象 复制代码代码如下:   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ...

  8. bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 1779  Solved: 823[Submit][Sta ...

  9. Angular 2 npm start 报错

    首先, index.html 和styles.css是和app目录平级的, 不要扔到里面去, 否则会404 确认配置文件齐全, 路径都正确之后 npm start What?! 照着快速起步也会弄错吗 ...

  10. 深入了解一下PYTHON中关于SOCKETSERVER的模块-B

    请求多个文件的原型. 这个是最草的情况,就是硬编码到内存中的字符串, 真实的应用还是会转到其它端口处理,或是读到硬盘上的文件吧. #!/usr/bin/env python from BaseHTTP ...