gizmo | 表示何时绘制 Gizmo 的标志。 |
定义何时应调用 Gizmo 进行绘制。
using UnityEngine; using UnityEditor;
// Draw an image above the light when the light is not selected // The icon has to be stored in Assets/Gizmos
public class ExampleScript : MonoBehaviour { // Draw an image above the light when the light is not selected [DrawGizmo(GizmoType.NotInSelectionHierarchy | GizmoType.Pickable)] static void drawGizmo1(Light light, GizmoType gizmoType) { Vector3 position = light.transform.position;
Gizmos.DrawIcon(position + Vector3.up, "ninja.jpg"); }
// Place a red sphere around a selected light. // Surround the sphere dark shaded when not selected. [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)] static void drawGizmo2(Light light, GizmoType gizmoType) { Vector3 position = light.transform.position;
if ((gizmoType & GizmoType.Selected) != 0) { Gizmos.color = Color.red; } else { Gizmos.color = Color.red * 0.5f; } Gizmos.DrawSphere(position , 1); } }
gizmo | 表示何时绘制 Gizmo 的标志。 |
drawnGizmoType | 应为其绘制 Gizmo 的对象类型。 |
与上面相同。 drawnGizmoType
确定我们绘制其 Gizmo 的对象的类型必须是什么。
如果 drawnGizmoType 为 null,则类型将从绘制 Gizmo 方法的第一个参数确定。如果 drawnGizmoType 不为 null,则它必须与第一个参数的类型相同或为其子类型。