Version: 2020.3

DrawGizmo

class in UnityEditor

매뉴얼로 전환

설명

The DrawGizmo attribute allows you to supply a gizmo renderer for any Component.

The renderer function must be static, and take two parameters: the object for which the gizmo is being drawn, and a GizmoType parameter which indicates the context in which the gizmo is being drawn.

The renderer function can be defined in any class, including editor scripts. This allows you to keep your gizmo-drawing code out of your component scripts so that it is not included in builds.

See Also: GizmoType.

using UnityEngine;
using UnityEditor;

public class MyScript : MonoBehaviour { }

// The icon has to be stored in Assets/Gizmos

public class MyScriptGizmoDrawer { [DrawGizmo(GizmoType.Selected | GizmoType.Active)] static void DrawGizmoForMyScript(MyScript scr, GizmoType gizmoType) { Vector3 position = scr.transform.position;

if (Vector3.Distance(position, Camera.current.transform.position) > 10f) Gizmos.DrawIcon(position, "MyScript Gizmo.tiff"); } }

생성자

DrawGizmoDefines when the gizmo should be invoked for drawing.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961