Detecting run-time game platform in XNA
Question
I'm working on a C# XNA project that requires me to display information based on the platform the game is on.
Is there a way to detect the platform (XBox, Windows, Zune) during run-time?
Solution
Environment.OSVersion is what you want. Per the MSDN doc, you would use it like:
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
//Do whatever
}
OTHER TIPS
You can use Environment.OSVersion
to obtain information on the Platform and Version. The Platform property will likely tell you what you want, although I don't know for sure if the returned strings will be enough to tell the different platforms apart. I'd be surprised if they didn't though.
The best way is to check the preprocessor flags
#if WINDOWS
// do stuff
#endif
#if XBOX360
// do stuff
#endif
##if ZUNE
// do stuff
##endif
They probable have an API that will give you the OS version.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow