Skip to content

Commit

Permalink
✨ 更新资源
Browse files Browse the repository at this point in the history
  • Loading branch information
xinansky committed Jun 25, 2024
1 parent bb44fb8 commit d1295a2
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace AIO.RainbowFolders.Settings
{
[PreferBinarySerialization]
[CreateAssetMenu(menuName = "Plugins/Project Ruleset", fileName = nameof(ProjectRuleset))]
[HelpURL("https://www.borodar.com/stuff/rainbowfolders/docs/quickstart_v2.1.0.pdf")]
internal class ProjectRuleset : ScriptableObject
Expand Down Expand Up @@ -365,4 +366,4 @@ private void SaveSetting()
OnRulesetChange();
}
}
}
}
72 changes: 72 additions & 0 deletions Editor/Helper/PropertyDrawer/ButtonDrawer.cs
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();
// // }
// // }
// }
67 changes: 0 additions & 67 deletions Editor/Helper/PropertyDrawer/EditorButton.cs

This file was deleted.

194 changes: 96 additions & 98 deletions Editor/Helper/PropertyDrawer/LabelDrawer.cs
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;
}
}
}
}
}
Loading

0 comments on commit d1295a2

Please sign in to comment.