From 858a063d25e6ec915ede08e2c1961f4736e9413d Mon Sep 17 00:00:00 2001 From: Ruben Ohnmacht <26636673+shniqq@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:37:51 +0100 Subject: [PATCH] Adds sample. --- README.md | 20 +++++------ .../CanvasWithoutRaycastHierarchyLabelRule.cs | 33 +++++++++++++++++++ package.json | 10 +++++- 3 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 Samples~/CanvasWithoutRaycastHierarchyLabelRule.cs diff --git a/README.md b/README.md index b63aa93..99c6120 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,16 @@ Custom labels for the Unity Hierarchy window: ![Example image of hierarchy labels](Documentation~/HierarchyExample.png) - [Hierarchy Labels](#hierarchy-labels) - * [Features](#features) - * [How to use](#how-to-use) - * [Built-in rules](#built-in-rules) - * [Custom Rules](#custom-rules) - + [How to add your own rule](#how-to-add-your-own-rule) - + [How to make your rule configurable](#how-to-make-your-rule-configurable) - + [Add name and description for your rule](#add-name-and-description-for-your-rule) - + [Tips for adding custom rules](#tips-for-adding-custom-rules) - * [Known limitations](#known-limitations) - * [Future Plans](#future-plans) + - [Features](#features) + - [How to use](#how-to-use) + - [Built-in rules](#built-in-rules) + - [Custom Rules](#custom-rules) + - [How to add your own rule](#how-to-add-your-own-rule) + - [How to make your rule configurable](#how-to-make-your-rule-configurable) + - [Add name and description for your rule](#add-name-and-description-for-your-rule) + - [Tips for adding custom rules](#tips-for-adding-custom-rules) + - [Known limitations](#known-limitations) + - [Future Plans](#future-plans) ## Features diff --git a/Samples~/CanvasWithoutRaycastHierarchyLabelRule.cs b/Samples~/CanvasWithoutRaycastHierarchyLabelRule.cs new file mode 100644 index 0000000..793ea71 --- /dev/null +++ b/Samples~/CanvasWithoutRaycastHierarchyLabelRule.cs @@ -0,0 +1,33 @@ +using System; +using System.ComponentModel; +using HierarchyLabels; +using UnityEngine; +using UnityEngine.UI; +using Component = UnityEngine.Component; + +[Serializable, +DisplayName("Missing Raycaster on Canvas"), +Description("Shows a label if a Canvas is attached but no GraphicalRaycaster is present or it is disabled.")] +public class CanvasWithoutRaycastHierarchyLabelRule : HierarchyLabelRule +{ + [SerializeField] private bool _includeDisabled; + + public override bool GetLabel(Component component, out string label) + { + label = string.Empty; + + if (component is Canvas && IsRaycastDisabledOrMissing(component)) + { + label = "Missing GraphicRaycaster!"; + return true; + } + + return false; + } + + private bool IsRaycastDisabledOrMissing(Component component) + { + return !component.GetComponent() || + _includeDisabled && !component.GetComponent().enabled; + } +} \ No newline at end of file diff --git a/package.json b/package.json index e4823db..3f90454 100644 --- a/package.json +++ b/package.json @@ -4,5 +4,13 @@ "description": "Rule based labels for the Unity Editor hierarchy window.", "author": "Ruben Ohnmacht", "license": "MIT", - "displayName": "Hierarchy Labels" + "displayName": "Hierarchy Labels", + "documentationUrl": "https://github.com/shniqq/hierarchy-labels#readme", + "samples": [ + { + "displayName": "Custom Rule Example", + "description": "Contains rule to show a label if a Canvas is missing a GraphicalRaycaster as example on how to create a custom rule.", + "path": "Samples~/" + } + ] } \ No newline at end of file