1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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");
- }
- /// <summary>
- /// 重绘面板
- /// </summary>
- 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<RectTransform>();
- 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);
- }
- }
- }
- }
|