百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gizmos

> 编程语言
开源

用于在构建和编辑器 (Unity3D) 中绘制运行时 gizmo

579 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于在构建和编辑器 (Unity3D) 中绘制运行时 gizmo

Gizmos

Used for drawing gizmos in either builds or the editor, as the built in gizmos API by Unity only does so in the editor. With some extra features.

Note: Currently doesn't work if a render pipline asset is set in the graphics settings of the project in SRP, if the version of the SRP package is below 7.1.1

Example

…

Camera render filter

By default, gizmos will only be drawn to the MainCamera, and the Scene view camera. If you'd like to specify other cameras to also render the gizmos, the Gizmos.CameraFilter predicate allows you to subscribe to a delegate where you can manually specify if a camera should be rendered to or not.

Example

cs
private void OnEnable()
{
    //always sub in on enable, because OnEnable gets called when code gets recompiled AND on awake
    Gizmos.CameraFilter += cam =>
    {
        return cam.name == "MyOtherCamera";
    };
}

Custom drawers

The ability to add custom drawers is possible. Inherit from the Drawer class and implement the Draw method. To see an example of drawing a line using a custom drawer, look at the LineDrawer.cs file.

The Draw method takes in a ref parameter to a Vector3 array as the buffer, and then a params array of objects. The method expects to return the number of points allocated to the buffer. For example, if renderering a single line, allocate the two points at buffer[0] and buffer[1], and return 2. If the number returned is not the same as the amount of points actually used, then the end result of the drawn element will look incorrect and corrupt.

API

  • Gizmos.Line = Draws a line from point a to b. Equivalent to Gizmos.DrawLine
  • Gizmos.Square = Draws a 2D square in the XY plane
  • Gizmos.Cube = Draws a 3D cube in world space with orientation and scale parameters. Equivalent to Gizmos.DrawWireCube
  • Gizmos.Bounds = Draws a representation of a Bounds object
  • Gizmos.Rect = Draws a rect object to a specific camera
  • Gizmos.Cone = Draws a cone with specified orientation, length and angle. It looks like the spotlight gizmo
  • Gizmos.Sphere = Draws a 3D sphere. Equivalent to Gizmos.DrawWireSphere
  • Gizmos.Circle = Draws a 2D circle that is oriented to the camera by default

Notes

The package uses the same class name as the built-in gizmo class, because of this, you will need to use an alias to point to the right class (using Gizmos = Popcron.Gizmos).

The alternative is to make a global class with the same name that redirects all of its calls to Popcron.Gizmos. The downside to this is that you will need to be explicit when calling the UnityEngine.Gizmos class if you ever need to. Choose your poison.

FAQ

  • What namespace? Popcron
  • Does it work in builds? Yes
  • Is there frustum culling? Yes, it can be toggled with Gizmos.FrustumCulling
  • It's not rendering in game! Check if your gizmo code is in OnDrawGizmos(), because this method isnt called in builds, and ensure that Gizmos.Enabled is true

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#csharpunity3d

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言