This repository has been archived on 2025-09-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
XericLibrary-OLD/Runtime/CustomDrawer/GroupAttribute.cs
T
2023-12-08 10:41:31 +08:00

58 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
namespace XericLibrary.Runtime.CustomDrawer
{
public class GroupAttribute : PropertyAttribute
{
public string group;
public GroupAttribute(string groupName)
{
group = groupName;
}
}
#if UNITY_EDITOR
/// <summary>
/// ʹÓ÷Ö×鹦ÄܵÄʾÀý
/// </summary>
//[CustomEditor(typeof(GroupAttribute))]
public class GroupExampleEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
//ShowGroupInspector(target);
}
public static void ShowGroupInspector(Editor editor, object target)
{
// Iterate through the fields
foreach(var field in target.GetType().GetFields())
{
var groupAttribute = field.GetCustomAttribute<GroupAttribute>();
if(groupAttribute != null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(groupAttribute.group, EditorStyles.boldLabel);
}
EditorGUILayout.PropertyField(editor.serializedObject.FindProperty(field.Name), true);
}
editor.serializedObject.ApplyModifiedProperties();
}
}
#endif
}