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

IDrawSelectedHandles.OnDrawHandles

建议修改

成功!

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

关闭

提交失败

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

关闭

取消

声明

public void OnDrawHandles();

描述

实现此方法以在自定义编辑器工具可用时绘制非交互式手柄。

当当前选择项有自定义编辑器工具可用时,此方法会被调用。使用此方法在 SceneView 中绘制信息。自定义编辑器工具是 EditorTool,其目标类型由 EditorToolAttribute 指定。

using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.EditorTools;

[EditorTool("Light Tool", typeof(Light))] public class CustomEditorLightTool : EditorTool, IDrawSelectedHandles { // OnToolGUI is called when the tool is active. Interactive handles belong here. public override void OnToolGUI(EditorWindow window) { var position = Tools.handlePosition;

EditorGUI.BeginChangeCheck();

var result = Handles.PositionHandle(position, Quaternion.identity);

if (EditorGUI.EndChangeCheck()) { var delta = result - position;

Undo.RecordObjects(Selection.transforms, "Move Lights");

foreach (var light in targets) ((Light)light).transform.position += delta; } }

// OnDrawHandles is called when a custom editor tool is available for the current selection. Use this to draw // information in the SceneView when any object matching the target type is selected. public void OnDrawHandles() { foreach (var light in targets) { // If the Light Tool is active, draw a green radius handle. If it is not active, make the radius blue. Handles.color = EditorTools.IsActiveTool(this) ? Color.green : Color.blue; Handles.RadiusHandle(Quaternion.identity, ((Light)light).transform.position, 2f); Handles.color = Color.white; } } }