当前的Unity编辑器标题格式如下:
Unity - Unity 2017.4.6f1 Personal (64bit) - TestMoveAndJump.unity - Ro.Unity - PC, Mac & Linux Standalone <OpenGL 4.5>
因为“Unity - Unity 2017.4.6f1 Personal (64bit)”太长,所以在应用程序切换器和任务栏中很难识别,我希望将 unity 项目名称放在第一位,例如:
Ro.Unity Unity - Unity 2017.4.6f1 Personal (64bit) - TestMoveAndJump.unity - Ro.Unity - PC, Mac & Linux Standalone <OpenGL 4.5>
我该怎么办,我可以在 system c++ 中更改 unity 窗口标题,但我发现 unity 编辑器标题在很多情况下会被重置,所以我希望有一种方法可以在 unity 编辑器脚本中设置 unity 编辑器标题
最佳答案
我不确定您尝试了什么,也不确定这是否是您所说的“system c++”的意思,但我已经使用它成功地更改了标题。 (您需要将其附加到游戏对象)
只能在 Windows 上运行......但无论如何我都会把它扔在这里。
[ExecuteInEditMode]
public class TitleChanger : MonoBehaviour
{
[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();
void Start()
{
IntPtr windowPtr = GetActiveWindow();
SetWindowText(windowPtr, Application.productName + " [" + Application.unityVersion +"]");
}
void OnRenderObject()
{
IntPtr windowPtr = GetActiveWindow();
SetWindowText(windowPtr, Application.productName + " [" + Application.unityVersion + "]");
}
}
unity 中有很多方法可以获取信息以放入您的标题,Application
有一些方法,如果您想要当前场景,您可以执行 SceneManager.GetActiveScene().name
等
编辑:
我注意到在保存我的项目时标题会丢失,但是在我将 OnRenderObject
添加到上面的代码后,这就不再是问题了。
关于c# - 如何永久更改统一编辑器标题格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51968170/