Exemple #1
0
        public WindowComponentNavigation NavigationFind(NavigationSide side, bool interactableOnly = false)
        {
            WindowComponentNavigation result = null;

            switch (side)
            {
            case NavigationSide.Left:
                result = this.GetNavigation(interactableOnly, WindowComponentNavigation.GetNavigationLeft_INTERNAL);
                break;

            case NavigationSide.Right:
                result = this.GetNavigation(interactableOnly, WindowComponentNavigation.GetNavigationRight_INTERNAL);
                break;

            case NavigationSide.Up:
                result = this.GetNavigation(interactableOnly, WindowComponentNavigation.GetNavigationUp_INTERNAL);
                break;

            case NavigationSide.Down:
                result = this.GetNavigation(interactableOnly, WindowComponentNavigation.GetNavigationDown_INTERNAL);
                break;
            }

            return(result);
        }
        private static void DrawNavigationArrow(Vector2 direction, IWindowNavigation fromObj, IWindowNavigation toObj)
        {
            if (fromObj == null || toObj == null)
            {
                return;
            }

            var fromTransform = fromObj.GetRectTransform();
            var toTransform   = toObj.GetRectTransform();

            Vector2 sideDir   = new Vector2(direction.y, -direction.x);
            Vector3 fromPoint = fromTransform.TransformPoint(WindowComponentNavigation.GetPointOnRectEdge(fromTransform, direction));
            Vector3 toPoint   = toTransform.TransformPoint(WindowComponentNavigation.GetPointOnRectEdge(toTransform, -direction));
            float   fromSize  = UnityEditor.HandleUtility.GetHandleSize(fromPoint) * 0.05f;
            float   toSize    = UnityEditor.HandleUtility.GetHandleSize(toPoint) * 0.05f;

            fromPoint += fromTransform.TransformDirection(sideDir) * fromSize;
            toPoint   += toTransform.TransformDirection(sideDir) * toSize;
            float   length      = Vector3.Distance(fromPoint, toPoint);
            Vector3 fromTangent = fromTransform.rotation * direction * length * 0.3f;
            Vector3 toTangent   = toTransform.rotation * -direction * length * 0.3f;

            UnityEditor.Handles.DrawBezier(fromPoint, toPoint, fromPoint + fromTangent, toPoint + toTangent, UnityEditor.Handles.color, null, kArrowThickness);
            UnityEditor.Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction - sideDir) * toSize * kArrowHeadSize);
            UnityEditor.Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction + sideDir) * toSize * kArrowHeadSize);
        }
        public bool NavigateSendEvents(WindowComponentNavigation source, NavigationSide side)
        {
            if (this.customContainer != null)
            {
                this.customContainer.NavigateSendEvents(this, side);

                if (this.customContainer.IsNavigationPreventChildEvents(side) == true)
                {
                    return(false);
                }
            }
            else
            {
                if (this.rootComponent != null && this.rootComponent is IWindowNavigation)
                {
                    var nav = (this.rootComponent as IWindowNavigation);
                    nav.NavigateSendEvents(this, side);

                    if (nav.IsNavigationPreventChildEvents(side) == true)
                    {
                        return(false);
                    }
                }
            }

            if (this.IsNavigationPreventEvents(side) == false)
            {
                if (this.IsNavigationControlSide(side) == true)
                {
                    this.OnNavigate(side);
                    this.OnNavigate(source, side);
                    this.NavigationScrollRect_INTERNAL(source, side);

                    switch (side)
                    {
                    case NavigationSide.Down:
                        this.OnNavigateDown();
                        break;

                    case NavigationSide.Up:
                        this.OnNavigateUp();
                        break;

                    case NavigationSide.Left:
                        this.OnNavigateLeft();
                        break;

                    case NavigationSide.Right:
                        this.OnNavigateRight();
                        break;
                    }
                }

                return(true);
            }

            return(false);
        }
        private void NavigationScrollRect_INTERNAL(WindowComponentNavigation source, NavigationSide side)
        {
            var scrollRect = this.NavigationScrollRect();

            if (scrollRect == null)
            {
                return;
            }

            var next = source.GetNavigation(side);

            if (next == null)
            {
                if (side == NavigationSide.Up)
                {
                    scrollRect.verticalNormalizedPosition = 1f;
                }
                else if (side == NavigationSide.Down)
                {
                    scrollRect.verticalNormalizedPosition = 0f;
                }
                else if (side == NavigationSide.Left)
                {
                    scrollRect.horizontalNormalizedPosition = 0f;
                }
                else if (side == NavigationSide.Right)
                {
                    scrollRect.horizontalNormalizedPosition = 1f;
                }
                return;
            }

            var containerRect = (scrollRect.transform as RectTransform).rect;
            var from          = RectTransformUtility.CalculateRelativeRectTransformBounds(this.GetRectTransform(), source.GetRectTransform());
            var to            = RectTransformUtility.CalculateRelativeRectTransformBounds(this.GetRectTransform(), next.GetRectTransform());
            var nextRect      = new Rect(to.center.XY(), to.size.XY());

            if (containerRect.Overlaps(nextRect) == true)
            {
                return;
            }

            var delta = (to.center - from.center).XY();

            if (side == NavigationSide.Left || side == NavigationSide.Right)
            {
                delta.y = 0f;
            }
            else
            {
                delta.x = 0f;
            }

            scrollRect.content.anchoredPosition    -= delta;
            scrollRect.horizontalNormalizedPosition = Mathf.Clamp01(scrollRect.horizontalNormalizedPosition);
            scrollRect.verticalNormalizedPosition   = Mathf.Clamp01(scrollRect.verticalNormalizedPosition);
        }
