Skip to content

Instantly share code, notes, and snippets.

@luxuia
Last active April 22, 2019 04:38
Show Gist options
  • Save luxuia/8a9bde7a8b57e5f727415d2866eb67c7 to your computer and use it in GitHub Desktop.
Save luxuia/8a9bde7a8b57e5f727415d2866eb67c7 to your computer and use it in GitHub Desktop.
change editor window's titile.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace lss.editor {
[InitializeOnLoad]
public class ChangeEditorTitle : MonoBehaviour {
#if UNITY_EDITOR_WIN
[DllImport("user32.dll", EntryPoint = "SetWindowText")]
public static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
[DllImport("user32.dll")]
private static extern System.IntPtr GetActiveWindow();
// unity editor will auto reset editor title in many cases
static ChangeEditorTitle() {
EditorApplication.update += ChangeTitleWhenSceneOnRuntime;
}
private static DateTime lastTime;
private static void ChangeTitleWhenSceneOnRuntime() {
if ((DateTime.Now - lastTime).TotalSeconds > 1) {
lastTime = DateTime.Now;
ChangeTitle();
}
}
private static void ChangeTitle() {
IntPtr windowPtr = GetActiveWindow();
var path = Application.dataPath.Substring(0, Application.dataPath.Length - 7);
SetWindowText(windowPtr, string.Format("{0} [{1}] [{2}] [{3}]",
path, Application.unityVersion ,EditorUserBuildSettings.activeBuildTarget.ToString() , SystemInfo.graphicsDeviceType.ToString() ));
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment