When expanding unity, some attributes are often used. Here are the common ones
1. The attribute is read-only
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
#endif
[ReadOnly]
public string PLUGIN = "";
2. Private variables are displayed in inspector [serializefield]
[ReadOnly]
[SerializeField]
private string ABC = "abc";
The results are as follows
3. Add a header description [headerattribute] to an attribute
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
[Header("Health Settings")]
public int health = 0;
public int maxHealth = 100;
[Header("Shield Settings")]
public int shield = 0;
public int maxShield = 0;
}
412289;38544;34255;*23646;246151;HideInInspector]
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
[HideInInspector]
public int p = 5;
}
Others, such as help URL, can refer to the official help document for details https://docs.unity3d.com/ScriptReference/HeaderAttribute.html
Similar Posts:
- Unity – NullReferenceException: Object reference not set to an instance of an object
- Log system reconstruction of unity3d
- Rigidbody.moveposition rigid body movement
- Xlua#: How to Call C
- Android Exception: UncaughtException detected: java.lang.RuntimeException: Parcelable encountered IOExcepti
- Unity3d: How to Change Font
- [Solved] C# The type or namespace name ‘DllImport’ could not be found
- Unity 3D physics Manager
- [Solved] UserInfo()’ in ‘com.example.gmall.cart.pojo.UserInfo’ cannot be applied to ‘(long, java.lang.String)’
- C#: How to Add Ink Annotation in PDF