XRToggle.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using DG.Tweening;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using XRTool.Util;
  8. namespace XRTool.WorldUI
  9. {
  10. public class XRToggle : Toggle
  11. {
  12. private GameObject checkXRIcon3D;
  13. /// <summary>
  14. /// 是否隐藏取消框
  15. /// </summary>
  16. public bool isHideCheck = true;
  17. public Vector3 openPos = Vector3.right;
  18. public float moveTime = 0.3f;
  19. private Vector3 initPos = Vector3.zero;
  20. public bool isSwitch;
  21. public GameObject CheckXRIcon3D
  22. {
  23. get
  24. {
  25. if (!checkXRIcon3D)
  26. {
  27. checkXRIcon3D = UnityUtil.GetBreadthChild(transform, "CheckXRIcon3D");
  28. initPos = checkXRIcon3D.transform.localPosition;
  29. }
  30. return checkXRIcon3D;
  31. }
  32. }
  33. protected override void Awake()
  34. {
  35. base.Awake();
  36. initListen();
  37. }
  38. public void initListen()
  39. {
  40. if (CheckXRIcon3D) { }
  41. onValueChanged.RemoveListener(OnToggleChanged);
  42. onValueChanged.AddListener(OnToggleChanged);
  43. }
  44. protected override void OnDestroy()
  45. {
  46. base.OnDestroy();
  47. onValueChanged.RemoveAllListeners();
  48. }
  49. public virtual void OnToggleChanged(bool isOn)
  50. {
  51. if (CheckXRIcon3D)
  52. {
  53. CheckXRIcon3D.SetActive(isOn);
  54. }
  55. }
  56. }
  57. }