Exemple #5
0
        private void EditorFindVertical_INTERNAL(bool inverse)
        {
            WindowComponentNavigation prev = null;
            WindowComponentNavigation next = null;

            var root = this.transform.parent;

            for (int i = 0; i < root.childCount; ++i)
            {
                var child = root.GetChild(i);
                var nav   = child.GetComponent <WindowComponentNavigation>();
                if (nav == null)
                {
                    continue;
                }

                if (i > 0)
                {
                    prev = root.GetChild(i - 1).GetComponent <WindowComponentNavigation>();
                }
                else
                {
                    prev = null;
                }

                if (i < root.childCount - 1)
                {
                    next = root.GetChild(i + 1).GetComponent <WindowComponentNavigation>();
                }
                else
                {
                    next = null;
                }

                var navigation = nav.navigation;
                navigation.childIndex = i;
                if (inverse == true)
                {
                    navigation.up   = next;
                    navigation.down = prev;
                }
                else
                {
                    navigation.up   = prev;
                    navigation.down = next;
                }
                nav.navigation = navigation;
            }
        }
        private static void DrawNavigationForSelectable(IWindowNavigation sel)
        {
            if (sel == null)
            {
                return;
            }

            var  transform = sel.GetRectTransform();
            bool active    = UnityEditor.Selection.transforms.Any(e => e == transform);

            UnityEditor.Handles.color = new Color(1.0f, 0.9f, 0.1f, active ? 1.0f : 0.4f);

            WindowComponentNavigation.DrawNavigationArrow(-Vector2.right, sel, sel.NavigationFindLeft());
            WindowComponentNavigation.DrawNavigationArrow(Vector2.right, sel, sel.NavigationFindRight());
            WindowComponentNavigation.DrawNavigationArrow(Vector2.up, sel, sel.NavigationFindUp());
            WindowComponentNavigation.DrawNavigationArrow(-Vector2.up, sel, sel.NavigationFindDown());
        }
        private void OnDrawGUI_EDITOR(bool selected, bool selectedHierarchy)
        {
            this.ValidateItemsEditor();

            /*ME.EditorUtilities.BeginDraw();
             *
             * var scale = 1f;
             * var canvas = this.GetComponentsInParent<Canvas>().FirstOrDefault((c) => c.isRootCanvas);
             * if (canvas != null) scale = canvas.transform.localScale.x;
             *
             * var arrowsSize = 80f * scale;
             * if (this.navigation.left != null) ME.EditorUtilities.DrawArrow(Color.white, this.transform.position, this.navigation.left.transform.position, arrowsSize);
             * if (this.navigation.right != null) ME.EditorUtilities.DrawArrow(Color.white, this.transform.position, this.navigation.right.transform.position, arrowsSize);
             * if (this.navigation.up != null) ME.EditorUtilities.DrawArrow(Color.white, this.transform.position, this.navigation.up.transform.position, arrowsSize);
             * if (this.navigation.down != null) ME.EditorUtilities.DrawArrow(Color.white, this.transform.position, this.navigation.down.transform.position, arrowsSize);
             *
             * ME.EditorUtilities.EndDraw();*/

            WindowComponentNavigation.DrawNavigationForSelectable(this);
        }
