Version: 2022.3
LanguageEnglish
  • C#

SceneView.AddOverlayToActiveView

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void AddOverlayToActiveView(T overlay);

Parameters

overlay The Overlay to add.

Description

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.

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() { SceneView.RemoveOverlayFromActiveView(m_Overlay); } }

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

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

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; } }