如何获得ContentManager的全根目录在XNA 4.0 [英] How to get the full root directory of a ContentManager in XNA 4.0

查看:200
本文介绍了如何获得ContentManager的全根目录在XNA 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有人在这里知道如何找到完整路径(从驱动器盘符起)一ContentManager实例。使用这个我可以创建具有..\右边的数字的字符串追加到的文件路径,当我要加载的计算机上从其他地方的文件(例如,从注册表项)。

I was wondering if anyone here knows how to find the complete path (from the drive letter onwards) of a ContentManager instance. using this I could create a string with the right number of "..\" to append to the file path when I want to load a file from anywhere else on the computer (eg. from a registry key).

所以基本上我问,如果有一种方式。

So basically I'm asking if there is a way.

推荐答案

您可以只想用 System.GetFolderPath ,提供的这些位置,最有可能的程序文件。从那里,你可以浏览到您的应用程序的安装目录。你也可以使用.Load(\MyFolder\blah),将从默认磁盘加载。(如C:\MyFolder\blah.xnb或其他)

You may just want to use System.GetFolderPath with one of these locations, most likely Program Files. From there, you can navigate to your application's installation directory. You could also use .Load("\MyFolder\blah") which will load from the default disk (e.g. C:\MyFolder\blah.xnb or whatever).

如果你希望你的.exe文件...

If you want the path of your .exe file...

using System.IO;
using System.Windows.Forms;

//blah blah
string GetAppDir()
{
    return Path.GetDirectoryName(Application.ExecutablePath);
}

这篇关于如何获得ContentManager的全根目录在XNA 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