AutoLayout3DEditor.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #if UNITY_EDITOR
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEditor;
  6. namespace AutoLayout3D
  7. {
  8. [CustomPropertyDrawer(typeof(Bool3))]
  9. public class Bool3Drawer : PropertyDrawer
  10. {
  11. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  12. {
  13. EditorGUI.BeginProperty(position, label, property);
  14. int indent = EditorGUI.indentLevel;
  15. EditorGUI.indentLevel = 0;
  16. position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
  17. Rect xLabelRect = new Rect(position.x, position.y, 15, position.height);
  18. Rect yLabelRect = new Rect(position.x + 35, position.y, 15, position.height);
  19. Rect zLabelRect = new Rect(position.x + 70, position.y, 15, position.height);
  20. Rect xRect = new Rect(position.x + 15, position.y, 15, position.height);
  21. Rect yRect = new Rect(position.x + 50, position.y, 15, position.height);
  22. Rect zRect = new Rect(position.x + 85, position.y, 15, position.height);
  23. EditorGUI.LabelField(xLabelRect, new GUIContent("X"));
  24. EditorGUI.PropertyField(xRect, property.FindPropertyRelative("x"), GUIContent.none);
  25. EditorGUI.LabelField(yLabelRect, new GUIContent("Y"));
  26. EditorGUI.PropertyField(yRect, property.FindPropertyRelative("y"), GUIContent.none);
  27. EditorGUI.LabelField(zLabelRect, new GUIContent("Z"));
  28. EditorGUI.PropertyField(zRect, property.FindPropertyRelative("z"), GUIContent.none);
  29. EditorGUI.indentLevel = indent;
  30. EditorGUI.EndProperty();
  31. }
  32. }
  33. [CustomPropertyDrawer(typeof(Constraint))]
  34. public class ConstraintDrawer : PropertyDrawer
  35. {
  36. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  37. {
  38. float height = 18.0f;
  39. SerializedProperty constraintType = property.FindPropertyRelative("constraintType");
  40. if ((ConstraintType)constraintType.enumValueIndex == ConstraintType.FixedCellCount) height = 36.0f;
  41. return height;
  42. }
  43. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  44. {
  45. EditorGUI.BeginProperty(position, label, property);
  46. int indent = EditorGUI.indentLevel;
  47. EditorGUI.indentLevel = 0;
  48. SerializedProperty constraintType = property.FindPropertyRelative("constraintType");
  49. Rect rectType = new Rect(position.x, position.y, position.width, 15);
  50. rectType = EditorGUI.PrefixLabel(rectType, GUIUtility.GetControlID(FocusType.Passive), label);
  51. EditorGUI.PropertyField(rectType, constraintType, GUIContent.none);
  52. if ((ConstraintType)constraintType.enumValueIndex == ConstraintType.FixedCellCount)
  53. {
  54. EditorGUI.indentLevel = 1;
  55. Rect rectCount = new Rect(position.x, position.y + 18, position.width, 15);
  56. EditorGUI.PropertyField(rectCount, property.FindPropertyRelative("constraintCount"));
  57. }
  58. EditorGUI.indentLevel = indent;
  59. EditorGUI.EndProperty();
  60. }
  61. }
  62. }
  63. #endif