Tri Inspector Documentation

repository·main·Indexed 23 days ago

https://github.com/codewriter-packages/tri-inspector

A Unity package (version 1.15.1) providing advanced inspector attributes to enhance the Unity Editor's UI and developer workflow. It includes tools for property visibility (ShowInInspector, ReadOnly), validation (Required, ValidateInput), layout organization (Group, TableList), and custom controls (Slider, Button, EnumToggleButtons). Supports Unity 2020.3 and above, and offers compatibility mode with Odin Inspector via the [DrawWithTriInspector] attribute.

Tokens
5.6K
Snippets
29
Records
33
Agent score
30%

What's inside Tri Inspector

  1. Use Tri Inspector with Odin Inspector

    main

    Tri Inspector can operate in compatibility mode with Odin Inspector. In this mode, Odin handles the primary interface, but you can opt-in specific parts to be rendered by Tri Inspector using the [DrawWithTriInspector] attribute.

    • Per Class: Mark a class with [DrawWithTriInspector] to render its interface using Tri Inspector.
    • Per Assembly: Mark an entire assembly with [assembly:DrawWithTriInspector] to use Tri Inspector for all types within that assembly.
  2. Install Tri Inspector via Git URL

    main

    Tri Inspector is distributed as a Unity Package Manager (UPM) git package. To install it, add the following Git URL to your project's package manager:

    https://github.com/codewriter-packages/Tri-Inspector.git

    https://github.com/codewriter-packages/Tri-Inspector.git
  3. Select Material properties with MaterialProperty

    main

    The [MaterialProperty] attribute automatically displays valid shader properties from a target Material. Supports types like Color, Float, Vector, and Texture via ShaderPropertyType.

    [MaterialProperty(nameof(material))]
    public string propertyName;
    
    [MaterialProperty(nameof(material), ShaderPropertyType.Color)]
    public int propertyHash;
    
    public Material material;
  4. Convert enums to toggle buttons with EnumToggleButtons

    main

    Use [EnumToggleButtons] to display enum values as a row of toggle buttons instead of a standard dropdown. This works for both standard enums and [Flags] enums.

    [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,
    }
  5. Enforce required fields with Required

    main

    The [Required] attribute marks a field as mandatory. You can provide a FixAction (method name) and FixActionName (display name) to allow users to automatically fix missing references via a button in the inspector.

    [Required]
    public Material material;
    
    [Required(FixAction = nameof(FixTarget), FixActionName = "Assign self")]
    public Transform target;
    
    private void FixTarget()
    {
        target = GetComponent<Transform>();
    }
  6. Show non-serialized properties with ShowInInspector

    main

    Use the [ShowInInspector] attribute to display properties in the Unity Inspector that are not normally serialized (such as private fields, read-only properties, or properties with custom getters/setters).

    private float _field;
    
    [ShowInInspector]
    private bool _myToggle;
    
    [ShowInInspector]
    public float ReadOnlyProperty => _field;
    
    [ShowInInspector]
    public float EditableProperty
    {
        get => _field;
        set => _field = value;
    }
  7. Automatically fetch references with RequiredGet

    main

    The [RequiredGet] attribute automatically searches for and assigns a reference during inspector interaction.

    • InParents = true: Searches up the hierarchy.
    • InChildren = true, IncludeSelf = false: Searches down the hierarchy excluding the current object.
    [RequiredGet]
    public Transform myTransform;
    
    [RequiredGet(InParents = true)]
    public Animator animator; // Search for any Animator in parents
    
    [RequiredGet(InChildren = true, IncludeSelf = false)]
    public MeshRenderer[] childrenMeshes; // Search all meshes in children
  8. Display complex types inline with InlineProperty

    main

    The [InlineProperty] attribute allows you to display the fields of a [Serializable] class directly within the inspector of the parent object, rather than using a foldout.

    public MinMax rangeFoldout;
    
    [InlineProperty(LabelWidth = 40)]
    public MinMax rangeInline;
    
    [Serializable]
    public class MinMax
    {
        public int min;
        public int max;
    }