简体   繁体   English

XNA的内容项目中添加的引用的文件路径是什么?

[英]What is the file path for references added in Content project in XNA?

This problem is somewhat similar to this. 这个问题与类似

In my case, I have a text file. 就我而言,我有一个文本文件。 And since there is no content importer that works for text file, I have to write my own functions using stream readers. 而且,由于没有适用于文本文件的内容导入器,因此我必须使用流读取器编写自己的函数。 What I am trying to accomplish is to read from the text file, and set a few values accordingly into the options screen. 我要完成的工作是从文本文件中读取,并在选项屏幕中相应地设置一些值。 I have added all necessary references, but using "../options.txt" as filepath does not work. 我已经添加了所有必需的引用,但是使用“ ../options.txt”作为文件路径不起作用。 Quite possibly the filepath is resolved to something else than Content folder. 文件路径很可能解析为Content文件夹以外的其他文件。 How do I then proceed with it? 我该如何进行呢?

Also, I am getting errors saying "attempt to access method (System.IO....ctor) failed". 另外,我收到错误消息:“尝试访问方法(System.IO .... ctor)失败”。 Is it that I am missing to add some other reference? 是否缺少添加其他参考?

Does this have to work on the xBox 360? 这必须在xBox 360上工作吗? If so it's not possible to just use the filesystem like you can in Windows, you'll need to use a storage device. 如果这样,不可能像Windows中那样仅使用文件系统,则需要使用存储设备。 To be honest I would just use this method anyway so if you decide to take your game on to WP7 or 360 it'll just work. 老实说,我还是会使用这种方法,因此,如果您决定将游戏安装到WP7或360上,它将可以正常工作。

There is a nice demo game that loads and saves data on this Microsoft page as well as a description of what it's doing 有一个很好的演示游戏,可以在 Microsoft页面上加载和保存数据,并对其工作方式进行描述

This is taken from the demo, it shows how to open a storage container and serialize some config data to it, the load operation is just as simple. 这是从演示中获取的,它显示了如何打开存储容器并序列化一些配置数据,加载操作也很简单。

// Create the data to save.
SaveGameData data = new SaveGameData();
data.PlayerName = "Hiro";
data.AvatarPosition = new Vector2(360, 360);
data.Level = 11;
data.Score = 4200;

// Open a storage container.
IAsyncResult result =
    device.BeginOpenContainer("StorageDemo", null, null);

// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();

StorageContainer container = device.EndOpenContainer(result);

// Close the wait handle.
result.AsyncWaitHandle.Close();

string filename = "savegame.sav";

// Check to see whether the save exists.
if (container.FileExists(filename))
    // Delete it so that we can create one fresh.
    container.DeleteFile(filename);

// Create the file.
Stream stream = container.CreateFile(filename);

// Convert the object to XML data and put it in the stream.
XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
serializer.Serialize(stream, data);

// Close the file.
stream.Close();

// Dispose the container, to commit changes.
container.Dispose();

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM