SettingsDlg.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using BeinLab.Util;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using XRTool.Util;
  8. using XRTool.WorldUI;
  9. namespace XRTool.UI
  10. {
  11. /// <summary>
  12. /// 窗口管理面板
  13. /// </summary>
  14. public class SettingsDlg : MonoBehaviour
  15. {
  16. public bool isDelOnClose = false;
  17. private Button closeButton;
  18. private ToggleButton lockButton;
  19. private ToggleButton transferButton;
  20. private WorldDlg dlg;
  21. private void Start()
  22. {
  23. dlg = GetComponentInParent<WorldDlg>();
  24. if (dlg)
  25. {
  26. closeButton = UnityUtil.GetBreadthChild<Button>(transform, "CloseButton");
  27. lockButton = UnityUtil.GetBreadthChild<ToggleButton>(transform, "LockButton");
  28. transferButton = UnityUtil.GetBreadthChild<ToggleButton>(transform, "TransferButton");
  29. closeButton.onClick.AddListener(() => { dlg.Close(isDelOnClose); });
  30. lockButton.OnValueChanged += OnLockValueChanged;
  31. transferButton.OnValueChanged += OnTransferValueChanged;
  32. if (lockButton.isActiveAndEnabled)
  33. {
  34. TimerMgr.Instance.CreateTimer(() =>
  35. {
  36. OnLockValueChanged(lockButton.isOn);
  37. }, 0.02f);
  38. }
  39. if (transferButton.isActiveAndEnabled)
  40. {
  41. TimerMgr.Instance.CreateTimer(() =>
  42. {
  43. OnTransferValueChanged(transferButton.isOn);
  44. }, 0.02f);
  45. }
  46. }
  47. }
  48. private void OnEnable()
  49. {
  50. if (lockButton && lockButton.isActiveAndEnabled)
  51. {
  52. OnLockValueChanged(lockButton.isOn);
  53. }
  54. if (transferButton && transferButton.isActiveAndEnabled)
  55. {
  56. OnTransferValueChanged(transferButton.isOn);
  57. }
  58. }
  59. private void OnDestroy()
  60. {
  61. if (lockButton)
  62. {
  63. lockButton.OnValueChanged -= OnLockValueChanged;
  64. }
  65. if (transferButton)
  66. {
  67. transferButton.OnValueChanged -= OnTransferValueChanged;
  68. }
  69. }
  70. private void OnTransferValueChanged(bool obj)
  71. {
  72. if (dlg)
  73. {
  74. dlg.IsDragEnable = obj;
  75. }
  76. }
  77. private void OnLockValueChanged(bool obj)
  78. {
  79. if (dlg)
  80. {
  81. dlg.IsFaceLock = obj;
  82. }
  83. }
  84. }
  85. }