Мои Уведомления
Привет, !
Мой Аккаунт Мои Финансы Мои Подписки Мои Настройки Выход
Руководство API скрипты

Gizmos.matrix

public static Matrix4x4 matrix;

Описание

Sets the Matrix4x4 that the Unity Editor uses to draw Gizmos.

The Gizmos.matrix stores the position, rotation and scale of the Gizmos. By default, Gizmos always uses world coordinates. The default Gizmos.matrix transforms the world coordinates using a default identity matrix. Transform.localToWorldMatrix changes local coordinate space to world space.

GameObjects often use local coordinates. Gizmos.matrix changes these local coordinates into world coordinates to allow Gizmos to use them. For example, a rotating object uses local coordinates. A transfer into world coordinates happens using Gizmos.matrix. To visualise the object, use Gizmos.DrawCube. See below.

Чтобы использовать этот пример для рисования красной полупрозрачной кубической штуковины:

  1. Поместите этот пример скрипта на цилиндр в начале координат.
  2. Выберите цилиндр в иерархии и нажмите кнопку Play.
  3. Затем нажмите кнопку Scene. Должен появиться гизмо.

Цилиндр будет вращаться в режиме Play и отображаться в виде Scene.

using System.Collections; using System.Collections.Generic; using UnityEngine; // Gizmos.matrix example public class Example : MonoBehaviour { // Allow the speed of rotation to be changed. public float rotationSpeed = 50.0f; void OnDrawGizmosSelected() { Gizmos.color = new Color(0.75f, 0.0f, 0.0f, 0.75f); // Convert the local coordinate values into world // coordinates for the matrix transformation. Gizmos.matrix = transform.localToWorldMatrix; Gizmos.DrawCube(Vector3.zero, Vector3.one); } // Rotate the cylinder. void Update() { float zRot = rotationSpeed * Time.deltaTime; transform.Rotate(0.0f, 0.0f, zRot); } }
Вы можете отблагодарить автора, за перевод документации на русский язык. ₽ Спасибо
API скрипты 2021.3