123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using UnityEngine;
- using UnityEditor.UI;
- using UnityEditor;
- using XRTool.Util;
- namespace XRTool.WorldUI
- {
- /// <summary>
- /// Image 3D
- /// </summary>
- [InitializeOnLoad]
- [CustomEditor(typeof(XRVideoPlayer))]
- public class XRVideoPlayerEditor : Editor
- {
- private SerializedProperty isAutoScale;
- private SerializedProperty thickness;
- private SerializedProperty video;
- private Mesh mesh;
- private Material mate;
- // private SerializedProperty scale;
- private XRVideoPlayer image3D;
- private Vector2 lastSize;
- // private Vector3 axis;
- [MenuItem("GameObject/XRUI/XRUIModel/XRVideoPlayer", priority = 0)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<XRVideoPlayer>(typeof(XRVideoPlayer).Name));
- obj.name = (typeof(XRVideoPlayer).Name);
- if (obj)
- {
- var parent = Selection.activeGameObject;
- if (!parent)
- {
- var canvas = GameObject.FindObjectsOfType(typeof(Canvas));
- if (canvas != null)
- {
- for (int i = 0; i < canvas.Length; i++)
- {
- if ((canvas[i] as Canvas).renderMode == RenderMode.WorldSpace)
- {
- parent = (canvas[i] as Canvas).gameObject;
- break;
- }
- }
- }
- }
- UnityUtil.SetParent(parent ? parent.transform : null, obj.transform);
- Selection.activeGameObject = obj.gameObject;
- }
- }
- protected void OnEnable()
- {
- // base.OnEnable();
- // return;
- image3D = target as XRVideoPlayer;
- isAutoScale = serializedObject.FindProperty("isAutoScale");
- thickness = serializedObject.FindProperty("thickness");
- // scale = serializedObject.FindProperty("scale");
- video = serializedObject.FindProperty("video");
- lastSize = image3D.RectTransform.rect.size;
- image3D.AutoSetSize();
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- // return;
- EditorGUILayout.PropertyField(isAutoScale, new GUIContent("等比缩放"));
- if (!image3D.isAutoScale)
- {
- EditorGUILayout.PropertyField(thickness, new GUIContent("厚度"));
- }
- mesh = (Mesh)EditorGUILayout.ObjectField("模型", mesh, typeof(Mesh));
- mate = (Material)EditorGUILayout.ObjectField("材质", mate, typeof(Material));
- EditorGUILayout.PropertyField(video, new GUIContent("视频"));
- //icon3D.img = (Texture2D)EditorGUILayout.ObjectField("Icon", icon3D.img, typeof(Texture2D));
- //EditorGUILayout.PropertyField(mesh, new GUIContent("mesh"));
- // EditorGUILayout.PropertyField(scale, new GUIContent("模型比例"));
- // axis = EditorGUILayout.Vector3Field("模型偏转角(暂不支持)", axis);
- serializedObject.ApplyModifiedProperties();
- if (image3D.RectTransform.rect.size != lastSize)
- {
- lastSize = image3D.RectTransform.rect.size;
- image3D.AutoSetSize();
- }
- if (GUI.changed)
- {
- if (image3D)
- {
- if (!image3D.isAutoScale)
- {
- image3D.SetThickness();
- }
- image3D.SetRenderMesh(mesh);
- image3D.SetRenderMate(mate);
- image3D.AutoSetSize();
- image3D.SetSimple();
- }
- }
- }
- }
- }
|