简体   繁体   English

命名空间“System.Windows”中不存在类型或命名空间名称“Forms”修复

[英]The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' FIX

Can someone please help me with this, am trying to use OpenFileDialog class from System.Windows.Forms to open a file dialog and read the selected file.有人可以帮我解决这个问题吗,我正在尝试使用 System.Windows.Forms 中的 OpenFileDialog class 打开文件对话框并读取所选文件。 Then, this error showed up.然后,这个错误出现了。 I've referenced it but still the same, below is the code.我已经引用了它但仍然相同,下面是代码。

`using UnityEngine using UnityEngine.UI using System.Windows.Forms; `使用 UnityEngine 使用 UnityEngine.UI 使用 System.Windows.Forms;

public class OpenFileButtonScript: MonoBehaviour { public TextFieldScript textFieldScript;公共 class OpenFileButtonScript: MonoBehaviour { 公共 TextFieldScript textFieldScript;

public void OpenFile()
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
    openFileDialog.FilterIndex = 1;
    openFileDialog.Multiselect = false;

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
        string filePath = openFileDialog.FileName;
        string text = System.IO.File.ReadAllText(filePath);
        textFieldScript.inputField.text = text;
    }
}

}` }`

It may look like you have access to all of the native Window system libraries, but it just looks like it.看起来您可以访问所有本机 Window 系统库,但它看起来就是这样。 In actuality, a lot of the time you're simply given stubs, or shims, that look like the full Window libraries, because there's a certain element that Unity wants to use from those namespaces.实际上,很多时候你只是简单地得到了存根或垫片,它们看起来像完整的 Window 库,因为 Unity 想要使用这些命名空间中的某个元素。 If you think about it, the code you present above, what do you think it should do on Android or Nintendo devices?如果您考虑一下,您上面显示的代码,您认为它应该在 Android 或任天堂设备上做什么? The simple answer is, it simply won't work.简单的答案是,它根本行不通。

Generally in cases like this, you have to gain access to the native operating system, and perform those calls directly.通常在这种情况下,您必须获得对本机操作系统的访问权限,并直接执行这些调用。 For example, there is a file browser asset on the Asset Store, that does this for you.例如,Asset Store 上有一个文件浏览器资产,可以为您执行此操作。 It's not free, because the process isn't trivial.它不是免费的,因为这个过程并不简单。

Depending on how much effort you want to put in, you CAN read files from the local file stores (to varying degrees based on platform).根据您想付出的努力,您可以从本地文件存储中读取文件(根据平台的不同程度)。 It's possible to read the list of files in a location, and use either uGUI or UIToolkit to create your own File Open Dialogue box.可以读取某个位置的文件列表,并使用 uGUI 或 UIToolkit 创建您自己的文件打开对话框。 Again, this isn't a trivial task either.同样,这也不是一项微不足道的任务。 So you have to be sure that you'd want to go down that path.所以你必须确定你想要 go 沿着那条路走下去。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unity 中的命名空间“UnityEngine”中不存在类型或命名空间名称“Windows” - The type or namespace name `Windows' does not exist in the namespace `UnityEngine' in Unity 类型或名称空间名称“ Xml”在名称空间“ System.Security.Cryptography”中不存在 - The type or namespace name `Xml' does not exist in the namespace `System.Security.Cryptography' 命名空间“System.IO”中不存在类型或命名空间名称“Ports”(您是否缺少程序集引用?) - The type or namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?) 命名空间“UnityEngine”中不存在 Unity 类型或命名空间名称“InputSystem” - Unity type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' 命名空间“UnityEditor.Experimental”中不存在类型或命名空间名称“SceneManagement” - The type or namespace name `SceneManagement' does not exist in the namespace `UnityEditor.Experimental' Unity 类型或命名空间名称“空间跟踪”在命名空间“UnityEngine”中不存在 - Unity type or namespace name 'Spatial Tracking' does not exist in the namespace 'UnityEngine' 命名空间“UnityEditor”中不存在类型或命名空间名称“Animations” - The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor' 命名空间“UnityEngine.Experimental”中不存在类型或命名空间名称“Input” - The type or namespace name 'Input' does not exist in the namespace 'UnityEngine.Experimental' 类型或名称空间名称“ Kinect”在名称空间“ Microsoft”中不存在 - The type or namespace name `Kinect' does not exist in the namespace `Microsoft' 命名空间“UnityEngine.Rendering”中不存在类型或命名空间名称“PostProcessing” - The type or namespace name `PostProcessing' does not exist in the namespace `UnityEngine.Rendering'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM