XRVideoPlayerEditor.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using UnityEngine;
  2. using UnityEditor.UI;
  3. using UnityEditor;
  4. using XRTool.Util;
  5. namespace XRTool.WorldUI
  6. {
  7. /// <summary>
  8. /// Image 3D
  9. /// </summary>
  10. [InitializeOnLoad]
  11. [CustomEditor(typeof(XRVideoPlayer))]
  12. public class XRVideoPlayerEditor : Editor
  13. {
  14. private SerializedProperty isAutoScale;
  15. private SerializedProperty thickness;
  16. private SerializedProperty video;
  17. private Mesh mesh;
  18. private Material mate;
  19. // private SerializedProperty scale;
  20. private XRVideoPlayer image3D;
  21. private Vector2 lastSize;
  22. // private Vector3 axis;
  23. [MenuItem("GameObject/XRUI/XRUIModel/XRVideoPlayer", priority = 0)]
  24. static void Init()
  25. {
  26. var obj = Instantiate(Resources.Load<XRVideoPlayer>(typeof(XRVideoPlayer).Name));
  27. obj.name = (typeof(XRVideoPlayer).Name);
  28. if (obj)
  29. {
  30. var parent = Selection.activeGameObject;
  31. if (!parent)
  32. {
  33. var canvas = GameObject.FindObjectsOfType(typeof(Canvas));
  34. if (canvas != null)
  35. {
  36. for (int i = 0; i < canvas.Length; i++)
  37. {
  38. if ((canvas[i] as Canvas).renderMode == RenderMode.WorldSpace)
  39. {
  40. parent = (canvas[i] as Canvas).gameObject;
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. UnityUtil.SetParent(parent ? parent.transform : null, obj.transform);
  47. Selection.activeGameObject = obj.gameObject;
  48. }
  49. }
  50. protected void OnEnable()
  51. {
  52. // base.OnEnable();
  53. // return;
  54. image3D = target as XRVideoPlayer;
  55. isAutoScale = serializedObject.FindProperty("isAutoScale");
  56. thickness = serializedObject.FindProperty("thickness");
  57. // scale = serializedObject.FindProperty("scale");
  58. video = serializedObject.FindProperty("video");
  59. lastSize = image3D.RectTransform.rect.size;
  60. image3D.AutoSetSize();
  61. }
  62. public override void OnInspectorGUI()
  63. {
  64. base.OnInspectorGUI();
  65. // return;
  66. EditorGUILayout.PropertyField(isAutoScale, new GUIContent("等比缩放"));
  67. if (!image3D.isAutoScale)
  68. {
  69. EditorGUILayout.PropertyField(thickness, new GUIContent("厚度"));
  70. }
  71. mesh = (Mesh)EditorGUILayout.ObjectField("模型", mesh, typeof(Mesh));
  72. mate = (Material)EditorGUILayout.ObjectField("材质", mate, typeof(Material));
  73. EditorGUILayout.PropertyField(video, new GUIContent("视频"));
  74. //icon3D.img = (Texture2D)EditorGUILayout.ObjectField("Icon", icon3D.img, typeof(Texture2D));
  75. //EditorGUILayout.PropertyField(mesh, new GUIContent("mesh"));
  76. // EditorGUILayout.PropertyField(scale, new GUIContent("模型比例"));
  77. // axis = EditorGUILayout.Vector3Field("模型偏转角(暂不支持)", axis);
  78. serializedObject.ApplyModifiedProperties();
  79. if (image3D.RectTransform.rect.size != lastSize)
  80. {
  81. lastSize = image3D.RectTransform.rect.size;
  82. image3D.AutoSetSize();
  83. }
  84. if (GUI.changed)
  85. {
  86. if (image3D)
  87. {
  88. if (!image3D.isAutoScale)
  89. {
  90. image3D.SetThickness();
  91. }
  92. image3D.SetRenderMesh(mesh);
  93. image3D.SetRenderMate(mate);
  94. image3D.AutoSetSize();
  95. image3D.SetSimple();
  96. }
  97. }
  98. }
  99. }
  100. }