Exemple #8
0
 private static WindowComponentNavigation GetNavigationDown_INTERNAL(WindowComponentNavigation nav)
 {
     return(nav.navigation.down);
 }
Exemple #9
0
 private static WindowComponentNavigation GetNavigationUp_INTERNAL(WindowComponentNavigation nav)
 {
     return(nav.navigation.up);
 }
Exemple #10
0
 private static WindowComponentNavigation GetNavigationRight_INTERNAL(WindowComponentNavigation nav)
 {
     return(nav.navigation.right);
 }
Exemple #11
0
 private static WindowComponentNavigation GetNavigationLeft_INTERNAL(WindowComponentNavigation nav)
 {
     return(nav.navigation.left);
 }
		public virtual void OnNavigate(WindowComponentNavigation source, NavigationSide side) {}
		public bool NavigateSendEvents(WindowComponentNavigation source, NavigationSide side) {
			
			if (this.listContainer != null) {

				this.listContainer.NavigateSendEvents(this, side);

				if (this.listContainer.IsNavigationPreventChildEvents(side) == true) {

					return false;

				}

			} else {

				if (this.rootComponent != null && this.rootComponent is IWindowNavigation) {

					var nav = (this.rootComponent as IWindowNavigation);
					nav.NavigateSendEvents(this, side);

					if (nav.IsNavigationPreventChildEvents(side) == true) {

						return false;

					}

				}

			}

			if (this.IsNavigationControlledSide(side) == true) {

				this.OnNavigate(side);
				this.OnNavigate(source, side);

				switch (side) {

					case NavigationSide.Down:
						this.OnNavigateDown();
						break;

					case NavigationSide.Up:
						this.OnNavigateUp();
						break;

					case NavigationSide.Left:
						this.OnNavigateLeft();
						break;

					case NavigationSide.Right:
						this.OnNavigateRight();
						break;

				}

			}

			return true;

		}
        public WindowComponentNavigation FindSelectable(Vector3 dir, NavigationSideInfo sideInfo, bool pointOnEdge = true)
        {
            if (sideInfo.stop == true)
            {
                return(null);
            }

            var navGroup = this.GetNavigationGroup();

            if (navGroup == null)
            {
                return(null);
            }

            dir = dir.normalized;
            var tr       = this.transform as RectTransform;
            var localDir = Quaternion.Inverse(tr.rotation) * dir;
            var pos      = tr.TransformPoint(pointOnEdge == true ? WindowComponentNavigation.GetPointOnRectEdge(tr, localDir) : (Vector3)tr.rect.center);
            var maxScore = Mathf.NegativeInfinity;

            var components = navGroup.GetNavigationComponents();

            WindowComponentNavigation bestPick = null;

            for (int i = 0; i < components.Count; ++i)
            {
                var sel = components[i] as WindowComponentNavigation;
                if (sel == this || sel == null)
                {
                    continue;
                }

                var selInteractable = sel as IInteractableStateComponent;
                if (selInteractable != null)
                {
                    if (selInteractable.GetNavigationType() == NavigationType.None ||
                        (
                            selInteractable.IsNavigateOnDisabled() == false &&
                            selInteractable.IsVisible() == false
                        ) ||
                        (
                            selInteractable.IsNavigateOnDisabled() == false &&
                            selInteractable.IsInteractable() == false
                        ))
                    {
                        continue;
                    }
                }
                else
                {
                    if (sel.GetNavigationType() == NavigationType.None ||
                        sel.IsVisible() == false)
                    {
                        continue;
                    }
                }

                var selRect   = sel.GetRectTransform();
                var selCenter = selRect != null?selRect.rect.center.XY() : Vector3.zero;

                var myVector = selRect.TransformPoint(selCenter) - pos;

                if (sideInfo.directionAxisOnly == true)
                {
                    if (dir.x == 0f)
                    {
                        myVector.x = 0f;
                    }
                    if (dir.y == 0f)
                    {
                        myVector.y = 0f;
                    }
                }

                var dot = Vector3.Dot(dir, myVector);
                if (dot <= 0f)
                {
                    continue;
                }

                var score = dot / myVector.sqrMagnitude;
                if (score > maxScore)
                {
                    maxScore = score;
                    bestPick = sel;
                }
            }

            return(bestPick);
        }
 public virtual void OnNavigate(WindowComponentNavigation source, NavigationSide side)
 {
 }