c# - 如何永久更改统一编辑器标题格式

标签 c# unity3d

当前的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/

相关文章:

android - "Page not found"当用户点击来 self 的应用程序的 Facebook 邀请时

c# - 统一飞机物理

c# - Exchange Web 服务 API 和 401 未授权异常

c# - Microsoft.VisualBasic.DateAndTime 到 C#

c# - UWP - 旋转图像,同时保持其与网格对齐,仅使用 XAML

c# - 在编辑时在 C# 中读取和写入打开的 excel 文件

c# - 在运行时在 C# 中转换开放泛型

c# - 动态构建表达式树

c# - Unity 中的 Quaternion.FromToRotation 出错?

c# - 无法重新实例化/重生我在 Unity3D 中销毁的对象