public void MakeTransitionProgrammatically(ManagementView.SwipeResultAction action)
 {
     if (action == ManagementView.SwipeResultAction.MoveToLeft)
     {
         SwipeData swipeData = new SwipeData()
         {
             Direction     = SwipeDirection.Left,
             EndPosition   = new Vector2(-10, 0),
             StartPosition = new Vector2(0, 0),
             IsEnd         = false
         };
         isDragStarted = false;
         DragCurrentTransform(swipeData);
         Transition(action);
     }
     else if (action == ManagementView.SwipeResultAction.MoveToRight)
     {
         SwipeData swipeData = new SwipeData()
         {
             Direction     = SwipeDirection.Right,
             EndPosition   = new Vector2(0, 0),
             StartPosition = new Vector2(10, 0),
             IsEnd         = false
         };
         isDragStarted = false;
         DragCurrentTransform(swipeData);
         Transition(action);
     }
 }
示例#2
0
 private void OnSwipe(SwipeData data)
 {
     if (isSwipeEnabled && IsModelValidForSwipe)
     {
         if (!data.IsEnd)
         {
             if (!isSwiped)
             {
                 isSwiped        = true;
                 startSwipePoint = data.StartPosition;
                 //Debug.Log("start wait..");
             }
             else
             {
                 //Debug.Log("swipe continue..");
                 Vector2 currentPosition = data.EndPosition;
                 float   delta           = currentPosition.x - startSwipePoint.x;
                 float   sign            = Mathf.Sign(delta);
                 if (sign > 0)
                 {
                     moduleView.LerpPart(currentModule.Id, GetNormalizedOffset(delta));
                 }
                 else if (sign < 0)
                 {
                     moduleView.LerpPart(currentModule.Id + 1, GetNormalizedOffset(delta));
                 }
             }
         }
         else
         {
             //Debug.Log("end swipe");
             isSwiped      = false;
             endSwipePoint = data.EndPosition;
             Vector2 offset = endSwipePoint - startSwipePoint;
             if (offset.x > swipeDistance)
             {
                 if (currentModule.Id == 0)
                 {
                     currentSwipeAction = ManagementView.SwipeResultAction.ReturnToCenter;
                 }
                 else
                 {
                     currentSwipeAction = ManagementView.SwipeResultAction.MoveToRight;
                 }
             }
             else if (offset.x < -swipeDistance)
             {
                 currentSwipeAction = ManagementView.SwipeResultAction.MoveToLeft;
             }
             else
             {
                 currentSwipeAction = ManagementView.SwipeResultAction.ReturnToCenter;
             }
         }
     }
 }
        private Vector2 GetTargetPointForCurrentRect(ManagementView.SwipeResultAction transitionAction)
        {
            switch (transitionAction)
            {
            case ManagementView.SwipeResultAction.MoveToLeft: {
                return(-HORIZONTAL_VECTOR);
            }

            case ManagementView.SwipeResultAction.MoveToRight: {
                return(HORIZONTAL_VECTOR);
            }

            default: {
                return(Vector2.zero);
            }
            }
        }
示例#4
0
        public override void Update()
        {
            base.Update();

            if (IsModelValidForSwipe)
            {
                if (isSwipeEnabled)
                {
                    if (!isSwiped)
                    {
                        if (currentSwipeAction != ManagementView.SwipeResultAction.None)
                        {
                            Finalize(currentSwipeAction);
                            currentSwipeAction = ManagementView.SwipeResultAction.None;
                        }
                    }
                }
            }
        }
示例#5
0
        private void Finalize(ManagementView.SwipeResultAction action)
        {
            switch (action)
            {
            case ManagementView.SwipeResultAction.ReturnToCenter: {
                moduleView.Setup(currentModule);
            }
            break;

            case ManagementView.SwipeResultAction.MoveToLeft: {
                if (HasRightModule)
                {
                    Setup(new ViewData {
                            UserData = new ModuleViewModel
                            {
                                ScreenType = ModuleScreenType.Normal,
                                ModuleId   = currentModule.Id + 1
                            }
                        });
                }
            }
            break;

            case ManagementView.SwipeResultAction.MoveToRight: {
                if (HasLeftModule)
                {
                    Setup(new ViewData {
                            UserData = new ModuleViewModel
                            {
                                ScreenType = ModuleScreenType.Normal,
                                ModuleId   = currentModule.Id - 1
                            }
                        });
                }
            }
            break;
            }
        }
