Version: 2022.1
언어: 한국어

SceneView.AddOverlayToActiveView(Overlay)

매뉴얼로 전환

파라미터

overlay The Overlay to add.

설명

Add an Overlay to be displayed in the last focused Scene View. Overlays added to this static list will be automatically moved to the last active Scene View, and are displayed until removed.

Overlays added using this method must implement ITransientOverlay. See also SceneView.RemoveOverlayFromActiveView.

using System;
using System.Linq;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEditor.Overlays;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

// An EditorTool that shows an Overlay in the active scene view while enabled. [EditorTool("Overlay Tool Example", typeof(Transform))] class ToolWithOverlay : EditorTool { ActiveSceneViewOverlay m_Overlay;

void OnEnable() { m_Overlay = new ActiveSceneViewOverlay(targets.Cast<Transform>().ToArray()); SceneView.AddOverlayToActiveView(m_Overlay); }

void OnDisable() { m_Overlay.Close(); } }

// A simple Overlay that moves a collection of transforms by some translation. class ActiveSceneViewOverlay : Overlay, ITransientOverlay { Vector3Field m_Translation; Transform[] m_Selection;

public ActiveSceneViewOverlay(Transform[] selection) { m_Selection = selection; }

public bool visible => true;

public override VisualElement CreatePanelContent() { var root = new VisualElement(); root.Add(m_Translation = new Vector3Field("Translation")); root.Add(new Button(MoveSelectionUp) { text = "Move Selection Up" }); m_Translation.SetValueWithoutNotify(Vector3.up); m_Translation.style.minWidth = 300; return root; }

void MoveSelectionUp() { Undo.RecordObjects(m_Selection.ToArray(), "Move Selection"); foreach (var transform in m_Selection) transform.position += m_Translation.value; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961