• Stars
    star
    921
  • Rank 49,603 (Top 1.0 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Free inspector attributes for Unity [Custom Editor, Custom Inspector, Inspector Attributes, Attribute Extensions]

Tri Inspector Github license Unity 2020.3 GitHub package.json version openupm

Advanced inspector attributes for Unity

Tri-Inspector-Demo

How to Install

Library distributed as git package (How to install package from git URL)
Git URL: https://github.com/codewriter-packages/Tri-Inspector.git

After package installation run the Installer by double clicking on it. TriInspector-Installer

Roadmap GitHub Repo stars

Each star β˜… on the project page brings new features closer. You can suggest new features in the Discussions.

Samples

TriInspector has built-in samples at Tools/Tri Inspector/Samples menu. Samples

Attributes

Misc

ShowInInspector

Shows non-serialized property in the inspector.

ShowInInspector

private float _field;

[ShowInInspector]
private bool _myToggle;

[ShowInInspector]
public float ReadOnlyProperty => _field;

[ShowInInspector]
public float EditableProperty
{
    get => _field;
    set => _field = value;
}

HideReferencePicker

Tri Inspector by default shows a polymorphic type picker for [SerializeReference] and [ShowInInspector]. It can be hidden with a [HideReferencePicker] attribute.

HideReferencePicker

[SerializeReference]
public MyReferenceClass clazz1 = new MyReferenceClass();

[SerializeReference, HideReferencePicker]
public MyReferenceClass clazz2 = new MyReferenceClass();

[ShowInInspector, HideReferencePicker]
public MyReferenceClass Clazz3 { get; set; } = new MyReferenceClass();

[Serializable]
public class MyReferenceClass
{
    public int inner;
}

PropertyOrder

Changes property order in the inspector.

PropertyOrder

public float first;

[PropertyOrder(0)]
public float second;

ReadOnly

Makes property non-editable in the inspector.

ReadOnly

[ReadOnly]
public Vector3 vec;

OnValueChanged

Invokes callback on property modification.

[OnValueChanged(nameof(OnMaterialChanged))]
public Material mat; 

private void OnMaterialChanged()
{
    Debug.Log("Material changed!");
}

HideMonoScript

Hides the default Script property in the inspector.

[HideMonoScript]
public class NewBehaviour : MonoBehaviour
{
}

Validation

Tri Inspector has some builtin validators such as missing reference and type mismatch error. Additionally you can mark out your code with validation attributes or even write own validators.

Builtin-Validators

Required

Required

[Required]
public Material mat;

ValidateInput

ValidateInput

[ValidateInput(nameof(ValidateTexture))]
public Texture tex;

private TriValidationResult ValidateTexture()
{
    if (tex == null) return TriValidationResult.Error("Tex is null");
    if (!tex.isReadable) return TriValidationResult.Warning("Tex must be readable");
    return TriValidationResult.Valid;
}

InfoBox

InfoBox

[Title("InfoBox Message Types")]
[InfoBox("Default info box")]
public int a;

[InfoBox("None info box", TriMessageType.None)]
public int b;

[InfoBox("Warning info box", TriMessageType.Warning)]
public int c;

[InfoBox("Error info box", TriMessageType.Error)]
public int d;

[InfoBox("$" + nameof(DynamicInfo), visibleIf: nameof(VisibleInEditMode))]
public Vector3 vec;

private string DynamicInfo => "Dynamic info box: " + DateTime.Now.ToLongTimeString();

private bool VisibleInEditMode => !Application.isPlaying;

AssetsOnly

AssetsOnly

[AssetsOnly]
public GameObject obj;

SceneObjectsOnly

SceneObjectsOnly

[SceneObjectsOnly]
public GameObject obj;

Decorators

Dropdown

Dropdown

[Dropdown(nameof(intValues))]
public int numberDropdown = 123;

[Dropdown(nameof(GetVectorValues))]
public Vector3 vectorDropdown;

private int[] intValues = {1, 2, 3, 4, 5};

private IEnumerable<TriDropdownItem<Vector3>> GetVectorValues()
{
    return new TriDropdownList<Vector3>
    {
        {"Zero", Vector3.zero},
        {"One/Forward", Vector3.forward},
        {"One/Backward", Vector3.back},
    };
}

Scene

Scene

[Scene] public string scene;

InlineEditor

InlineEditor

[InlineEditor]
public Material mat;

DisplayAsString

DisplayAsString

[DisplayAsString]
public string[] collection = {"hello", "world"};

Styling

Title

Title

[Title("My Title")]
public string val;

[Title("$" + nameof(_myTitleField))]
public Rect rect;

[Title("$" + nameof(MyTitleProperty))]
public Vector3 vec;

[Title("Button Title")]
[Button]
public void MyButton()
{
}

private string _myTitleField = "Serialized Title";

private string MyTitleProperty => DateTime.Now.ToLongTimeString();

HideLabel

HideLabel

[Title("Wide Vector")]
[HideLabel]
public Vector3 vector;

[Title("Wide String")]
[HideLabel]
public string str;

LabelText

LabelText

[LabelText("Custom Label")]
public int val;

[LabelText("$" + nameof(DynamicLabel))]
public Vector3 vec;

public string DynamicLabel => DateTime.Now.ToShortTimeString();

LabelWidth

LabelWidth

public int defaultWidth;

[LabelWidth(40)]
public int thin;

[LabelWidth(300)]
public int customInspectorVeryLongPropertyName;

GUIColor

GUIColor

[GUIColor(0.8f, 1.0f, 0.6f)]
public Vector3 vec;

[GUIColor(0.6f, 0.9f, 1.0f)]
[Button]
public void BlueButton() { }

[GUIColor(1.0f, 0.6f, 0.6f)]
[Button]
public void RedButton() { }

Indent

Indent

[Title("Custom Indent")]
[Indent]
public int a;

[Indent(2)]
public int b;

[Indent(3)]
public int c;

[Indent(4)]
public int d;

PropertySpace

PropertySpace

[Space, PropertyOrder(0)]
public Vector3 vecField;

[ShowInInspector, PropertyOrder(1)]
[PropertySpace(SpaceBefore = 10, SpaceAfter = 30)]
public Rect RectProperty { get; set; }

[PropertyOrder(2)]
public bool b;

PropertyTooltip

PropertyTooltip

[PropertyTooltip("This is tooltip")]
public Rect rect;

[PropertyTooltip("$" + nameof(DynamicTooltip))]
public Vector3 vec;

public string DynamicTooltip => DateTime.Now.ToShortTimeString();

InlineProperty

InlineProperty

public MinMax rangeFoldout;

[InlineProperty(LabelWidth = 40)]
public MinMax rangeInline;

[Serializable]
public class MinMax
{
    public int min;
    public int max;
}

Collections

ListDrawerSettings

ListDrawerSettings

[ListDrawerSettings(Draggable = true,
                    HideAddButton = false,
                    HideRemoveButton = false,
                    AlwaysExpanded = false)]
public List<Material> list;

[ListDrawerSettings(Draggable = false, AlwaysExpanded = true)]
public Vector3[] vectors;

TableList

TableList

[TableList(Draggable = true,
           HideAddButton = false,
           HideRemoveButton = false,
           AlwaysExpanded = false)]
public List<TableItem> table;

[Serializable]
public class TableItem
{
    [Required]
    public Texture icon;
    public string description;

    [Group("Combined"), LabelWidth(16)]
    public string A, B, C;

    [Button, Group("Actions")]
    public void Test1() { }

    [Button, Group("Actions")]
    public void Test2() { }
}

Conditionals

ShowIf

ShowIf

public Material material;
public bool toggle;
public SomeEnum someEnum;

[ShowIf(nameof(material), null)]
public Vector3 showWhenMaterialIsNull;

[ShowIf(nameof(toggle))]
public Vector3 showWhenToggleIsTrue;

[ShowIf(nameof(toggle), false)]
public Vector3 showWhenToggleIsFalse;

[ShowIf(nameof(someEnum), SomeEnum.Two)]
public Vector3 showWhenSomeEnumIsTwo;

public enum SomeEnum { One, Two, Three }

HideIf

public bool visible;

[HideIf(nameof(visible))]
public float val;

EnableIf

public bool visible;

[EnableIf(nameof(visible))]
public float val;

DisableIf

public bool visible;

[DisableIf(nameof(visible))]
public float val;

HideInPlayMode / ShowInPlayMode

[HideInPlayMode] [ShowInPlayMode]

DisableInPlayMode / EnableInPlayMode

[DisableInPlayMode] [EnableInPlayMode]

HideInEditMode / ShowInEditMode

[HideInEditMode] [ShowInEditMode]

DisableInEditMode / EnableInEditMode

[DisableInEditMode] [EnableInEditMode]

Buttons

Button

Button

[Button("Click me!")]
private void DoButton()
{
    Debug.Log("Button clicked!");
}

EnumToggleButtons

EnumToggleButtons

[EnumToggleButtons] public SomeEnum someEnum;
[EnumToggleButtons] public SomeFlags someFlags;

public enum SomeEnum { One, Two, Three }

[Flags] public enum SomeFlags
{
    A = 1 << 0,
    B = 1 << 1,
    C = 1 << 2,
    AB = A | B,
    BC = B | C,
}

Debug

ShowDrawerChain

ShowDrawerChain

[ShowDrawerChain]
[Indent]
[PropertySpace]
[Title("Custom Title")]
[GUIColor(1.0f, 0.8f, 0.8f)]
public Vector3 vec;

Groups

Properties can be grouped in the inspector using the Group attribute.

[Group("one")] public float a;
[Group("one")] public float b;

[Group("two")] public float c;
[Group("two")] public float d;

public float e;

If you have a lot of properties and group attributes take up too much space, then you can combine multiple properties at once using the GroupNext attribute.

[GroupNext("one")]
public float a;
public float b;

[GroupNext("two")]
public float c;
public float d;

[UnGroupNext]
public float e;

Box Group

BoxGroup

[DeclareBoxGroup("box", Title = "My Box")]
public class BoxGroupSample : ScriptableObject
{
    [Group("box")] public int a;
    [Group("box")] public bool b;
}

Foldout Group

FoldoutGroup

[DeclareFoldoutGroup("foldout", Title = "$" + nameof(DynamicTitle))]
public class FoldoutGroupSample : ScriptableObject
{
    [Group("foldout")] public int a;
    [Group("foldout")] public bool b;
    
    public string DynamicTitle => "My Foldout";
}

Toggle Group

ToggleGroup

[DeclareToggleGroup("toggle", Title = "$" + nameof(DynamicTitle))]
public class ToggleGroupSample : ScriptableObject
{
    [Group("toggle")] public bool enabled;
    [Group("toggle")] public int a;
    [Group("toggle")] public bool b;
    
    public string DynamicTitle => "My Toggle";
}

Tab Group

TabGroup

[DeclareTabGroup("tabs")]
public class TabGroupSample : ScriptableObject
{
    [Group("tabs"), Tab("One")] public int a;
    [Group("tabs"), Tab("Two")] public float b;
    [Group("tabs"), Tab("Three")] public bool c;
}

Horizontal Group

HorizontalGroup

[DeclareHorizontalGroup("vars")]
public class HorizontalGroupSample : ScriptableObject
{
    [Group("vars")] public int a;
    [Group("vars")] public int b;
    [Group("vars")] public int c;
}

Vertical Group

VerticalGroup

[DeclareHorizontalGroup("horizontal")]
[DeclareVerticalGroup("horizontal/vars")]
[DeclareVerticalGroup("horizontal/buttons")]
public class VerticalGroupSample : ScriptableObject
{
    [Group("horizontal/vars")] public float a;
    [Group("horizontal/vars")] public float b;

    [Button, Group("horizontal/buttons")]
    public void ButtonA() { }

    [Button, Group("horizontal/buttons")]
    public void ButtonB() { }
}

Integrations

Odin Inspector

Tri Inspector is able to work in compatibility mode with Odin Inspector. In this mode, the primary interface will be drawn by the Odin Inspector. However, parts of the interface can be rendered by the Tri Inspector.

In order for the interface to be rendered by Tri instead of Odin, it is necessary to mark classes with [DrawWithTriInspector] attribute.

Alternatively, you can mark the entire assembly with an attribute [assembly:DrawWithTriInspector] to draw all types in the assembly using the Tri Inspector.

Odin Validator

Tri Inspector is integrated with the Odin Validator so all validation results from Tri attributes will be shown in the Odin Validator window.

Odin-Validator-Integration

License

Tri-Inspector is MIT licensed.

More Repositories

1

Mesh-Animation

Fast GPU vertex shader based animation library for Unity (VAT, Vertex Animation Texture, Morphing Animation)
C#
498
star
2

UniMob

Modern reactive programming library for Unity (inspired by MobX js)
C#
182
star
3

UniMob.UI

MVU/Redux like library for building declarative UI in Unity (inspired by Flutter)
C#
105
star
4

Expression-Parser

Simple math expression parser library for Unity
C#
48
star
5

textmeshpro-spriteatlas-support

Tool that converts SpriteAtlas to TextMeshPro Sprite asset
C#
38
star
6

View-Binding

View binding library for Unity. Built over UniMob
C#
27
star
7

Morpeh.Events

Lightweight events for Morpeh
C#
25
star
8

Package-Symlinker

Package Symlinker is a tool that allows you create symbolic links to packages, so you can edit any package as if it were located right in the project.
C#
25
star
9

TutorialMaskForUGUI

UI Tutorial Mask is a component for highlighting specific objects over darkened background for Unity UI (uGUI)
C#
15
star
10

SceneMaterialAnalyzer

Tool for analyzing materials and shaders used in scenes
C#
14
star
11

Style-Components

Library for styling game objects in Unity. . Built over UniMob and View-Binding.
C#
12
star
12

Morpeh.SystemStateProcessor

Reactivity for Morpeh ECS
C#
10
star
13

RequireFieldsInit-Analyzer

C# 11 "Required Members" for Unity
C#
9
star
14

NpmPublisherSupport

Publish Npm packages to your registry directly from the Unity
C#
7
star
15

UniMob.UI-Samples

Samples for UniMob.UI - a declarative library for building reactive user interface
C#
6
star
16

Morpeh.StateMachine

C#
5
star
17

SampleApp-Clicker

Sample app uses UniMob, UniMob.UI, View-Binding, Style-Components, Morpeh, Morpeh-UniMob-Globals. Simplest game. Just click play and wait for timer end.
C#
4
star
18

Unity-Localization-Stub-for-Tri-Inspector

[Not affiliated with Unity Technologies.]
C#
1
star