All Projects → popcron → Gizmos

popcron / Gizmos

Licence: other
Used for drawing runtime gizmos in builds and editor (Unity3D)

Programming Languages

csharp
926 projects

Labels

Projects that are alternatives of or similar to Gizmos

Delight
Delight is an open source component-oriented framework for Unity.
Stars: ✭ 201 (-7.8%)
Mutual labels:  unity3d
Infinite Scroll Unity
Infinite Scroll is a script extension that allows you to use ScrollRect control as an infinite spinner. It is fast, simple and mobile-friendly way to make lists with thousands of rows.
Stars: ✭ 209 (-4.13%)
Mutual labels:  unity3d
Minis
Minis: MIDI Input for New Input System -- A plugin that adds MIDI input support to Unity's new Input System
Stars: ✭ 214 (-1.83%)
Mutual labels:  unity3d
Nice Lua
基于xlua的MVVM框架,支持Addressables, 统一渲染管线等Unity新特性
Stars: ✭ 207 (-5.05%)
Mutual labels:  unity3d
Entitiesbt
Behavior Tree for Unity ECS (DOTS) framework
Stars: ✭ 210 (-3.67%)
Mutual labels:  unity3d
Wfcmaze
WFC (Wave Function Collapse) with Unity
Stars: ✭ 212 (-2.75%)
Mutual labels:  unity3d
Lomenui
Stylish UI package for Unity engine.
Stars: ✭ 199 (-8.72%)
Mutual labels:  unity3d
Casinosclient
果派德州客户端源代码,使用Unity3D引擎。
Stars: ✭ 217 (-0.46%)
Mutual labels:  unity3d
Unity3d Gitlab Ci Example Mirror
🍴Mirror of the gableroux/unity3d-gitlab-ci-example project for Travis and CircleCI on Github. If you are looking for Github Actions, refer to https://github.com/game-ci/unity-actions-example instead.
Stars: ✭ 210 (-3.67%)
Mutual labels:  unity3d
Ipa
Illusion Plugin Architecture (Reloaded)
Stars: ✭ 214 (-1.83%)
Mutual labels:  unity3d
Csharpgameframework
基于unity3d引擎与c#语言的游戏框架/架构(包括客户端与服务器)。使用ServerPlatform作为服务端通信基础设施。
Stars: ✭ 208 (-4.59%)
Mutual labels:  unity3d
Klakhap
HAP video player plugin for Unity
Stars: ✭ 209 (-4.13%)
Mutual labels:  unity3d
Light2d
2D shader-based lighting system for Unity3D
Stars: ✭ 212 (-2.75%)
Mutual labels:  unity3d
Shinyeffectforugui
Shiny effect of uGUI, which does not need mask or normal map.
Stars: ✭ 204 (-6.42%)
Mutual labels:  unity3d
Noiseball2
A small example of procedural modeling with compute shaders.
Stars: ✭ 215 (-1.38%)
Mutual labels:  unity3d
Unityhook
Platform to hook into Unity3D assemblies
Stars: ✭ 198 (-9.17%)
Mutual labels:  unity3d
Egocs
EgoCS: An Entity (GameObject) Component System framework for Unity3D
Stars: ✭ 211 (-3.21%)
Mutual labels:  unity3d
Procedural Worlds Editor
Procedural World Editor is a node based procedural terrain generator
Stars: ✭ 218 (+0%)
Mutual labels:  unity3d
Noteeditor
Note editor for rhythm games.
Stars: ✭ 216 (-0.92%)
Mutual labels:  unity3d
Nativecollections
Native Collection Types for Unity
Stars: ✭ 213 (-2.29%)
Mutual labels:  unity3d

Ah, gl lines

Gizmos

Used for drawing runtime gizmos in builds and editor from any context in the code. It was created when I realized that the built in unity gizmos (Gizmos.DrawWireSphere, etc) don't render in builds, so I made this utility to be able to use.

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

Requirements

  • .NET Framework 4.5
  • Git

Installation

To install for local use, download this repo and copy everything from this repository to <YourUnityProject>/Packages/Popcron Gizmos folder.

If using 2018.3.x or higher, you can add a new entry to the manifest.json file in your Packages folder:

"com.popcron.gizmos": "https://github.com/popcron/gizmos.git"

The package checks for updates every time a compile happens, and it will say so under the Popcron/Gizmos/Update menu if one is available, upon pressing it will make unity update the package to the latest version thats here on github. Though you can always edit it yourself if you'd like.

Example

using UnityEngine;
using Gizmos = Popcron.Gizmos;

[ExecuteAlways]
public class GizmoDrawer : MonoBehaviour
{
    public Material material = null;

    //this will draw in scene view and in game view, in both play mode and edit mode
    private void OnRenderObject()
    {
        //draw a line from the position of the object, to world center
        //with the color green, and dashed as well
        Gizmos.Line(transform.position, Vector3.one, Color.green, true);

        //draw a cube at the position of the object, with the correct rotation and scale
        Gizmos.Cube(transform.position, transform.rotation, transform.lossyScale);
    }

    private void Update()
    {
        //use custom material, if null it uses a default line material
        Gizmos.Material = material;

        //toggle gizmo drawing
        if (Input.GetKeyDown(KeyCode.F3))
        {
            Gizmos.Enabled = !Gizmos.Enabled;
        }
        
        //can also draw from update
        Gizmos.Cone(transform.position, transform.rotation, 15f, 45f, Color.green);
    }
}

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

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].