2022-01-05 08:14:54 -05:00
|
|
|
# Tri Inspector [![Github license](https://img.shields.io/github/license/codewriter-packages/Tri-Inspector.svg?style=flat-square)](#) [![Unity 2019.3](https://img.shields.io/badge/Unity-2019.3+-2296F3.svg?style=flat-square)](#) ![GitHub package.json version](https://img.shields.io/github/package-json/v/codewriter-packages/Tri-Inspector?style=flat-square)
|
|
|
|
_Advanced inspector attributes for Unity_
|
|
|
|
|
2022-01-05 08:22:07 -05:00
|
|
|
### Usage
|
|
|
|
|
2022-01-05 08:14:54 -05:00
|
|
|
```csharp
|
|
|
|
using System;
|
|
|
|
using TriInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class BasicSample : TriMonoBehaviour
|
|
|
|
{
|
|
|
|
[PropertyOrder(1)]
|
|
|
|
[HideLabel, LabelText("My Label"), LabelWidth(100)]
|
|
|
|
[GUIColor(0, 1, 0), Space, Indent, ReadOnly]
|
|
|
|
[Title("My Title"), Header("My Header")]
|
|
|
|
[PropertySpace(SpaceBefore = 10, SpaceAfter = 20)]
|
|
|
|
[PropertyTooltip("My Tooltip")]
|
|
|
|
public float unityField;
|
2022-01-15 11:25:12 -05:00
|
|
|
|
|
|
|
[Required]
|
|
|
|
public Material mat;
|
2022-01-05 08:14:54 -05:00
|
|
|
|
2022-01-09 11:16:45 -05:00
|
|
|
[InlineEditor]
|
|
|
|
public SampleScriptableObject objectReference;
|
|
|
|
|
2022-01-05 08:14:54 -05:00
|
|
|
[HideInPlayMode, ShowInPlayMode]
|
|
|
|
[DisableInPlayMode, EnableInPlayMode]
|
2022-01-19 05:07:52 -05:00
|
|
|
[HideInEditMode, ShowInEditMode]
|
|
|
|
[DisableInEditMode, EnableInEditMode]
|
2022-01-05 08:14:54 -05:00
|
|
|
public float conditional;
|
|
|
|
|
2022-01-19 04:58:33 -05:00
|
|
|
[PropertyOrder(3)]
|
|
|
|
[EnableInPlayMode]
|
|
|
|
[Button("Click Me!")]
|
|
|
|
private void CustomButton()
|
|
|
|
{
|
|
|
|
Debug.Log("Button clicked!");
|
|
|
|
}
|
|
|
|
|
2022-01-05 08:14:54 -05:00
|
|
|
[ShowInInspector]
|
|
|
|
public float ReadonlyProperty => 123f;
|
|
|
|
|
|
|
|
[ShowInInspector]
|
|
|
|
public float EditableProperty
|
|
|
|
{
|
|
|
|
get => unityField;
|
|
|
|
set => unityField = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
[InlineProperty(LabelWidth = 60)]
|
|
|
|
public Config config = new Config();
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class Config
|
|
|
|
{
|
|
|
|
public Vector3 position;
|
|
|
|
public float rotation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[DeclareBoxGroup("body")]
|
|
|
|
[DeclareHorizontalGroup("header")]
|
|
|
|
[DeclareBoxGroup("header/left", Title = "My Left Box")]
|
|
|
|
[DeclareBoxGroup("header/right", Title = "My Right Box")]
|
|
|
|
public class GroupDemo : TriMonoBehaviour
|
|
|
|
{
|
|
|
|
[Group("header/left")] public string h1;
|
|
|
|
[Group("header/left")] public string h2;
|
|
|
|
|
|
|
|
[Group("header/right")] public string h3;
|
|
|
|
[Group("header/right")] public string h4;
|
|
|
|
|
|
|
|
[Group("body")] public string b1;
|
|
|
|
[Group("body")] public string b2;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-01-15 12:22:33 -05:00
|
|
|
### Customization
|
|
|
|
|
|
|
|
#### Custom Drawers
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Value Drawer</summary>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-01-06 12:11:27 -05:00
|
|
|
[assembly: RegisterTriValueDrawer(typeof(BoolDrawer), TriDrawerOrder.Fallback)]
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Attribute Drawer</summary>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-01-06 12:11:27 -05:00
|
|
|
[assembly: RegisterTriAttributeDrawer(typeof(LabelWidthDrawer), TriDrawerOrder.Decorator)]
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Group Drawer</summary>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
using TriInspector.Elements;
|
|
|
|
|
|
|
|
[assembly: RegisterTriGroupDrawer(typeof(TriBoxGroupDrawer))]
|
|
|
|
|
|
|
|
public class TriBoxGroupDrawer : TriGroupDrawer<DeclareBoxGroupAttribute>
|
|
|
|
{
|
|
|
|
public override TriPropertyCollectionBaseElement CreateElement(DeclareBoxGroupAttribute attribute)
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
#### Validators
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Value Validator</summary>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
2022-01-15 11:25:12 -05:00
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
|
|
|
|
[assembly: RegisterTriValueValidator(typeof(MissingReferenceValidator<>))]
|
|
|
|
|
|
|
|
public class MissingReferenceValidator<T> : TriValueValidator<T>
|
|
|
|
where T : UnityEngine.Object
|
|
|
|
{
|
|
|
|
public override TriValidationResult Validate(TriValue<T> propertyValue)
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Attribute Validators</summary>
|
2022-01-15 11:25:12 -05:00
|
|
|
|
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
|
|
|
|
[assembly: RegisterTriAttributeValidator(typeof(RequiredValidator), ApplyOnArrayElement = true)]
|
|
|
|
|
|
|
|
public class RequiredValidator : TriAttributeValidator<RequiredAttribute>
|
|
|
|
{
|
|
|
|
public override TriValidationResult Validate(TriProperty property)
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
#### Property Processors
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Property Hide Processor</summary>
|
2022-01-15 11:25:12 -05:00
|
|
|
|
2022-01-05 08:22:07 -05:00
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
[assembly: RegisterTriPropertyHideProcessor(typeof(HideInPlayModeProcessor))]
|
|
|
|
|
|
|
|
public class HideInPlayModeProcessor : TriPropertyHideProcessor<HideInPlayModeAttribute>
|
|
|
|
{
|
|
|
|
public override bool IsHidden(TriProperty property)
|
|
|
|
{
|
|
|
|
return Application.isPlaying;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
|
|
|
|
|
|
|
<details>
|
|
|
|
<summary>Custom Property Disable Processor</summary>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
|
|
|
```csharp
|
|
|
|
using TriInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableInPlayModeProcessor))]
|
|
|
|
|
|
|
|
public class DisableInPlayModeProcessor : TriPropertyDisableProcessor<DisableInPlayModeAttribute>
|
|
|
|
{
|
|
|
|
public override bool IsDisabled(TriProperty property)
|
|
|
|
{
|
|
|
|
return Application.isPlaying;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2022-01-15 12:22:33 -05:00
|
|
|
</details>
|
2022-01-05 08:22:07 -05:00
|
|
|
|
2022-01-05 08:14:54 -05:00
|
|
|
## How to Install
|
|
|
|
Minimal Unity Version is 2019.3.
|
|
|
|
|
|
|
|
Library distributed as git package ([How to install package from git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html))
|
|
|
|
<br>Git URL: `https://github.com/codewriter-packages/Tri-Inspector.git`
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
Tri-Inspector is [MIT licensed](./LICENSE.md).
|