Skip to content

Commit

Permalink
Adds sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
shniqq committed Jan 19, 2022
1 parent 827431b commit 858a063
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions Samples~/CanvasWithoutRaycastHierarchyLabelRule.cs
Original file line number Diff line number Diff line change
@@ -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<GraphicRaycaster>() ||
_includeDisabled && !component.GetComponent<GraphicRaycaster>().enabled;
}
}
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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~/"
}
]
}

0 comments on commit 858a063

Please sign in to comment.