//---------------------------------------------------------------------- public TreeView( Screen _screen ) : base(_screen) { Nodes = new ObservableList<TreeViewNode>(); Nodes.ListCleared += delegate { SelectedNode = null; HoveredNode = null; FocusedNode = null; mHoveredActionButton = null; mbIsHoveredActionButtonDown = false; }; Nodes.ListChanged += delegate( object _source, ObservableList<TreeViewNode>.ListChangedEventArgs _args ) { if( ! _args.Added ) { if( _args.Item == SelectedNode ) { SelectedNode = null; } if( _args.Item == HoveredNode ) { UpdateHoveredNode(); } if( _args.Item == FocusedNode ) { FocusedNode = null; IsDragging = false; } } }; Scrollbar = new UI.Scrollbar( _screen ); Scrollbar.Parent = this; ActionButtons = new List<Button>(); }
/// <summary> /// Process move navigation (touch) /// </summary> private bool SendTouchEventToSelectedObject() { Vector2 movement = Vector2.zero; Vector2 movementThreshold = Vector2.zero; if (EventSystem.current.currentSelectedGameObject == null) { return(false); } if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.Scrollbar>() != null) { currentScrollbar = EventSystem.current.currentSelectedGameObject.GetComponent <UI.Scrollbar>(); currentSlider = null; if (currentScrollbar.direction == UI.Scrollbar.Direction.LeftToRight || currentScrollbar.direction == UI.Scrollbar.Direction.RightToLeft) { movementThreshold.x = scrollAmount * 4f; movementThreshold.y = EasyInputHelper.mInstance.requiredSwipeLength; } else { movementThreshold.x = EasyInputHelper.mInstance.requiredSwipeLength; movementThreshold.y = scrollAmount * 4f; } } else if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>() != null) { if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().verticalScrollbar != null && EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().horizontalScrollbar != null) { //if we have both scrollbars we'd have an issue with controllers. directions would be taken up by scrolling //and no directions would be left to navigate to other UI objects. When this is the case we scroll the //vertical only since it's much more common currentScrollbar = EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().verticalScrollbar; } else if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().verticalScrollbar != null) { currentScrollbar = EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().verticalScrollbar; } else if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().horizontalScrollbar != null) { currentScrollbar = EventSystem.current.currentSelectedGameObject.GetComponent <UI.ScrollRect>().horizontalScrollbar; } else { currentScrollbar = null; } currentSlider = null; if (currentScrollbar != null) { if (currentScrollbar.direction == UI.Scrollbar.Direction.LeftToRight || currentScrollbar.direction == UI.Scrollbar.Direction.RightToLeft) { movementThreshold.x = scrollAmount * 4f; movementThreshold.y = EasyInputHelper.mInstance.requiredSwipeLength; } else { movementThreshold.x = EasyInputHelper.mInstance.requiredSwipeLength; movementThreshold.y = scrollAmount * 4f; } } } else if (EventSystem.current.currentSelectedGameObject.GetComponent <UI.Slider>() != null) { currentSlider = EventSystem.current.currentSelectedGameObject.GetComponent <UI.Slider>(); currentScrollbar = null; if (currentSlider.direction == UI.Slider.Direction.LeftToRight || currentSlider.direction == UI.Slider.Direction.RightToLeft) { movementThreshold.x = scrollAmount * 4f; movementThreshold.y = EasyInputHelper.mInstance.requiredSwipeLength; } else { movementThreshold.x = EasyInputHelper.mInstance.requiredSwipeLength; movementThreshold.y = scrollAmount * 4f; } } else { currentScrollbar = null; currentSlider = null; movementThreshold.x = EasyInputHelper.mInstance.requiredSwipeLength; movementThreshold.y = EasyInputHelper.mInstance.requiredSwipeLength; } //touch (here we're simulating the nice Apple UI with swipe naviagtion) //we are essentially going to keep track of the touch and fire off a 1 value only when the swipe //threshold has been reached if (touchpad.currentTouchPosition != EasyInputConstants.NOT_TOUCHING) { movement = touchpad.currentTouchPosition - touchpad.originalTouchPosition; //horizontal if (movement.x > movementThreshold.x * rightStepsFired) { movement.x = 1; rightStepsFired++; if (currentScrollbar != null || currentSlider != null) { movement.x = scrollSpeedMultiplier; rightStepsFired += (scrollSpeedMultiplier - 1); } } else if (movement.x < -movementThreshold.x * leftStepsFired) { movement.x = -1; leftStepsFired++; if (currentScrollbar != null || currentSlider != null) { movement.x = -scrollSpeedMultiplier; leftStepsFired += (scrollSpeedMultiplier - 1); } } else { movement.x = 0; } //vertical if (movement.y > movementThreshold.y * upStepsFired) { movement.y = 1; upStepsFired++; if (currentScrollbar != null || currentSlider != null) { movement.y = scrollSpeedMultiplier; upStepsFired += (scrollSpeedMultiplier - 1); } } else if (movement.y < -movementThreshold.y * downStepsFired) { movement.y = -1; downStepsFired++; if (currentScrollbar != null || currentSlider != null) { movement.y = -scrollSpeedMultiplier; downStepsFired += (scrollSpeedMultiplier - 1); } } else { movement.y = 0; } } if (currentScrollbar != null) { if (currentScrollbar.direction == UI.Scrollbar.Direction.LeftToRight) { currentScrollbar.value += scrollAmount * movement.x; movement.x = 0; } else if (currentScrollbar.direction == UI.Scrollbar.Direction.RightToLeft) { currentScrollbar.value += -scrollAmount * movement.x; movement.x = 0; } else if (currentScrollbar.direction == UI.Scrollbar.Direction.TopToBottom) { currentScrollbar.value += -scrollAmount * movement.y; movement.y = 0; } else if (currentScrollbar.direction == UI.Scrollbar.Direction.BottomToTop) { currentScrollbar.value += scrollAmount * movement.y; movement.y = 0; } } if (currentSlider != null) { if (currentSlider.direction == UI.Slider.Direction.LeftToRight) { currentSlider.value += scrollAmount * movement.x; movement.x = 0; } else if (currentSlider.direction == UI.Slider.Direction.RightToLeft) { currentSlider.value += -scrollAmount * movement.x; movement.x = 0; } else if (currentSlider.direction == UI.Slider.Direction.TopToBottom) { currentSlider.value += -scrollAmount * movement.y; movement.y = 0; } else if (currentSlider.direction == UI.Slider.Direction.BottomToTop) { currentSlider.value += scrollAmount * movement.y; movement.y = 0; } } var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f); if (!Mathf.Approximately(axisEventData.moveVector.x, 0f) || !Mathf.Approximately(axisEventData.moveVector.y, 0f)) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); } return(axisEventData.used); }
// Use this for initialization void Start() { scrollbar = GetComponent <UI.Scrollbar>(); }