版本:Unity 6 (6000.0)
语言英语
  • C#

EditorWindow.autoRepaintOnSceneChange

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交的内容,但我们会阅读用户提出的每一个建议更改,并在适当的地方进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public bool autoRepaintOnSceneChange;

描述

启用此属性以在修改 SceneView 时自动重新绘制窗口。


显示主摄像机“看到”内容的编辑器窗口。

// Simple script that lets you render the main camera in an Editor Window.

using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;

public class CameraViewer : EditorWindow
{
    Camera camera;
    RenderTexture renderTexture;
    Image image;

    [MenuItem("Examples/Camera Viewer")]
    static void Init()
    {
        EditorWindow editorWindow = GetWindow(typeof(CameraViewer));
        editorWindow.autoRepaintOnSceneChange = true;
        editorWindow.Show();
    }

    public void Awake()
    {
        renderTexture = new RenderTexture((int)position.width,
            (int)position.height,
            (int)RenderTextureFormat.ARGB32);
    }

    public void OnEnable()
    {
        camera = Camera.main;
    }

    void CreateGUI()
    {
        image = new Image();
        image.image = renderTexture;
        image.style.width = Length.Percent(100);
        image.style.height = Length.Percent(100);
        rootVisualElement.Add(image);
    }

    public void Update()
    {
        if (renderTexture.width != position.width ||
            renderTexture.height != position.height)
            renderTexture = new RenderTexture((int)position.width,
                (int)position.height,
                (int)RenderTextureFormat.ARGB32);
            image.image = renderTexture;    

        if (camera != null)
        {
            camera.targetTexture = renderTexture;
            camera.Render();
            camera.targetTexture = null;
        }    
    }
}