123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using UnityEngine;
- using UnityEditor.UI;
- using UnityEditor;
- using XRTool.Util;
- namespace XRTool.WorldUI
- {
- /// <summary>
- /// Image 3D
- /// </summary>
- [InitializeOnLoad]
- [CustomEditor(typeof(XRImage3D))]
- public class XRImage3DEditor : ImageEditor
- {
- private SerializedProperty isAutoScale;
- private SerializedProperty thickness;
- private SerializedProperty simple;
- private Mesh mesh;
- private Material mate;
- private SerializedProperty scale;
- private XRImage3D image3D;
- private Vector2 lastSize;
- private Vector3 axis;
- [MenuItem("GameObject/XRUI/XRUIModel/XRImage3D", priority = 0)]
- static void Init()
- {
- var obj = Instantiate(Resources.Load<XRImage3D>(typeof(XRImage3D).Name));
- obj.name = (typeof(XRImage3D).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 override void OnEnable()
- {
- base.OnEnable();
- image3D = target as XRImage3D;
- isAutoScale = serializedObject.FindProperty("isAutoScale");
- thickness = serializedObject.FindProperty("thickness");
- scale = serializedObject.FindProperty("scale");
- simple = serializedObject.FindProperty("simple");
- lastSize = image3D.rectTransform.rect.size;
- image3D.AutoSetSize();
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- 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(simple, 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();
- }
- }
- }
- }
- }
|