DrawingScope

Unity · Версия 2020.3 LTS · Scripting

DrawingScope

Описание

Одноразовая вспомогательная структура для автоматической установки и отмены Handles.color и/или Handles.matrix.

Эта структура позволяет временно установить значение Handles.color и/или Handles.matrix. внутри блока кода и автоматически возвращать их к предыдущим значениям при выходе из области видимости.

using UnityEditor;
using UnityEngine;

// a custom editor that draws a labeled circle around the selected MeshRenderer in the scene view
[CustomEditor(typeof(MeshRenderer))]
public class MeshRendererEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        MeshRenderer meshRenderer = (MeshRenderer)target;

        // get an orientation pointing from the selected object to the camera
        Vector3 cameraToTarget = Camera.current.transform.position - meshRenderer.transform.position;
        Quaternion billboardOrientation = Quaternion.LookRotation(cameraToTarget, Camera.current.transform.up);

        // set the handle matrix to the target's position, oriented facing the camera
        Matrix4x4 matrix = Matrix4x4.TRS(meshRenderer.transform.position, billboardOrientation, Vector3.one);
        using (new Handles.DrawingScope(Color.magenta, matrix))
        {
            // draw a magenta circle around the selected object with a label at the top
            Vector3 size = meshRenderer.bounds.size;
            float radius = Mathf.Max(size.x, size.y, size.z);
            Handles.DrawWireArc(Vector3.zero, Vector3.forward, Vector3.right, 360f, radius);
            Handles.Label(Vector3.up * radius, meshRenderer.name);
        }
    }
}

Свойства

originalColor Значение Handles.color на момент создания этого DrawingScope.
originalMatrix Значение Handles.matrix на момент создания этого DrawingScope.

Конструкторы

Handles.DrawingScope Создаёт новый DrawingScope и задайте для Handles.color и/или Handles.matrix указанные значения..

Публичные Методы

Dispose Автоматически возвращает Handles.color и Handles.matrix к их значениям до входа в область при выходе из области. Вам не нужно вызывать этот метод вручную.

Обновлено 17 ноября 2026 г.