For macOS, create a dynamic library project in XCode. Put the following Objective-C code into the project:
TitlebarLib.h
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#if __cplusplus
extern "C" {
#endif
int ShowTitleBar();
int HideTitleBar();
#if __cplusplus
}
#endif
TitlebarLib.m
#import "TitlebarLib.h"
int ShowTitleBar() {
NSWindow* win = [NSApplication.sharedApplication mainWindow];
win.titleVisibility = NSWindowTitleVisible;
win.titlebarAppearsTransparent = false;
win.movableByWindowBackground = false;
win.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
return 0;
}
int HideTitleBar() {
NSWindow* win = [NSApplication.sharedApplication mainWindow];
win.titleVisibility = NSWindowTitleHidden;
win.titlebarAppearsTransparent = true;
win.movableByWindowBackground = true;
win.styleMask |= NSWindowStyleMaskFullSizeContentView;
return 0;
}
Build the XCode project. Put the output file libTitlebarLib.dylib into the Plugins dir of the Unity project. Use the following code to import the two native functions:
using System.Runtime.InteropServices;
using UnityEngine;
public class GameManager : MonoBehaviour {
[DllImport("libTitlebarLib")]
public extern static int ShowTitleBar();
[DllImport("libTitlebarLib")]
public extern static int HideTitleBar();
public void OnShowTitleBar() {
int ret = ShowTitleBar();
Debug.Log($"ShowTitleBar = {ret}");
}
public void OnHideTitleBar() {
int ret = HideTitleBar();
Debug.Log($"HideTitleBar = {ret}");
}
}
