public VRUIScrollableSetup(EUIDirection dir, float minVal = 0.0f, float maxVal = 1.0f, bool wholeNum = false) { _direction = dir; _minValue = minVal; _maxValue = maxVal; _wholeNumbers = wholeNum; }
/// <summary> /// Check the BoxCollider size and make it fit the Scrollable UI Element according to its direction /// </summary> /// <param name="box">The box collider to set</param> /// <param name="rt">The rect transform of the ui element</param> /// <param name="direction">The direction of the scrollable, given as a UIDirection</param> /// <returns>The new BoxCOllider after being set</returns> public BoxCollider CheckBoxColliderSize(BoxCollider box, RectTransform rt, EUIDirection direction) { switch (direction) { case (EUIDirection.TopToBottom): box.size = new Vector3(rt.rect.width, rt.rect.height, 0.0001f); box.center = new Vector3(0.0f, rt.rect.height / 2, 0.0f); break; case (EUIDirection.BottomToTop): box.size = new Vector3(rt.rect.width, rt.rect.height, 0.0001f); box.center = new Vector3(0.0f, -rt.rect.height / 2, 0.0f); break; case (EUIDirection.RightToLeft): box.size = new Vector3(rt.rect.width, rt.rect.height, 0.0001f); box.center = new Vector3(0.0f, 0, 0.0f); break; case (EUIDirection.LeftToRight): box.size = new Vector3(rt.rect.width, rt.rect.height, 0.0001f); box.center = new Vector3(0.0f, 0, 0.0f); break; } return(box); }
private void SetupVRScrollRect() { _scrollableSetup = new VRUIScrollableSetup(Direction); // We setup the references to the ScrollRect elements SetScrollRectReferences(); // We override the directio selected in the inspector by the scrollbar direction if we use one // The vertical direction will always have top priority on the horizontal direction if (vertical && verticalScrollbar != null) { Direction = UnityUIToVRDFUI.ScrollbarDirectionToUIDirection(verticalScrollbar.direction); verticalScrollbar.onValueChanged.AddListener(delegate { OnValueChangedCallback(); }); } else if (horizontal && horizontalScrollbar != null) { Direction = UnityUIToVRDFUI.ScrollbarDirectionToUIDirection(horizontalScrollbar.direction); horizontalScrollbar.onValueChanged.AddListener(delegate { OnValueChangedCallback(); }); } OnVRClickerStartClicking.Listeners += CheckClickedObject; OnVRClickerStopClicking.Listeners += CheckUnclickedObject; // We setup the Min and Max pos transform _scrollableSetup.CheckMinMaxGameObjects(transform, Direction, ref _minPosBar, ref _maxPosBar); _scrollableSetup.CheckContentStatus(viewport, content); }
/// <summary> /// Check if the MinPos and MaxPos of the element are correctly instantiated and Check there RectTransform /// </summary> /// <param name="handleRectParent">The parent of the HandleRect</param> /// <param name="direction">The UIDirection of the element</param> public void CheckMinMaxGameObjects(Transform handleRectParent, EUIDirection direction) { RectTransform minPosRect; RectTransform maxPosRect; if (handleRectParent.Find("MinPos") == null) { minPosRect = InstantiateNewPosObject("MinPos", handleRectParent); } else { minPosRect = handleRectParent.Find("MinPos").GetComponent <RectTransform>(); } if (handleRectParent.Find("MaxPos") == null) { maxPosRect = InstantiateNewPosObject("MaxPos", handleRectParent); } else { maxPosRect = handleRectParent.Find("MaxPos").GetComponent <RectTransform>(); } if (direction == EUIDirection.BottomToTop || direction == EUIDirection.TopToBottom) { CheckRectTrans(ref minPosRect, new Vector2(0.5f, 1.0f)); CheckRectTrans(ref maxPosRect, new Vector2(0.5f, 0.0f)); } else { CheckRectTrans(ref minPosRect, new Vector2(1.0f, 0.5f)); CheckRectTrans(ref maxPosRect, new Vector2(0.0f, 0.5f)); } }
private void Init(OnSetupVRReady _) { if (VRSF_Components.DeviceLoaded != EDevice.SIMULATOR) { // We setup the references to the ScrollRect elements SetScrollRectReferences(); // We override the directio selected in the inspector by the scrollbar direction if we use one // The vertical direction will always have top priority on the horizontal direction if (vertical && verticalScrollbar != null) { Direction = UnityUIToVRSFUI.ScrollbarDirectionToUIDirection(verticalScrollbar.direction); verticalScrollbar.onValueChanged.AddListener(delegate { OnValueChangedCallback(); }); } else if (horizontal && horizontalScrollbar != null) { Direction = UnityUIToVRSFUI.ScrollbarDirectionToUIDirection(horizontalScrollbar.direction); horizontalScrollbar.onValueChanged.AddListener(delegate { OnValueChangedCallback(); }); } ObjectWasClickedEvent.Listeners += CheckRectClick; _eventWereRegistered = true; // We setup the Min and Max pos transform _scrollableSetup.CheckMinMaxGameObjects(transform, Direction, ref _minPosBar, ref _maxPosBar); } }
// EMPTY #region PUBLIC_METHODS #endregion #region PRIVATE_METHODS private void MakeBasicSetup() { // We initialize the _ListenersDictionary _ListenersDictionary = new Dictionary <string, GameEventListenerTransform> { { "Right", null }, { "Left", null }, { "Gaze", null }, }; // We override the directio selected in the inspector by the scrollbar direction if we use one // The vertical direction will always have top priority on the horizontal direction if (vertical && verticalScrollbar.gameObject != null) { Direction = UnityUIToVRSFUI.ScrollbarDirectionToUIDirection(verticalScrollbar.direction); } else if (horizontal && horizontalScrollbar.gameObject != null) { Direction = UnityUIToVRSFUI.ScrollbarDirectionToUIDirection(horizontalScrollbar.direction); } // We create new object to setup the button references; listeners and GameEventListeners _CheckObject = CheckRectClick; _UISetup = new VRUISetup(_CheckObject); _ClickOnlySetup = new VRScrollbarSetup(); _ScrollableSetup = new VRUIScrollableSetup(Direction); // Check if the Listeners GameObject is set correctly. If not, create the child if (!_ClickOnlySetup.CheckGameEventListenerChild(ref _GameEventListenersContainer, ref _ListenersDictionary, transform)) { _UISetup.CreateGameEventListenerChild(ref _GameEventListenersContainer, transform); } if (!_boxColliderSetup && gameObject.activeInHierarchy) { // We setup the BoxCollider size and center StartCoroutine(SetupBoxCollider()); } // We setup the references to the ScrollRect elements SetScrollRectReferences(); }