Removed TOTU 103
This commit is contained in:
		
							
								
								
									
										37
									
								
								Assets/Common/Scripts/SliderToggle.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Assets/Common/Scripts/SliderToggle.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| // Copyright 2022-2024 Niantic. | ||||
| using System; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
|  | ||||
| public class SliderToggle : Toggle | ||||
| { | ||||
|     [SerializeField] private RectTransform uiHandleRectTransform; | ||||
|  | ||||
|     private Vector2 _handlePosition; | ||||
|  | ||||
|     protected override void Awake() | ||||
|     { | ||||
|         _handlePosition = uiHandleRectTransform.anchoredPosition; | ||||
|  | ||||
|         onValueChanged.AddListener(OnSwitch); | ||||
|         if (isOn) | ||||
|         { | ||||
|             OnSwitch(true); | ||||
|         } | ||||
|  | ||||
|         base.Awake(); | ||||
|     } | ||||
|  | ||||
|     private void OnSwitch(bool on) | ||||
|     { | ||||
|         var Xvalue = on ? Math.Abs(_handlePosition.x) : Math.Abs(_handlePosition.x) * -1; | ||||
|         _handlePosition = new Vector2(Xvalue, _handlePosition.y); | ||||
|  | ||||
|         uiHandleRectTransform.anchoredPosition = _handlePosition; | ||||
|     } | ||||
|     protected override void OnDestroy() | ||||
|     { | ||||
|         onValueChanged.RemoveListener(OnSwitch); | ||||
|         base.OnDestroy(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Ignacio Gómez Puga
					Ignacio Gómez Puga