1.6.0: Added FieldLabelFromType, StringToAnimationClipName and SingleSelectionFlag
This commit is contained in:
parent
7d99d62e11
commit
9faacb6291
15 changed files with 215 additions and 6 deletions
28
Editor/Drawers/SingleSelectionFlagAttributeDrawer.cs
Normal file
28
Editor/Drawers/SingleSelectionFlagAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(SingleSelectionFlagAttribute))]
|
||||
internal sealed class SingleSelectionFlagAttributeDrawer : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Enum)
|
||||
return false;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
property.enumValueIndex = EditorGUI.Popup(position, label.text, property.enumValueIndex, property.enumDisplayNames);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports enum";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fac15dbf3f08429982e975e7454cbe2a
|
||||
timeCreated: 1657357189
|
||||
81
Editor/Drawers/StringToAnimationClipNameAttributeDrawer.cs
Normal file
81
Editor/Drawers/StringToAnimationClipNameAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System.Collections.Generic;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(StringToAnimationClipAttribute))]
|
||||
internal sealed class StringToAnimationClipAttributeDrawer : DrawerPropertyDrawer
|
||||
{
|
||||
private readonly List<string> names = new List<string>();
|
||||
private GUIContent[] contentArr;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (StringToAnimationClipAttribute)attribute;
|
||||
SerializedProperty spSibling = property.GetRelativeProperty(att.animationFieldName);
|
||||
|
||||
if (spSibling == null)
|
||||
return false;
|
||||
|
||||
FetchParameters(spSibling);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
int index = names.IndexOf(property.stringValue);
|
||||
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
|
||||
int newIndex = EditorGUI.Popup(position, label, index, contentArr);
|
||||
property.stringValue = newIndex >= 1 ? names[newIndex] : string.Empty;
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return "Only supports strings";
|
||||
|
||||
var att = (StringToAnimationClipAttribute)attribute;
|
||||
return $"Missing field: {att.animationFieldName}";
|
||||
}
|
||||
|
||||
private void FetchParameters(SerializedProperty property)
|
||||
{
|
||||
var animation = property.objectReferenceValue as Animation;
|
||||
names.Clear();
|
||||
names.Add("----");
|
||||
|
||||
if (animation != null)
|
||||
{
|
||||
AnimationClip[] clips = AnimationUtility.GetAnimationClips(animation.gameObject);
|
||||
|
||||
for (var i = 0; i < clips.Length; i++)
|
||||
{
|
||||
if (clips[i] != null)
|
||||
names.Add(clips[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
contentArr = new GUIContent[names.Count];
|
||||
|
||||
for (var i = 0; i < contentArr.Length; i++)
|
||||
{
|
||||
contentArr[i] = new GUIContent(names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d2dd22fb0c4748e58b2c282194bd88e8
|
||||
timeCreated: 1656856923
|
||||
Loading…
Add table
Add a link
Reference in a new issue