SpatialUIElementInspector.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace EZXR.Glass.UI
  6. {
  7. [CustomEditor(typeof(SpatialUIElement))]
  8. [CanEditMultipleObjects]
  9. public class SpatialUIElementInspector : Editor
  10. {
  11. private SpatialUIElement _target_SpatialUIElement;
  12. SerializedProperty interactable;
  13. SerializedProperty positionType;
  14. SerializedProperty size;
  15. SerializedProperty text;
  16. SerializedProperty textColor;
  17. SerializedProperty color;
  18. SerializedProperty texture;
  19. SerializedProperty sortingOrder;
  20. protected virtual void OnEnable()
  21. {
  22. _target_SpatialUIElement = target as SpatialUIElement;
  23. interactable = serializedObject.FindProperty("interactable");
  24. positionType = serializedObject.FindProperty("positionType");
  25. size = serializedObject.FindProperty("size");
  26. text = serializedObject.FindProperty("text");
  27. textColor = serializedObject.FindProperty("textColor");
  28. color = serializedObject.FindProperty("color");
  29. texture = serializedObject.FindProperty("texture");
  30. sortingOrder = serializedObject.FindProperty("sortingOrder");
  31. }
  32. public override void OnInspectorGUI()
  33. {
  34. serializedObject.Update();
  35. EditorGUILayout.PropertyField(interactable, new GUIContent("Interactable", "是否可以与射线或者手进行交互"));
  36. EditorGUILayout.PropertyField(positionType);
  37. EditorGUILayout.PropertyField(size, new GUIContent("Size(单位:m)"));
  38. EditorGUILayout.PropertyField(text);
  39. EditorGUILayout.PropertyField(textColor);
  40. EditorGUILayout.PropertyField(color);
  41. EditorGUILayout.BeginHorizontal();
  42. {
  43. EditorGUILayout.PropertyField(texture);
  44. if (GUILayout.Button(new GUIContent("Set Physical Size", "按照SpatialUIController.unitsPerPixel中设定的“像素-UnityUnit转换比例”将Texture以换算后的物理尺寸绘制在空间中")))
  45. {
  46. Undo.RecordObject(_target_SpatialUIElement, "Set Physical Size");
  47. _target_SpatialUIElement.size = new Vector3(_target_SpatialUIElement.Texture.width * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.Texture.height * _target_SpatialUIElement.curUnitsPerPixel, _target_SpatialUIElement.size.z);
  48. //_target_SpatialUIElement.curUnitsPerPixel = SpatialUIController.Instance.unitsPerPixel;
  49. EditorApplication.QueuePlayerLoopUpdate();
  50. //SceneView.RepaintAll();
  51. }
  52. }
  53. EditorGUILayout.EndHorizontal();
  54. EditorGUI.BeginChangeCheck();
  55. _target_SpatialUIElement.sortingOrder = EditorGUILayout.DelayedIntField("SortingOrder", _target_SpatialUIElement.sortingOrder);
  56. if (EditorGUI.EndChangeCheck())
  57. {
  58. if (_target_SpatialUIElement._text != null && _target_SpatialUIElement._text.GetComponent<MeshRenderer>() != null)
  59. {
  60. _target_SpatialUIElement._text.GetComponent<MeshRenderer>().sortingOrder = _target_SpatialUIElement.sortingOrder + 1;
  61. }
  62. }
  63. serializedObject.ApplyModifiedProperties();
  64. SceneView.RepaintAll();
  65. }
  66. }
  67. }