using System; using UnityEditor; using UnityEngine; using XRTool.Util; namespace XRTool.UI { [InitializeOnLoad] [CustomEditor(typeof(Dlg))] public class DlgEditor : Editor { public SerializedProperty screenOrientation; public static RectTransform CanvasTranser; private void OnEnable() { screenOrientation = serializedObject.FindProperty("screenOrientation"); } /// /// 重绘面板 /// public override void OnInspectorGUI() { //serializedObject.Update(); base.OnInspectorGUI(); EditorGUILayout.PropertyField(screenOrientation, new GUIContent("横竖屏")); //EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); if (GUILayout.Button("自动调整横竖屏")) { Dlg dlg = target as Dlg; //GameSession.GameScreen.x = Screen.width; //GameSession.GameScreen.y = Screen.height; if (!CanvasTranser) { CanvasTranser = dlg.transform.parent.GetComponent(); GameSession.GameScreen = CanvasTranser.sizeDelta; UnityLog.Instance.Log(CanvasTranser); } else { GameSession.GameScreen = CanvasTranser.sizeDelta; UnityLog.Instance.Log(CanvasTranser); } UnityLog.Instance.Log(GameSession.GameScreen.ToString()); if (GameSession.GameScreen.x > GameSession.GameScreen.y) { GameSession.deviceOrientation = DeviceOrientation.LandscapeLeft; } else { GameSession.deviceOrientation = DeviceOrientation.Portrait; } //if (dlg.isAutoSize) //{ // dlg.UpdateLayout(); //} dlg.OnScreenChangeAction(GameSession.deviceOrientation, GameSession.GameScreen); } } } }