DlgEditor.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using XRTool.Util;
  5. namespace XRTool.UI
  6. {
  7. [InitializeOnLoad]
  8. [CustomEditor(typeof(Dlg))]
  9. public class DlgEditor : Editor
  10. {
  11. public SerializedProperty screenOrientation;
  12. public static RectTransform CanvasTranser;
  13. private void OnEnable()
  14. {
  15. screenOrientation = serializedObject.FindProperty("screenOrientation");
  16. }
  17. /// <summary>
  18. /// 重绘面板
  19. /// </summary>
  20. public override void OnInspectorGUI()
  21. {
  22. //serializedObject.Update();
  23. base.OnInspectorGUI();
  24. EditorGUILayout.PropertyField(screenOrientation, new GUIContent("横竖屏"));
  25. //EditorUtility.SetDirty(target);
  26. serializedObject.ApplyModifiedProperties();
  27. if (GUILayout.Button("自动调整横竖屏"))
  28. {
  29. Dlg dlg = target as Dlg;
  30. //GameSession.GameScreen.x = Screen.width;
  31. //GameSession.GameScreen.y = Screen.height;
  32. if (!CanvasTranser)
  33. {
  34. CanvasTranser = dlg.transform.parent.GetComponent<RectTransform>();
  35. GameSession.GameScreen = CanvasTranser.sizeDelta;
  36. UnityLog.Instance.Log(CanvasTranser);
  37. }
  38. else
  39. {
  40. GameSession.GameScreen = CanvasTranser.sizeDelta;
  41. UnityLog.Instance.Log(CanvasTranser);
  42. }
  43. UnityLog.Instance.Log(GameSession.GameScreen.ToString());
  44. if (GameSession.GameScreen.x > GameSession.GameScreen.y)
  45. {
  46. GameSession.deviceOrientation = DeviceOrientation.LandscapeLeft;
  47. }
  48. else
  49. {
  50. GameSession.deviceOrientation = DeviceOrientation.Portrait;
  51. }
  52. //if (dlg.isAutoSize)
  53. //{
  54. // dlg.UpdateLayout();
  55. //}
  56. dlg.OnScreenChangeAction(GameSession.deviceOrientation, GameSession.GameScreen);
  57. }
  58. }
  59. }
  60. }