1.12.0: Added FieldLabelFromArrayIndex
This commit is contained in:
parent
df1d2f6df1
commit
23b24d42d3
6 changed files with 71 additions and 1 deletions
36
Editor/Predrawers/FieldLabelFromArrayIndexAttributeDrawer.cs
Normal file
36
Editor/Predrawers/FieldLabelFromArrayIndexAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Text;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Module.Inspector.Editor
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(FieldLabelFromArrayIndexAttribute))]
|
||||||
|
internal sealed class FieldLabelFroArrayIndexAttributeDrawer : PredrawerModifierPropertyDrawer
|
||||||
|
{
|
||||||
|
public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label)
|
||||||
|
{
|
||||||
|
var att = (FieldLabelFromArrayIndexAttribute)attribute;
|
||||||
|
var spParent = property.GetParent();
|
||||||
|
|
||||||
|
if (spParent == null || !spParent.isArray)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var index = spParent.IndexOfProperty(property);
|
||||||
|
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(att.prefix))
|
||||||
|
builder.Append(att.prefix);
|
||||||
|
|
||||||
|
builder.Append(index);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(att.postfix))
|
||||||
|
builder.Append(att.postfix);
|
||||||
|
|
||||||
|
label.text = builder.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c3d86ca907fc4263af776ff820941320
|
||||||
|
timeCreated: 1781374403
|
||||||
|
|
@ -70,6 +70,8 @@ List of all available pre-drawer attributes:
|
||||||
* Sets GUIContent label for `SerializedProperty` to value type from another field
|
* Sets GUIContent label for `SerializedProperty` to value type from another field
|
||||||
* `FieldLabelFromToString`
|
* `FieldLabelFromToString`
|
||||||
* Sets GUIContent label for `SerializedProperty` to values ToString-method
|
* Sets GUIContent label for `SerializedProperty` to values ToString-method
|
||||||
|
* `FieldLabelFromArrayIndex`
|
||||||
|
* Sets GUIContent label for `SerializedProperty` to array index with support for prefix, postfix, and array offset
|
||||||
* `HideLabel`
|
* `HideLabel`
|
||||||
* Sets GUIContent label for `SerializedProperty` to empty string
|
* Sets GUIContent label for `SerializedProperty` to empty string
|
||||||
|
|
||||||
|
|
|
||||||
26
Runtime/Predrawers/FieldLabelFromArrayIndexAttribute.cs
Normal file
26
Runtime/Predrawers/FieldLabelFromArrayIndexAttribute.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Module.Inspector
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
|
public sealed class FieldLabelFromArrayIndexAttribute : PredrawerModifierPropertyAttribute
|
||||||
|
{
|
||||||
|
public readonly string prefix;
|
||||||
|
public readonly string postfix;
|
||||||
|
public readonly int offset;
|
||||||
|
|
||||||
|
public FieldLabelFromArrayIndexAttribute(string prefix, int offset = 0)
|
||||||
|
{
|
||||||
|
this.prefix = prefix;
|
||||||
|
postfix = null;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldLabelFromArrayIndexAttribute(string prefix, string postfix, int offset = 0)
|
||||||
|
{
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.postfix = postfix;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 84143cf4320e4ead85b143498a27f8c4
|
||||||
|
timeCreated: 1781374352
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.inspector",
|
"name": "com.module.inspector",
|
||||||
"version": "1.11.3",
|
"version": "1.12.0",
|
||||||
"displayName": "Module.Inspector",
|
"displayName": "Module.Inspector",
|
||||||
"description": "Custom inspector with various useful property drawers",
|
"description": "Custom inspector with various useful property drawers",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue