SyncVarAttributeDrawer.cs 1.1 KB

12345678910111213141516171819202122232425262728
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Mirror
  4. {
  5. [CustomPropertyDrawer(typeof(SyncVarAttribute))]
  6. public class SyncVarAttributeDrawer : PropertyDrawer
  7. {
  8. static readonly GUIContent syncVarIndicatorContent = new GUIContent("SyncVar", "This variable has been marked with the [SyncVar] attribute.");
  9. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  10. {
  11. Vector2 syncVarIndicatorRect = EditorStyles.miniLabel.CalcSize(syncVarIndicatorContent);
  12. float valueWidth = position.width - syncVarIndicatorRect.x;
  13. Rect valueRect = new Rect(position.x, position.y, valueWidth, position.height);
  14. Rect labelRect = new Rect(position.x + valueWidth, position.y, syncVarIndicatorRect.x, position.height);
  15. EditorGUI.PropertyField(valueRect, property, label, true);
  16. GUI.Label(labelRect, syncVarIndicatorContent, EditorStyles.miniLabel);
  17. }
  18. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  19. {
  20. return EditorGUI.GetPropertyHeight(property);
  21. }
  22. }
  23. }