Go to file
2022-05-12 12:08:12 +03:00
Editor ReferenceGui improvements 2022-05-12 11:28:02 +03:00
Editor.Extras Add ShowIf, HideIf, EnableIf, DisableIf attributes 2022-05-11 20:33:48 +03:00
Runtime Add ShowIf, HideIf, EnableIf, DisableIf attributes 2022-05-11 20:33:48 +03:00
Unity.InternalAPIEditorBridge.012 Hide header in reference type dropdown 2022-05-09 11:24:02 +03:00
.editorconfig initial commot 2022-01-05 14:59:05 +03:00
.gitignore initial commot 2022-01-05 14:59:05 +03:00
Editor.Extras.meta initial commot 2022-01-05 14:59:05 +03:00
Editor.meta initial commot 2022-01-05 14:59:05 +03:00
Installer.unitypackage Access to unity internal with InternalsVisibleTo instead of reflection 2022-05-08 14:31:18 +03:00
Installer.unitypackage.meta Access to unity internal with InternalsVisibleTo instead of reflection 2022-05-08 14:31:18 +03:00
LICENSE.md Add license 2022-01-05 15:45:02 +03:00
LICENSE.md.meta Add license 2022-01-05 15:45:02 +03:00
package.json Up version 1.0.0 2022-05-12 12:08:12 +03:00
package.json.meta initial commot 2022-01-05 14:59:05 +03:00
README.md Add ShowIf, HideIf, EnableIf, DisableIf attributes 2022-05-11 20:33:48 +03:00
README.md.meta Update readme 2022-01-05 16:14:54 +03:00
Runtime.meta initial commot 2022-01-05 14:59:05 +03:00
Unity.InternalAPIEditorBridge.012.meta Access to unity internal with InternalsVisibleTo instead of reflection 2022-05-08 14:31:18 +03:00

Tri Inspector Github license Unity 2020.3 GitHub package.json version

Advanced inspector attributes for Unity

Attributes

Misc

ShowInInspector

Shows non-serialized property in the inspector.

private float field;

[ShowInInspector]
public float ReadOnlyProperty => field;

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

PropertyOrder

Changes property order in the inspector.

[PropertyOrder(1)]

ReadOnly

Makes property non-editable.

[ReadOnly]

OnValueChanged

Invokes callback on property modification.

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

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

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

Required

[Required]
public Material mat;

Required

ValidateInput

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

private TriValidationResult ValidateTexture()
{
    if (tex == null) return TriValidationResult.Error("Tex is null");
    return TriValidationResult.Valid;
}

ValidateInput

Styling

HideLabel

[HideLabel]

HideLabel

LabelText

[LabelText("My Label")]

LabelWidth

[LabelWidth(100)]

GUIColor

[GUIColor(0, 1, 0)]

Space

[Space]

Indent

[Indent]

Title

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

Title

Header

[Header("My Header")]

PropertySpace

[PropertySpace(SpaceBefore = 10, 
               SpaceAfter = 20)]

PropertyTooltip

[PropertyTooltip("My Tooltip")]

InlineEditor

[InlineEditor]
public Material mat;

InlineEditor

InlineProperty

public MinMax rangeFoldout;

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

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

InlineProperty

Collections

ListDrawerSettings

[ListDrawerSettings(Draggable = true,
                    HideAddButton = false,
                    HideRemoveButton = false,
                    AlwaysExpanded = false)]

ListDrawerSettings

Conditionals

ShowIf

public bool visible;

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

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("My Button")]
private void DoButton()
{
    Debug.Log("Button clicked!");
}

Button

Debug

ShowDrawerChain

[ShowDrawerChain]

Groups

[DeclareHorizontalGroup("header")]
[DeclareBoxGroup("header/left", Title = "My Left Box")]
[DeclareVerticalGroup("header/right")]
[DeclareBoxGroup("header/right/top", Title = "My Right Box")]
[DeclareTabGroup("header/right/tabs")]
[DeclareBoxGroup("body")]
public class GroupDemo : MonoBehaviour
{
    [Group("header/left")] public bool prop1;
    [Group("header/left")] public int prop2;
    [Group("header/left")] public string prop3;
    [Group("header/left")] public Vector3 prop4;

