//calculates the normalized value accroding to click position on slider to be set in the fillamount void UpdatePosition() { if (!j_Interactable.IsEnabled) { return; } if (j_Cursor == null) { j_Cursor = FindObjectOfType(typeof(JMRCursor)) as JMRCursor; } //Debug.Log("J raycast cam : " + j_RaycastCam); if (j_RaycastCam == null || !j_Cursor) { return; } //Vector3 point = eventData.position; //point.z = sliderFiller.transform.position.z; //Vector3 clickPoint = j_RaycastCam.ScreenToWorldPoint(point); Vector3 clickPoint = j_Cursor.Position; Vector3[] worldPoints = new Vector3[4]; sliderFiller.GetComponent <RectTransform>().GetWorldCorners(worldPoints); float normalizedValue = Mathf.InverseLerp(worldPoints[0].x, worldPoints[2].x, clickPoint.x); SliderValue = normalizedValue; if (updateSliderUIDirectly) { SliderValueUI = SliderValue; } OnValueUpdated?.Invoke(SliderValue); }
private void Start() { j_Interactable = GetComponent <JMRInteractable>(); if (j_Interactable) { j_Interactable.SwipeLeft += OnHorizontalSwipe; j_Interactable.SwipeRight += OnHorizontalSwipe; j_Interactable.SwipeUp += OnVerticalSwipe; j_Interactable.SwipeDown += OnVerticalSwipe; } else { throw new MissingComponentException("Interactable component missing from the object"); } if (JMRPointerManager.Instance != null) { j_RaycastCam = JMRPointerManager.Instance.UIRaycastCamera; } else { throw new MissingComponentException("Raycast Camera component missing from the Scene"); } j_SliderRect = GetComponent <RectTransform>(); j_SliderStartDistance = j_SliderRect.rect.xMin; j_SliderEndDistance = j_SliderRect.rect.xMax; InitializeSliderHandle(); OnValueUpdated?.Invoke(j_SliderValue); j_Cursor = FindObjectOfType(typeof(JMRCursor)) as JMRCursor; }