-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorWindowTitleChanger
More file actions
65 lines (54 loc) · 1.77 KB
/
EditorWindowTitleChanger
File metadata and controls
65 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Unity.EditorCoroutines.Editor;
using UnityEngine;
using UnityEditor;
using Environment = System.Environment;
#if UNITY_EDITOR_WIN
[InitializeOnLoad]
public static class EditorWindowTitleChanger{
[DllImport("user32.dll", EntryPoint = "SetWindowText")]
public static extern bool SetWindowText(System.IntPtr hwnd, System.String lpString);
[DllImport("user32.dll")]
static extern int GetWindowText(System.IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
private static extern System.IntPtr GetActiveWindow();
public static System.IntPtr GetWindowHandle()
{
return GetActiveWindow();
}
static EditorWindowTitleChanger()
{
//Get the window handle.
CheckChangeTitle();
EditorCoroutineUtility.StartCoroutineOwnerless(DelayedInitCoroutine());
// 订阅播放状态变化事件
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
private static void OnPlayModeStateChanged(PlayModeStateChange obj)
{
CheckChangeTitle();
}
private static void CheckChangeTitle()
{
var windowPtr = GetActiveWindow();
var customTitle = Environment.CurrentDirectory;
var sb = new StringBuilder(200);
GetWindowText(windowPtr,sb,200);
var oldTitle = sb.ToString();
if (!oldTitle.Contains("|"))
{
customTitle = oldTitle + " | " + customTitle;
SetWindowText(windowPtr, customTitle);
}
}
private static IEnumerator DelayedInitCoroutine()
{
// 等待5秒
yield return new WaitForSeconds(5f);
CheckChangeTitle();
}
}
#endif