12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using DG.Tweening;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- namespace XRTool.WorldUI
- {
- public class XRToggle : Toggle
- {
- private GameObject checkXRIcon3D;
- /// <summary>
- /// 是否隐藏取消框
- /// </summary>
- public bool isHideCheck = true;
- public Vector3 openPos = Vector3.right;
- public float moveTime = 0.3f;
- private Vector3 initPos = Vector3.zero;
- public bool isSwitch;
- public GameObject CheckXRIcon3D
- {
- get
- {
- if (!checkXRIcon3D)
- {
- checkXRIcon3D = UnityUtil.GetBreadthChild(transform, "CheckXRIcon3D");
- initPos = checkXRIcon3D.transform.localPosition;
- }
- return checkXRIcon3D;
- }
- }
- protected override void Awake()
- {
- base.Awake();
- initListen();
- }
- public void initListen()
- {
- if (CheckXRIcon3D) { }
- onValueChanged.RemoveAllListeners();
- onValueChanged.AddListener(OnToggleChanged);
- }
- protected override void OnDestroy()
- {
- base.OnDestroy();
- onValueChanged.RemoveAllListeners();
- }
- public virtual void OnToggleChanged(bool isOn)
- {
- if (CheckXRIcon3D)
- {
- if (isHideCheck)
- {
- CheckXRIcon3D.SetActive(isOn);
- return;
- }
- CheckXRIcon3D.transform.DOKill();
- Vector3 target = initPos;
- if (isOn)
- {
- target = openPos;
- }
- CheckXRIcon3D.transform.DOLocalMove(target, moveTime);
- }
- }
- }
- }
|