3.5 cross platform game, how to find OS?

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.

There is a PR on making some MG internal classes public that provide that functionality: https://github.com/mono/MonoGame/pull/4585

For now you can do:

var pid = Environment.OSVersion.Platform;

switch (pid) {
    case PlatformID.Win32NT:
    case PlatformID.Win32S:
    case PlatformID.Win32Windows:
    case PlatformID.WinCE:
       // Windows Platform
        break;
    case PlatformID.MacOSX:
        // MacOS Platform
        break;
    case PlatformID.Unix:
        var buf = IntPtr.Zero;
        try {
            buf = Marshal.AllocHGlobal (8192);

            if (uname (buf) == 0) {
                var sos = Marshal.PtrToStringAnsi (buf);

                if (sos == "Darwin") {
                    // MacOS Platform
                    return;
                }
            }
        } catch {
        } finally {
            if (buf != IntPtr.Zero)
                Marshal.FreeHGlobal (buf);
        }

        // Linux Platform
        break;
    default:
        // Unknown Platform
        break;
}

Thanks! I’ll give that a shot. :slightly_smiling: