From 1a18b3b4cc05cf55ca8fc7e33f290aa29beadb77 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Wed, 4 Jan 2017 21:58:07 +0000 Subject: [PATCH] Added new NonDrawingGraphic control and editor script Resolved request #107 --HG-- branch : develop_5.3 --- Editor/NonDrawingGraphicEditor.cs | 21 +++++++++++++++++++++ Editor/NonDrawingGraphicEditor.cs.meta | 12 ++++++++++++ Scripts/Utilities/NonDrawingGraphic.cs | 21 +++++++++++++++++++++ Scripts/Utilities/NonDrawingGraphic.cs.meta | 12 ++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 Editor/NonDrawingGraphicEditor.cs create mode 100644 Editor/NonDrawingGraphicEditor.cs.meta create mode 100644 Scripts/Utilities/NonDrawingGraphic.cs create mode 100644 Scripts/Utilities/NonDrawingGraphic.cs.meta diff --git a/Editor/NonDrawingGraphicEditor.cs b/Editor/NonDrawingGraphicEditor.cs new file mode 100644 index 0000000..4f8ef76 --- /dev/null +++ b/Editor/NonDrawingGraphicEditor.cs @@ -0,0 +1,21 @@ +/// Credit Slipp Douglas Thompson +/// Sourced from - https://gist.github.com/capnslipp/349c18283f2fea316369 +/// +using UnityEditor; +using UnityEditor.UI; + +namespace UnityEngine.UI.Extensions +{ + [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(); + } + } +} \ No newline at end of file diff --git a/Editor/NonDrawingGraphicEditor.cs.meta b/Editor/NonDrawingGraphicEditor.cs.meta new file mode 100644 index 0000000..f9b612a --- /dev/null +++ b/Editor/NonDrawingGraphicEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ee2802949feca4c4c934331b6a0dc379 +timeCreated: 1483566748 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Utilities/NonDrawingGraphic.cs b/Scripts/Utilities/NonDrawingGraphic.cs new file mode 100644 index 0000000..c3a274b --- /dev/null +++ b/Scripts/Utilities/NonDrawingGraphic.cs @@ -0,0 +1,21 @@ +/// Credit Slipp Douglas Thompson +/// Sourced from - https://gist.github.com/capnslipp/349c18283f2fea316369 + +namespace UnityEngine.UI.Extensions +{ + /// A concrete subclass of the Unity UI `Graphic` class that just skips drawing. + /// Useful for providing a raycast target without actually drawing anything. + [AddComponentMenu("Layout/Extensions/NonDrawingGraphic")] + public class NonDrawingGraphic : MaskableGraphic + { + 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; + } + } +} \ No newline at end of file diff --git a/Scripts/Utilities/NonDrawingGraphic.cs.meta b/Scripts/Utilities/NonDrawingGraphic.cs.meta new file mode 100644 index 0000000..4b604c5 --- /dev/null +++ b/Scripts/Utilities/NonDrawingGraphic.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 51db53697a53f7a479b8570674dae649 +timeCreated: 1483541456 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: