-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
316 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// using System; | ||
// using System.Linq; | ||
// using System.Reflection; | ||
// using UnityEditor; | ||
// using UnityEngine; | ||
// using AIO.UEngine; | ||
// | ||
// namespace AIO.UEditor | ||
// { | ||
// [CustomPropertyDrawer(typeof(ButtonAttribute))] | ||
// public class ButtonDrawer : PropertyDrawer | ||
// { | ||
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
// { | ||
// DrawEasyButtons(property.serializedObject.targetObject); | ||
// } | ||
// | ||
// public static void DrawEasyButtons<T>(T editor) where T : UnityEngine.Object | ||
// { | ||
// var methods = editor.GetType() | ||
// .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) | ||
// .Where(m => m.GetParameters().Length == 0); | ||
// foreach (var method in methods) | ||
// { | ||
// var ba = (ButtonAttribute)Attribute.GetCustomAttribute(method, typeof(ButtonAttribute)); | ||
// | ||
// if (ba == null) continue; | ||
// var wasEnabled = GUI.enabled; | ||
// GUI.enabled = ba.Mode == ButtonAttribute.EnableMode.Always | ||
// || (EditorApplication.isPlaying | ||
// ? ba.Mode == ButtonAttribute.EnableMode.PlayMode | ||
// : ba.Mode == ButtonAttribute.EnableMode.Editor); | ||
// | ||
// if (((int)ba.Spacing & (int)ButtonAttribute.SpacingMode.Before) != 0) GUILayout.Space(10); | ||
// | ||
// // Draw a button which invokes the method | ||
// var buttonName = string.IsNullOrEmpty(ba.Text) ? ObjectNames.NicifyVariableName(method.Name) : ba.Text; | ||
// if (GUILayout.Button(buttonName)) | ||
// { | ||
// method.Invoke(editor, null); | ||
// } | ||
// | ||
// if (((int)ba.Spacing & (int)ButtonAttribute.SpacingMode.After) != 0) GUILayout.Space(10); | ||
// GUI.enabled = wasEnabled; | ||
// } | ||
// } | ||
// } | ||
// | ||
// // [CanEditMultipleObjects] | ||
// // [CustomEditor(typeof(MonoBehaviourEx), true)] | ||
// // public class ButtonMonoBehaviourEx : UnityEditor.Editor | ||
// // { | ||
// // public override void OnInspectorGUI() | ||
// // { | ||
// // this.DrawEasyButtons(); | ||
// // // Draw the rest of the inspector as usual | ||
// // DrawDefaultInspector(); | ||
// // } | ||
// // } | ||
// // | ||
// // [CanEditMultipleObjects] | ||
// // [CustomEditor(typeof(ScriptableObjectEx), true)] | ||
// // public class ButtonScriptableObjectEx : UnityEditor.Editor | ||
// // { | ||
// // public override void OnInspectorGUI() | ||
// // { | ||
// // this.DrawEasyButtons(); | ||
// // // Draw the rest of the inspector as usual | ||
// // DrawDefaultInspector(); | ||
// // } | ||
// // } | ||
// } |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,97 @@ | ||
// | ||
// using System.Text.RegularExpressions; | ||
// using AIO.Unity.Runtime; | ||
// using UnityEditor; | ||
// using UnityEngine; | ||
// | ||
// namespace AIO.UEditor | ||
// { | ||
// /// <summary> | ||
// /// 只支持 数值类型 | ||
// /// </summary> | ||
// [CustomPropertyDrawer(typeof(LabelRangeAttribute))] | ||
// [CustomPropertyDrawer(typeof(LabelRangeIntAttribute))] | ||
// public class LabelRangeDrawer : LabelDrawer | ||
// { | ||
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
// { | ||
// switch (property.propertyType) | ||
// { | ||
// case SerializedPropertyType.Float: | ||
// { | ||
// if (!(attribute is LabelRangeAttribute attributes)) | ||
// { | ||
// base.OnGUI(position, property, label); | ||
// return; | ||
// } | ||
// | ||
// var name = attributes.name ?? ""; | ||
// property.floatValue = EditorGUI.Slider(position, name, property.floatValue, attributes.min, attributes.max); | ||
// return; | ||
// } | ||
// case SerializedPropertyType.Integer: | ||
// { | ||
// if (!(attribute is LabelRangeIntAttribute attributes)) | ||
// { | ||
// base.OnGUI(position, property, label); | ||
// return; | ||
// } | ||
// | ||
// var name = attributes.name ?? ""; | ||
// property.floatValue = EditorGUI.IntSlider(position, name, property.intValue, attributes.min, attributes.max); | ||
// return; | ||
// } | ||
// default: | ||
// base.OnGUI(position, property, label); | ||
// return; | ||
// } | ||
// } | ||
// } | ||
// | ||
// /// <summary> | ||
// /// 使字段在Inspector中显示自定义的名称。 | ||
// /// 支持 Enum | ||
// /// 支持 Boolean | ||
// /// 支持 Integer | ||
// /// 支持 String | ||
// /// 支持 Class | ||
// /// --------- | ||
// /// 不支持 数组类型 (Odin 插件冲突) | ||
// /// </summary> | ||
// [CustomPropertyDrawer(typeof(LabelAttribute))] | ||
// public class LabelDrawer : PropertyDrawer | ||
// { | ||
// private GUIContent Label; | ||
// | ||
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
// { | ||
// switch (property.propertyType) | ||
// { | ||
// case SerializedPropertyType.Enum: | ||
// { | ||
// if (Label == null && attribute is LabelAttribute attributes) | ||
// { | ||
// Label = new GUIContent(attributes.name ?? ""); | ||
// var isElement = Regex.IsMatch(property.displayName, "Element \\d+"); | ||
// if (isElement) Label.text = property.displayName; | ||
// } | ||
// | ||
// EditorGUI.BeginChangeCheck(); | ||
// var index = DrawerUtils.DrawEnum<LabelAttribute>(fieldInfo, position, property, Label ?? label); | ||
// if (EditorGUI.EndChangeCheck() && index != -1) property.enumValueIndex = index; | ||
// break; | ||
// } | ||
// case SerializedPropertyType.ObjectReference: | ||
// case SerializedPropertyType.String: | ||
// case SerializedPropertyType.Integer: | ||
// case SerializedPropertyType.Boolean: | ||
// default: | ||
// { | ||
// if (Label == null && attribute is LabelAttribute attributes) | ||
// Label = new GUIContent(attributes.name ?? ""); | ||
// EditorGUI.PropertyField(position, property, Label ?? label); | ||
// break; | ||
// } | ||
// } | ||
// } | ||
// } | ||
// } | ||
using System.Text.RegularExpressions; | ||
using AIO.UEngine; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace AIO.UEditor | ||
{ | ||
/// <summary> | ||
/// 只支持 数值类型 | ||
/// </summary> | ||
[CustomPropertyDrawer(typeof(LabelRangeAttribute))] | ||
[CustomPropertyDrawer(typeof(LabelRangeIntAttribute))] | ||
public class LabelRangeDrawer : LabelDrawer | ||
{ | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
switch (property.propertyType) | ||
{ | ||
case SerializedPropertyType.Float: | ||
{ | ||
if (!(attribute is LabelRangeAttribute attributes)) | ||
{ | ||
base.OnGUI(position, property, label); | ||
return; | ||
} | ||
|
||
var name = attributes.Name ?? ""; | ||
property.floatValue = EditorGUI.Slider(position, name, property.floatValue, attributes.min, attributes.max); | ||
return; | ||
} | ||
case SerializedPropertyType.Integer: | ||
{ | ||
if (!(attribute is LabelRangeIntAttribute attributes)) | ||
{ | ||
base.OnGUI(position, property, label); | ||
return; | ||
} | ||
|
||
var name = attributes.Name ?? ""; | ||
property.floatValue = EditorGUI.IntSlider(position, name, property.intValue, attributes.min, attributes.max); | ||
return; | ||
} | ||
default: | ||
base.OnGUI(position, property, label); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 使字段在Inspector中显示自定义的名称。 | ||
/// 支持 Enum | ||
/// 支持 Boolean | ||
/// 支持 Integer | ||
/// 支持 String | ||
/// 支持 Class | ||
/// --------- | ||
/// 不支持 数组类型 (Odin 插件冲突) | ||
/// </summary> | ||
[CustomPropertyDrawer(typeof(LabelAttribute))] | ||
public class LabelDrawer : PropertyDrawer | ||
{ | ||
private GUIContent Label; | ||
|
||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
switch (property.propertyType) | ||
{ | ||
case SerializedPropertyType.Enum: | ||
{ | ||
if (Label == null && attribute is LabelAttribute attributes) | ||
{ | ||
Label = new GUIContent(attributes.Name ?? ""); | ||
var isElement = Regex.IsMatch(property.displayName, "Element \\d+"); | ||
if (isElement) Label.text = property.displayName; | ||
} | ||
|
||
EditorGUI.BeginChangeCheck(); | ||
var index = DrawerUtils.DrawEnum<LabelAttribute>(fieldInfo, position, property, Label ?? label); | ||
if (EditorGUI.EndChangeCheck() && index != -1) property.enumValueIndex = index; | ||
break; | ||
} | ||
case SerializedPropertyType.ObjectReference: | ||
case SerializedPropertyType.String: | ||
case SerializedPropertyType.Integer: | ||
case SerializedPropertyType.Boolean: | ||
default: | ||
{ | ||
if (Label == null && attribute is LabelAttribute attributes) | ||
Label = new GUIContent(attributes.Name ?? ""); | ||
EditorGUI.PropertyField(position, property, Label ?? label); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.