1 year ago
#278589
Dev Logger
How to have same attribute instance applied to multiple variable instances in c#
I am a Unity Developer and I am trying to create an attribute called "ArrangeAttribut" that will Draw multiple variables in a single row.
Simply put, when I create the following class:
public class Testing: MonoBehaviour
{
[Arrange] public bool bool1, bool2;
public int anotherVariable;
}
I want the inspector to show:
For that, I will have to have the Same Attribute Instance applied to Multiple Variable Instances. Does C# allow this, and if yes, how to achieve it. Also, if there are other ways to arrange multiple variables in one row (Using an Attribute), please suggest them.
Code for ArrangeAttribute:
using UnityEngine;
using System;
# if UNITY_EDITOR
using UnityEditor;
# endif
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class ArrangeAttribute : PropertyAttribute { }
# if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ArrangeAttribute))]
public class ArrangeAttributeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.PropertyField(position, property, new GUIContent(property.name));
}
}
# endif
Thanks.
c#
unity-game-engine
attributes
unity-editor
unity3d-editor
0 Answers
Your Answer