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

SceneView.AddOverlayToActiveView

建议更改

成功

感谢您帮助我们改善 Unity 文档的质量。虽然我们无法接受所有建议,但我们确实会阅读用户提交的每一项更改建议并在适用时进行更新。

关闭

提交失败

由于某些原因,无法提交您建议的更改。请在几分钟后<a>重试</a>一次。还要感谢您抽出宝贵时间帮助我们提升 Unity 文档的质量。

关闭

取消

声明

public static void AddOverlayToActiveView(T overlay);

参数

覆盖图层 覆盖图层要添加。

描述

在最近聚焦的 Scene View 中添加一个覆盖图层以供显示。添加到此静态列表的覆盖图层会自动移到最近启用的 Scene View,显示直至移除。

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