Sorry if this is noobish, but I’ve searched a bit and can’t find any answers.
Is there a way to find out what OS the game is currently running on? For instance, one thing I’d like to do is default to a borderless window in Windows, but go fullscreen on OSX by default.
If (someAwesomeClass.isWindows)
{
doThisWindowsThing();
}
else if (someAwesomeClass.isOSX)
{
doThisOSXThing();
}
That typically is done making different builds for different platforms (the #if WINDOWS compiler switches).
And that is typically aided by using protobuild.
That tool creates and/or builds different project-files for different setups.
You may import different files for different platforms, etc… by defining that in XML files.
I see that we can now use PlatformInfo.MonoGamePlatform to grab the platform, which is awesome, but if your platform is DesktopGL, how do you differentiate between windows, macOS, and linux?
Is the answer above still the recommended approach?
Environment.OSVersion.Platform is part of dotnet in general (not MonoGame specific), and is one of the recommended ways of determining the operating system.
There are a couple of other ways in dotnet to do this as well.
// Add namespace
using System.Runtime.InteropServices;
// Then in your code....
if(RuntimeInformation.IsOsPlatform(OsPlatform.Windows)
{
// Windows stuff
}
else if(RunTimeInformation.IsOsPlatform(OsPlatform.Linux)
{
// Linux stuff
}
// ... etc
OperatingSystem Class
There is also the System.OperatingSystem class which has static methods to check for operating system.
Example
if(OperatingSystem.IsWindows())
{
// Do windows stuff
}
else if (OperatingSystem.IsLinux())
{
// Do Linux Stuff
}
// ... etc