Skip to content

Instantly share code, notes, and snippets.

@KorStrix
Forked from capnslipp/NonDrawingGraphic.cs
Created June 3, 2020 05:45
Show Gist options
  • Save KorStrix/509732b9f6fea55c9f72e3c3e3721ce3 to your computer and use it in GitHub Desktop.
Save KorStrix/509732b9f6fea55c9f72e3c3e3721ce3 to your computer and use it in GitHub Desktop.

Revisions

  1. @capnslipp capnslipp revised this gist Dec 5, 2019. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion NonDrawingGraphic.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /// @creator: Slipp Douglas Thompson
    /// @license: WTFPL
    /// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
    /// @purpose: A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
    /// @why: Because this functionality should be built-into Unity.
    /// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
    2 changes: 1 addition & 1 deletion NonDrawingGraphicEditor.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    /// @creator: Slipp Douglas Thompson
    /// @license: WTFPL
    /// @license: Public Domain per The Unlicense. See <http://unlicense.org/>.
    /// @purpose: Slimmed-down Inspector UI for `NonDrawingGraphic` class.
    /// @why: Because this functionality should be built-into Unity.
    /// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
  2. @capnslipp capnslipp revised this gist Mar 20, 2016. 1 changed file with 0 additions and 0 deletions.
    Binary file added Ω example-usage.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  3. @capnslipp capnslipp revised this gist Mar 20, 2016. 2 changed files with 16 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions NonDrawingGraphic.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    /// @creator: Slipp Douglas Thompson
    /// @license: WTFPL
    /// @purpose: A UnityEngine.UI.Graphic subclass that provides only raycast targeting, skipping all drawing.
    /// @why: Because this functionality should be built-into Unity.
    /// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
    /// @intended project path: Assets/Plugins/UnityEngine UI Extensions/NonDrawingGraphic.cs
    /// @interwebsouce: https://gist.github.com/capnslipp/349c18283f2fea316369

    using UnityEngine;
    using UnityEngine.UI;

    8 changes: 8 additions & 0 deletions NonDrawingGraphicEditor.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    /// @creator: Slipp Douglas Thompson
    /// @license: WTFPL
    /// @purpose: Slimmed-down Inspector UI for `NonDrawingGraphic` class.
    /// @why: Because this functionality should be built-into Unity.
    /// @usage: Add a `NonDrawingGraphic` component to the GameObject you want clickable, but without its own image/graphics.
    /// @intended project path: Assets/Plugins/Editor/UnityEngine UI Extensions/NonDrawingGraphicEditor.cs
    /// @interwebsouce: https://gist.github.com/capnslipp/349c18283f2fea316369

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.UI;
  4. @capnslipp capnslipp revised this gist Mar 20, 2016. No changes.
  5. @capnslipp capnslipp created this gist Mar 20, 2016.
    18 changes: 18 additions & 0 deletions NonDrawingGraphic.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    using UnityEngine;
    using UnityEngine.UI;



    /// A concrete subclass of the Unity UI `Graphic` class that just skips drawing.
    /// Useful for providing a raycast target without actually drawing anything.
    public class NonDrawingGraphic : Graphic
    {
    public override void SetMaterialDirty() { return; }
    public override void SetVerticesDirty() { return; }

    /// Probably not necessary since the chain of calls `Rebuild()`->`UpdateGeometry()`->`DoMeshGeneration()`->`OnPopulateMesh()` won't happen; so here really just as a fail-safe.
    protected override void OnPopulateMesh(VertexHelper vh) {
    vh.Clear();
    return;
    }
    }
    18 changes: 18 additions & 0 deletions NonDrawingGraphicEditor.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    using UnityEngine;
    using UnityEditor;
    using UnityEditor.UI;



    [CanEditMultipleObjects, CustomEditor(typeof(NonDrawingGraphic), false)]
    public class NonDrawingGraphicEditor : GraphicEditor
    {
    public override void OnInspectorGUI ()
    {
    base.serializedObject.Update();
    EditorGUILayout.PropertyField(base.m_Script, new GUILayoutOption[0]);
    // skipping AppearanceControlsGUI
    base.RaycastControlsGUI();
    base.serializedObject.ApplyModifiedProperties();
    }
    }