using UnityEngine;
using UnityEditor.UI;
using UnityEditor;
using XRTool.Util;
namespace XRTool.WorldUI
{
///
/// Image 3D
///
[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(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();
}
}
}
}
}