示例#6
0
        private void Finalize(ManagementView.SwipeResultAction action)
        {
            switch (action)
            {
            case ManagementView.SwipeResultAction.ReturnToCenter: {
                if (HasLeft(CurrentData))
                {
                    if (swipedTransforms.Count > 0)
                    {
                        cache.PushObject(swipedTransforms[0].gameObject);
                    }
                }
                if (HasRight(CurrentData))
                {
                    if (swipedTransforms.Count > 0)
                    {
                        cache.PushObject(swipedTransforms[swipedTransforms.Count - 1].gameObject);
                    }
                }
                swipedTransforms.Clear();
            }
            break;

            case ManagementView.SwipeResultAction.MoveToLeft: {
                if (HasLeft(CurrentData))
                {
                    cache.PushObject(swipedTransforms[0].gameObject);
                    cache.PushObject(swipedTransforms[1].gameObject);
                    var rightData = RightData(CurrentData);
                    var rightView = ChangeCurrentRect(swipedTransforms[2]);
                    Resetup(rightData, rightView);
                    ActiveViewChanged?.Invoke(CurrentView);
                    swipedTransforms.Clear();
                }
                else
                {
                    cache.PushObject(swipedTransforms[0].gameObject);
                    var rightData = RightData(CurrentData);
                    var rightRect = ChangeCurrentRect(swipedTransforms[1]);
                    Resetup(rightData, rightRect);
                    swipedTransforms.Clear();
                }
            }
            break;

            case ManagementView.SwipeResultAction.MoveToRight: {
                if (HasRight(CurrentData))
                {
                    cache.PushObject(swipedTransforms[2].gameObject);
                    cache.PushObject(swipedTransforms[1].gameObject);
                    var leftData = LeftData(CurrentData);
                    var leftRect = ChangeCurrentRect(swipedTransforms[0]);

                    Resetup(leftData, leftRect);
                    swipedTransforms.Clear();
                }
                else
                {
                    cache.PushObject(swipedTransforms[1].gameObject);
                    var leftData = LeftData(CurrentData);
                    var leftRect = ChangeCurrentRect(swipedTransforms[0]);
                    Resetup(leftData, leftRect);
                    swipedTransforms.Clear();
                }
            }
            break;
            }
        }
        private void Transition(ManagementView.SwipeResultAction transitionAction)
        {
            if (currentRect == null)
            {
                return;
            }

            float distance = Vector2.Distance(currentRect.anchoredPosition, GetTargetPointForCurrentRect(transitionAction));
            float interval = distance / container.TransitionSpeed;

            switch (transitionAction)
            {
            case ManagementView.SwipeResultAction.ReturnToCenter: {
                isCurrentTransitionStarted = true;
                OnTransitionStartedChanged(IsTransitionStarted);
                Vector2AnimationData currentPosData = new Vector2AnimationData {
                    StartValue = currentRect.anchoredPosition,
                    EndValue   = Vector2.zero,
                    Duration   = interval,
                    EaseType   = EaseType.EaseInOutQuad,
                    Target     = currentRect.gameObject,
                    OnStart    = (p, o) => SetPositions(p),
                    OnUpdate   = (p, t, o) => SetPositions(p),
                    OnEnd      = (p, o) => {
                        isCurrentTransitionStarted = false;
                        OnTransitionStartedChanged(IsTransitionStarted);
                        SetPositions(p);
                    }
                };
                currentRect.gameObject.GetOrAdd <Vector2Animator>().StartAnimation(currentPosData);
            }
            break;

            case ManagementView.SwipeResultAction.MoveToLeft: {
                isCurrentTransitionStarted = true;
                isRightTransitionStarted   = true;
                OnTransitionStartedChanged(IsTransitionStarted);
                Vector2AnimationData currentPosData = new Vector2AnimationData {
                    StartValue = currentRect.anchoredPosition,
                    EndValue   = -HORIZONTAL_VECTOR,
                    Duration   = interval,
                    EaseType   = EaseType.EaseInOutQuad,
                    Target     = currentRect.gameObject,
                    OnStart    = (p, o) => SetPositions(p),
                    OnUpdate   = (p, t, o) => SetPositions(p),
                    OnEnd      = (p, o) => {
                        isCurrentTransitionStarted = false;
                        SetPositions(p);
                        isRightTransitionStarted = false;
                        MakeRightAsCurrent();
                        container.OnTransitionCompletedIn(managerId);
                        OnTransitionStartedChanged(IsTransitionStarted);
                    }
                };
                currentRect.gameObject.GetOrAdd <Vector2Animator>().StartAnimation(currentPosData);
            }
            break;

            case ManagementView.SwipeResultAction.MoveToRight: {
                isCurrentTransitionStarted = true;
                isLeftTransitionStarted    = true;
                OnTransitionStartedChanged(IsTransitionStarted);
                Vector2AnimationData currentPosData = new Vector2AnimationData {
                    StartValue = currentRect.anchoredPosition,
                    EndValue   = HORIZONTAL_VECTOR,
                    Duration   = interval,
                    EaseType   = EaseType.EaseInOutQuad,
                    Target     = currentRect.gameObject,
                    OnStart    = (p, o) => SetPositions(p),
                    OnUpdate   = (p, t, o) => SetPositions(p),
                    OnEnd      = (p, o) => {
                        isCurrentTransitionStarted = false;
                        SetPositions(p);
                        isLeftTransitionStarted = false;
                        MakeLeftAsCurrent();
                        container.OnTransitionCompletedIn(managerId);
                        OnTransitionStartedChanged(IsTransitionStarted);
                    }
                };
                currentRect.gameObject.GetOrAdd <Vector2Animator>().StartAnimation(currentPosData);
            }
            break;
            }
        }