SpatialUIControllerInspector.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace EZXR.Glass.UI
  6. {
  7. [CustomEditor(typeof(SpatialUIController))]
  8. [CanEditMultipleObjects]
  9. public class SpatialUIControllerInspector : Editor
  10. {
  11. private SpatialUIController _target;
  12. protected void OnEnable()
  13. {
  14. _target = target as SpatialUIController;
  15. }
  16. public override void OnInspectorGUI()
  17. {
  18. serializedObject.Update();
  19. EditorGUILayout.HelpBox("图片中的每个像素对应Unity中的多少个Unit(以Cube的默认边长为1个Unit)", MessageType.Info);
  20. EditorGUILayout.BeginHorizontal();
  21. {
  22. //EditorGUI.BeginChangeCheck();
  23. _target.unitsPerPixel = EditorGUILayout.FloatField("UnitsPerPixel", _target.unitsPerPixel);
  24. //if (EditorGUI.EndChangeCheck())
  25. if (GUILayout.Button("Apply"))
  26. {
  27. if (_target.unitsPerPixel <= 0)
  28. {
  29. EditorUtility.DisplayDialog("提示", "必须是大于0的数字", "OK");
  30. _target.unitsPerPixel = _target.lastUnitsPerPixel;
  31. }
  32. else
  33. {
  34. _target.lastUnitsPerPixel = _target.unitsPerPixel;
  35. _target.PerformReCalculateAllSize(_target.unitsPerPixel);
  36. EditorApplication.QueuePlayerLoopUpdate();
  37. }
  38. }
  39. }
  40. EditorGUILayout.EndHorizontal();
  41. serializedObject.ApplyModifiedProperties();
  42. SceneView.RepaintAll();
  43. }
  44. }
  45. }