    [Group("header/right/top")] public string rightProp;

    [Group("body")] public string body1;
    [Group("body")] public string body2;

    [Group("header/right/tabs"), Tab("One")] public float tabOne;
    [Group("header/right/tabs"), Tab("Two")] public float tabTwo;
    [Group("header/right/tabs"), Tab("Three")] public float tabThree;

    [Group("header/right"), Button]
    public void MyButton()
    {
    }
}

GroupDemo Preview

Customization

Custom Drawers

Custom Value Drawer
using TriInspector;
using UnityEditor;
using UnityEngine;

[assembly: RegisterTriValueDrawer(typeof(BoolDrawer), TriDrawerOrder.Fallback)]

public class BoolDrawer : TriValueDrawer<bool>
{
    public override float GetHeight(float width, TriValue<bool> propertyValue, TriElement next)
    {
        return EditorGUIUtility.singleLineHeight;
    }

    public override void OnGUI(Rect position, TriValue<bool> propertyValue, TriElement next)
    {
        var value = propertyValue.Value;

        EditorGUI.BeginChangeCheck();

        value = EditorGUI.Toggle(position, propertyValue.Property.DisplayNameContent, value);

        if (EditorGUI.EndChangeCheck())
        {
            propertyValue.Value = value;
        }
    }
}
Custom Attribute Drawer
using TriInspector;
using UnityEditor;
using UnityEngine;

[assembly: RegisterTriAttributeDrawer(typeof(LabelWidthDrawer), TriDrawerOrder.Decorator)]

public class LabelWidthDrawer : TriAttributeDrawer<LabelWidthAttribute>
{
    public override void OnGUI(Rect position, TriProperty property, TriElement next)
    {
        var oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = Attribute.Width;
        next.OnGUI(position);
        EditorGUIUtility.labelWidth = oldLabelWidth;
    }
}
Custom Group Drawer
using TriInspector;
using TriInspector.Elements;

[assembly: RegisterTriGroupDrawer(typeof(TriBoxGroupDrawer))]

public class TriBoxGroupDrawer : TriGroupDrawer<DeclareBoxGroupAttribute>
{
    public override TriPropertyCollectionBaseElement CreateElement(DeclareBoxGroupAttribute attribute)
    {
        // ...
    }
}

Validators

Custom Value Validator
using TriInspector;

[assembly: RegisterTriValueValidator(typeof(MissingReferenceValidator<>))]

public class MissingReferenceValidator<T> : TriValueValidator<T>
    where T : UnityEngine.Object
{
    public override TriValidationResult Validate(TriValue<T> propertyValue)
    {
        // ...
    }
}
Custom Attribute Validators
using TriInspector;

[assembly: RegisterTriAttributeValidator(typeof(RequiredValidator), ApplyOnArrayElement = true)]

public class RequiredValidator : TriAttributeValidator<RequiredAttribute>
{
    public override TriValidationResult Validate(TriProperty property)
    {
        // ...
    }
}

Property Processors

Custom Property Hide Processor
using TriInspector;
using UnityEngine;

[assembly: RegisterTriPropertyHideProcessor(typeof(HideInPlayModeProcessor))]

public class HideInPlayModeProcessor : TriPropertyHideProcessor<HideInPlayModeAttribute>
{
    public override bool IsHidden(TriProperty property)
    {
        return Application.isPlaying;
    }
}
Custom Property Disable Processor
using TriInspector;
using UnityEngine;

[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInPlayModeProcessor))]

public class DisableInPlayModeProcessor : TriPropertyDisableProcessor<DisableInPlayModeAttribute>
{
    public override bool IsDisabled(TriProperty property)
    {
        return Application.isPlaying;
    }
}

How to Install

Minimal Unity Version is 2020.3.

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

After installing the package, you need to unpack the Installer.unitypackage that comes with the package

License

Tri-Inspector is MIT licensed.