Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
Created December 9, 2019 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mao-test-h/1ee30037da1879825a855bcf257e2b6f to your computer and use it in GitHub Desktop.
Save mao-test-h/1ee30037da1879825a855bcf257e2b6f to your computer and use it in GitHub Desktop.
Unityのタイトルバーを「もなふわすい~とる~む」に設定出来るEditor拡張(Windows限定)
#if UNITY_EDITOR_WIN
using System;
using System.Runtime.InteropServices;
using System.Text;
using UnityEditor;
namespace MonafuwaUtility
{
static class MonafuwaSweetRoomEditor
{
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet=CharSet.Unicode)]
static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
// refered to:
// - http://maketake.hatenablog.com/entry/advent-calendar/2019/unity/08
[MenuItem("もなふわゆ~てぃりてぃ/Set Title")]
static void SetTitle()
{
var window = GetActiveWindow();
if (window == IntPtr.Zero) return;
var length = GetWindowTextLength(window);
var stringBuilder = new StringBuilder(length + 1);
GetWindowText(window, stringBuilder, stringBuilder.Capacity);
SetWindowText(window, "もなふわすい~とる~む");
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment