Esempio n. 1
0
 void Update()
 {
     if (Input.touchCount == 1)
     {
         Touch touch = Input.GetTouch(0);
         if (touch.phase == TouchPhase.Began)
         {
             firstTouchPos = touch.position;
             lastTouchPos  = touch.position;
         }
         if (touch.phase == TouchPhase.Moved)
         {
             lastTouchPos = touch.position;
         }
         if (touch.phase == TouchPhase.Ended)
         {
             lastTouchPos = touch.position;
             if (IsSwipe())
             {
                 swipeState          = GetSwipeDirect();
                 isSwipeStateChanged = true;
             }
         }
     }
     else
     {
         if (isSwipeStateChanged)
         {
             ResetSwipeState();
             isSwipeStateChanged = false;
         }
     }
 }
Esempio n. 2
0
        private bool DriverSwipeReflector(string driverId, SwipeState state)
        {
            var driver = _userManager.Users.OfType <Driver>().Where(d => d.Id == driverId).FirstOrDefault();

            if (driver == null)
            {
                throw new ArgumentException("Driver does not exist.");
            }

            if (driver.VanID != null)
            {
                driver.VanID = null;
                _vanRepo.CommitChanges();
            }

            if (driver.Status == DriverStatusType.Off)
            {
                throw new InvalidOperationException("Driver is off duty.");
            }

            var startTask = GetStartTask(driver, state);
            var endTask   = GetEndTask(driver, state);

            if (endTask != null)
            {
                CheckIn(driver, state);
                return(true);
            }
            else if (startTask != null)
            {
                CheckOut(driver, state);
                return(false);
            }
            throw new InvalidOperationException("There are no tasks to start/finish in this station for this driver.");
        }
Esempio n. 3
0
        private void OnTap(EventArgs e)
        {
            OnTapHandler?.Invoke(this, e);

            // Reset.
            state = SwipeState.NULL;
        }
Esempio n. 4
0
    void Swipe(Vector2 pos)
    {
        switch (state)
        {
        case SwipeState.Began:
            couldBeSwipe = true;
            startPos     = pos;
            state        = SwipeState.Draging;
            break;

        case SwipeState.Draging:
            Vector2 currentVector = pos - startPos;
            float   swipeDist     = currentVector.magnitude;

            if (swipeDist > minSwipeDist)
            {
                swipeVector = currentVector;
            }
            else
            {
                swipeVector = Vector2.zero;
            }
            startPos = pos;
            break;
        }
    }
    public void UpdateSwipe()
    {
        if (Input.touchCount != 1)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        switch (touch.phase)
        {
        case TouchPhase.Began:
            swipeStartPosition = touch.position;
            break;

        case TouchPhase.Moved:
            swipeCurrentPosition = touch.position;
            break;

        case TouchPhase.Ended:
            SwipeState swipeState = DetectSwipe();
            if (swipeState != SwipeState.None)
            {
                ResetSwipe();
                OnSwipeFinished.Invoke(swipeState);
            }
            break;
        }
    }
Esempio n. 6
0
    public void DetectDrag(SwipeState state, Rigidbody obj)
    {
        Rigidbody rigidbody = obj;

        if (rigidbody)
        {
            debugText.text = "rigidbody of object not found";


//            throw new NullReferenceException("rigidbody of object not found");
        }

        switch (state)
        {
        case SwipeState.SwipeRight:
            MoveObj(rigidbody, Vector3.right);
            debugText.text = "right";
            rigidbody.gameObject.GetComponent <Cloud>().scoreGetting = true;
            break;

        case SwipeState.SwipeLeft:
            MoveObj(rigidbody, Vector3.left);
            debugText.text = "left";
            rigidbody.gameObject.GetComponent <Cloud>().scoreGetting = true;
            break;

        case SwipeState.NotSwipe:
            debugText.text = "default";
            break;
        }
    }
        private void SetTouchListener(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
                                      float dY, int actionState, bool isCurrentlyActive)
        {
            recyclerView.SetOnTouchListener(
                new TouchListenerDelegate(
                    (v, @event) =>
            {
                _swipeBack = @event.Action == MotionEventActions.Cancel || @event.Action == MotionEventActions.Up;
                if (_swipeBack)
                {
                    float containerWidth = GetMeasuredSize(GetContainerArea(dX), viewHolder).width;

                    if (dX <= -containerWidth)
                    {
                        _currentSwipeState = SwipeState.RightOpen;
                    }
                    else if (dX >= containerWidth)
                    {
                        _currentSwipeState = SwipeState.LeftOpen;
                    }

                    if (_currentSwipeState != SwipeState.Default)
                    {
                        DrawButtons(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive, _currentSwipeState, true);
                        SetTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
                        SetItemsClickable(recyclerView, false);
                    }
                }

                return(false);
            }));
        }
Esempio n. 8
0
 private void MoveCells(SwipeState swipeState)
 {
     if (swipeState == SwipeState.RIGHT)
     {
         MoveCellsToRight();
     }
 }
Esempio n. 9
0
        private void CheckIn(Driver driver, SwipeState state)
        {
            switch (state)
            {
            case SwipeState.InGate:
                var inGateFinishTask = driver.TicketStatuses
                                       .Where(s => s.StartDate != null && s.EndDate == null && s.Type == TicketStatusType.Returning)
                                       .OrderBy(s => s.CreationDate).FirstOrDefault();
                inGateFinishTask.EndDate = DateTime.Now;
                inGateFinishTask.Ticket.TicketStatuses.Add(new TicketStatus
                {
                    CreationDate = DateTime.Now,
                    Type         = TicketStatusType.CheckedIn,
                    StartDate    = DateTime.Now,
                    TicketID     = inGateFinishTask.Ticket.ID
                });
                break;

            case SwipeState.InParking:
                var inParkingFinishTask = driver.TicketStatuses
                                          .Where(s => s.StartDate != null && s.EndDate == null && s.Type == TicketStatusType.Dispatching)
                                          .OrderBy(s => s.CreationDate).FirstOrDefault();
                inParkingFinishTask.EndDate = DateTime.Now;
                inParkingFinishTask.Ticket.TicketStatuses.Add(new TicketStatus
                {
                    CreationDate = DateTime.Now,
                    Type         = TicketStatusType.Dispatched,
                    StartDate    = DateTime.Now,
                    TicketID     = inParkingFinishTask.Ticket.ID
                });
                break;
            }
            _ticketStatusRepo.CommitChanges();
        }
Esempio n. 10
0
    public Direction DetectSwipe()
    {
        if (Input.touches.Length > 0)
        {
            Touch t = Input.GetTouch(0);

            switch (swipeState)
            {
            case SwipeState.IDLE:

                if (t.phase == TouchPhase.Began)
                {
                    firstPressPos = new Vector2(t.position.x, t.position.y);
                    swipeState    = SwipeState.PRESSED;
                }
                break;

            case SwipeState.PRESSED:
                if (t.phase == TouchPhase.Ended)
                {
                    swipeState     = SwipeState.IDLE;
                    secondPressPos = new Vector2(t.position.x, t.position.y);
                    currentSwipe   = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);

                    // Make sure it was a legit swipe, not a tap
                    if (currentSwipe.magnitude < minSwipeLength)
                    {
                        return(Direction.NONE);
                    }

                    currentSwipe.Normalize();

                    // Swipe up
                    if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                    {
                        return(Direction.UP);
                    }
                    else if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                    {
                        return(Direction.DOWN);
                    }
                    else if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                    {
                        return(Direction.LEFT);
                    }
                    else if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                    {
                        return(Direction.RIGHT);
                    }
                    else
                    {
                        return(Direction.NONE);
                    }
                }
                break;
            }
        }
        return(Direction.NONE);
    }
Esempio n. 11
0
    public void StartSwipe()
    {
        state = SwipeState.IDLE;
        // GetComponent<Animator> ().enabled = false;
        firstTakeCard = false;

        OnStartSwipe?.Invoke();
    }
Esempio n. 12
0
    /// <summary>
    /// Reset swipe state as well as swipe relevant data.
    /// </summary>
    public void ResetAll()
    {
        swipeState = SwipeState.Idle;

        ResetSwipeData();

        Deactivate();
    }
Esempio n. 13
0
 void Awake()
 {
     currentChoise  = -1;
     state          = SwipeState.DISABLE;
     deviation      = 0;
     rectTransform  = this.GetComponent <RectTransform> ();
     pivotPoint     = new Vector2(rectTransform.anchoredPosition.x, rectTransform.anchoredPosition.y);
     cardController = this.GetComponent <CardController> ();
 }
Esempio n. 14
0
    void OnEnable()
    {
        swipeState = SwipeState.Idle;

        if (OnSwipeSucceeded == null)
        {
            OnSwipeSucceeded = new UnityEvent();
        }
    }
Esempio n. 15
0
    public void OnDrag(PointerEventData eventData)
    {
        if (state == SwipeState.DISABLE)
        {
            return;
        }

        state = SwipeState.DRAG;

        rectTransform.anchoredPosition += new Vector2(eventData.delta.x, 0) / _parent.scaleFactor;
        rectTransform.rotation          = Quaternion.Euler(0, 0, (rectTransform.anchoredPosition.x - pivotPoint.x) * fRotation);

        if (rectTransform.anchoredPosition.x > pivotPoint.x)
        {
            if (direction != 1)
            {
                OnChangeDirection?.Invoke(SwipeDirection.RIGHT);
            }
            direction = 1;
        }
        else if (rectTransform.anchoredPosition.x < pivotPoint.x)
        {
            if (direction != -1)
            {
                OnChangeDirection?.Invoke(SwipeDirection.LEFT);
            }
            direction = -1;
        }

        if (cardController != null)
        {
            cardController.OnDrag(direction);

            if (!cardController.rightAvailable && rectTransform.anchoredPosition.x > pivotPoint.x)
            {
                float scale = 0.93f;
                rectTransform.anchoredPosition = pivotPoint;

                rectTransform.rotation   = Quaternion.Euler(0, 0, 0);
                rectTransform.localScale = Vector3.MoveTowards(rectTransform.localScale, new Vector3(scale, scale, scale), 0.02f);
            }
            else if (!cardController.leftAvailable && rectTransform.anchoredPosition.x < pivotPoint.x)
            {
                float scale = 0.93f;
                rectTransform.anchoredPosition = pivotPoint;
                rectTransform.rotation         = Quaternion.Euler(0, 0, 0);
                rectTransform.localScale       = Vector3.MoveTowards(rectTransform.localScale, new Vector3(scale, scale, scale), 0.02f);
            }
            else
            {
            }
        }

        MovingDispatcher();
    }
Esempio n. 16
0
 void MouseUpdate()
 {
     if (Input.GetMouseButtonDown(0))
     {
         state = SwipeState.Began;
     }
     else if (Input.GetMouseButtonUp(0))
     {
         state = SwipeState.Ended;
     }
     Swipe(Input.mousePosition);
 }
Esempio n. 17
0
 void Update()
 {
     if (!isPause)
     {
         swipeState = inputController.GetSwipeState();
         if (swipeState != SwipeState.NONE)
         {
             MoveCells(swipeState);
             CheckGameState();
             NextStep();
         }
     }
 }
Esempio n. 18
0
        public void OnReset()
        {
            // Reset swipe state.
            state = SwipeState.NULL;

            // Reset start position.
            touchStart = Vector2.zero;

            // Reset to default swipe dead zone.
            swipeDeadZone = 100.00f;

            // Disable touch and mouse inputs.
            isTouchEnabled = false;
        }
Esempio n. 19
0
        private TicketStatus GetEndTask(Driver driver, SwipeState state)
        {
            switch (state)
            {
            case SwipeState.InGate:
                return(driver.TicketStatuses
                       .Where(s => s.StartDate != null && s.EndDate == null && s.Type == TicketStatusType.Returning)
                       .FirstOrDefault());

            case SwipeState.InParking:
                return(driver.TicketStatuses
                       .Where(s => s.StartDate != null && s.EndDate == null && s.Type == TicketStatusType.Dispatching)
                       .FirstOrDefault());
            }
            return(null);
        }
Esempio n. 20
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (state == SwipeState.DISABLE)
        {
            return;
        }

        direction = 0;

        if (firstTakeCard == false)
        {
            firstTakeCard = true;
            OnFirstSwipeCard?.Invoke();
        }

        state = SwipeState.DRAG;
    }
Esempio n. 21
0
	// Use this for initialization
	void Start ()
	{
		_swipeState = SwipeState.None;

		_isFirstTouch = true;

		_uiScrollView = GetComponentInChildren<UIScrollView>();

		if (null == _uiScrollView)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIScrollView component for _uiScrollView");
		}

		_startingMomentum = _uiScrollView.momentumAmount;
		_uiScrollView.panel.clipping = UIDrawCall.Clipping.None;

		_panel = _uiScrollView.GetComponent<UIPanel>();

		if (null == _panel)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIPanel component for _panel");
		}

		DynamicScrollView2 dynamicScrollView = FindObjectOfType<DynamicScrollView2>();

		if (null == dynamicScrollView)
		{
			throw new NullReferenceException("TestSwipeScripts.Start - can't find DynamicScrollView object");
		}

		_thresholdDistanceToCloseCard = dynamicScrollView.closeDetailCardThresholdHorizontal;
		_thresholdDistanceVerticalToCloseCard = dynamicScrollView.closeDetailCardThreshold;


		ScrollViewContainer = NGUITools.FindInParents<UIWidget>(_uiScrollView.transform);

		if (null == ScrollViewContainer)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIWidget component for _scrollViewContainer");
		}

		_currentScale = Vector3.one;

		_previousMovementState = UIScrollView.Movement.Custom;

	}
Esempio n. 22
0
    // Use this for initialization
    void Start()
    {
        _swipeState = SwipeState.None;

        _isFirstTouch = true;

        _uiScrollView = GetComponentInChildren <UIScrollView>();

        if (null == _uiScrollView)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIScrollView component for _uiScrollView");
        }

        _startingMomentum            = _uiScrollView.momentumAmount;
        _uiScrollView.panel.clipping = UIDrawCall.Clipping.None;

        _panel = _uiScrollView.GetComponent <UIPanel>();

        if (null == _panel)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIPanel component for _panel");
        }

        DynamicScrollView2 dynamicScrollView = FindObjectOfType <DynamicScrollView2>();

        if (null == dynamicScrollView)
        {
            throw new NullReferenceException("TestSwipeScripts.Start - can't find DynamicScrollView object");
        }

        _thresholdDistanceToCloseCard         = dynamicScrollView.closeDetailCardThresholdHorizontal;
        _thresholdDistanceVerticalToCloseCard = dynamicScrollView.closeDetailCardThreshold;


        ScrollViewContainer = NGUITools.FindInParents <UIWidget>(_uiScrollView.transform);

        if (null == ScrollViewContainer)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIWidget component for _scrollViewContainer");
        }

        _currentScale = Vector3.one;

        _previousMovementState = UIScrollView.Movement.Custom;
    }
    SwipeState DetectSwipe()
    {
        SwipeState swipeState = SwipeState.None;

        if (HasSwipped())
        {
            if (swipeType == SwipeType.Horizontal)
            {
                swipeState = (swipeCurrentPosition.x > swipeStartPosition.x) ? SwipeState.PositiveSwipe : SwipeState.NegativeSwipe;
            }
            else
            {
                swipeState = (swipeCurrentPosition.y > swipeStartPosition.y) ? SwipeState.PositiveSwipe : SwipeState.NegativeSwipe;
            }
        }

        return(swipeState);
    }
Esempio n. 24
0
 private void ResetGame()
 {
     // reset all cells to zero value
     for (int i = 0; i < cellsList.Count; i++)
     {
         cellsList[i].ResetCell();
     }
     // all cells is clear
     emptyIndexesList.Clear();
     for (int i = 0; i < cellsList.Count; i++)
     {
         emptyIndexesList.Add(i);
     }
     // reset game data
     isPause = false;
     score   = 0;
     uiController.ShowScore(score);
     swipeState = SwipeState.NONE;
 }
Esempio n. 25
0
 public void SwipeLeft()
 {
     if (swipeState == SwipeState.middle)
     {
         LeanTween.moveLocalX(mainCamera.gameObject, -3f, .5f);
         swipeState = SwipeState.left;
         buttonleft.SetActive(false);
     }
     if (swipeState == SwipeState.left)
     {
         return;
     }
     if (swipeState == SwipeState.right)
     {
         buttonright.SetActive(true);
         buttonleft.SetActive(true);
         LeanTween.moveLocalX(mainCamera.gameObject, 0f, .5f);
         swipeState = SwipeState.middle;
     }
 }
Esempio n. 26
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (state == SwipeState.DISABLE)
        {
            return;
        }

        if (cardController != null)
        {
            cardController.OnEndDrag();
        }

        OnDrop?.Invoke();

        Vector2 distance = rectTransform.anchoredPosition - pivotPoint;

        if (distance.magnitude >= swipeDetectionLimit_LR)
        {
            if (rectTransform.anchoredPosition.x < pivotPoint.x)
            {
                TriggerLeft();
            }
            else
            {
                TriggerRight();
            }
            state = SwipeState.DISABLE;
            eventData.pointerDrag = null;
            OnEndSwipe?.Invoke();

            if (isActiveAndEnabled)
            {
                Coroutine _coroutine = StartCoroutine(OnFideOut());
                _coroutine = null;
            }
        }
        else
        {
            state = SwipeState.RETURN;
        }
    }
        private void SetTouchUpListener(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
                                        float dY, int actionState, bool isCurrentlyActive)
        {
            recyclerView.SetOnTouchListener(
                new TouchListenerDelegate(
                    (recyclerViewInDelegate, outerArgs) =>
            {
                if (outerArgs.Action == MotionEventActions.Up)
                {
                    recyclerView.SetOnTouchListener(
                        new TouchListenerDelegate(
                            (innerView, innerArgs) => { return(false); }));

                    SetItemsClickable(recyclerView, true);
                    _swipeBack = false;

                    //							if (_buttonsActions != null && _buttonInstance != null &&
                    //								_buttonInstance.Contains(outerArgs.GetX(), outerArgs.GetY()))
                    //							{
                    //								if (_currentSwipeState == SwipeState.LeftOpen)
                    //								{
                    //									_buttonsActions.OnLeftClicked(viewHolder.AdapterPosition);
                    //								}
                    //								else if (_currentSwipeState == SwipeState.RightOpen)
                    //								{
                    //									_buttonsActions.OnRightClicked(viewHolder.AdapterPosition);
                    //								}
                    //							}

                    _currentSwipeState = SwipeState.Default;


                    // folgende codezeile behebt einen darstellungsbug, wenn man eine schaltfläche klickt
                    Thread.Sleep(100);
                    base.OnChildDraw(c, recyclerView, viewHolder, 0, dY, actionState, isCurrentlyActive);
                }

                return(false);
            }));
        }
Esempio n. 28
0
        private void CheckOut(Driver driver, SwipeState state)
        {
            if (driver.TicketStatuses.Any(s => s.StartDate != null && s.EndDate == null))
            {
                throw new InvalidOperationException("Driver has been already assigned a task.");
            }
            switch (state)
            {
            case SwipeState.InGate:
                driver.TicketStatuses
                .Where(s => s.StartDate == null && s.Type == TicketStatusType.Dispatching)
                .OrderBy(s => s.CreationDate).FirstOrDefault().StartDate = DateTime.Now;
                break;

            case SwipeState.InParking:
                driver.TicketStatuses
                .Where(s => s.StartDate == null && s.Type == TicketStatusType.Returning)
                .OrderBy(s => s.CreationDate).FirstOrDefault().StartDate = DateTime.Now;
                break;
            }
            _ticketStatusRepo.CommitChanges();
        }
Esempio n. 29
0
 private void OnSwipeUpdated(float pos)
 {
     if (swipeState_ == SwipeState.Standby)
     {
         if (SWIPE_THRESHOLD < pos)
         {
             ShiftRight();
             swipeState_ = SwipeState.Detected;
         }
         else if (pos < -SWIPE_THRESHOLD)
         {
             ShiftLeft();
             swipeState_ = SwipeState.Detected;
         }
     }
     else
     {
         if (pos == 0f)
         {
             swipeState_ = SwipeState.Standby;
         }
     }
 }
Esempio n. 30
0
    private void UpdateScrollPosition()
    {
        if (null == _uiScrollView)
        {
            return;
        }

        if (_uiScrollView.isDragging)
        {
            if (_isFirstTouch)
            {
                _startTouchPos = _currentPos;
                _isFirstTouch  = false;
            }

            float verticalSwipeDistance   = Mathf.Abs(DeltaTouchPos.y);
            float horizontalSwipeDistance = Mathf.Abs(DeltaTouchPos.x);

            if (_swipeState == SwipeState.None)
            {
                if (verticalSwipeDistance >= TouchDragThreshold)
                {
                    _swipeState = SwipeState.UseVerticalScroll;

                    _uiScrollView.movement    = UIScrollView.Movement.Vertical;
                    _begintScrollContainerPos = _uiScrollView.transform.localPosition;
                }
                else if (horizontalSwipeDistance >= TouchDragThreshold)
                {
                    _swipeState = SwipeState.UseHorizontalSwipe;
                    SetBasicDataBeforeDragging();
                }
            }

            UpdateScrollViewScale();
        }
        else
        {
            if (_uiScrollView.movement != UIScrollView.Movement.Vertical)
            {
                _previousMovementState = _uiScrollView.movement;

                _uiScrollView.customMovement = new Vector2(1, 1);

                _uiScrollView.movement = UIScrollView.Movement.Vertical;

                if (Mathf.Abs(_currentDistance) > _thresholdDistanceToCloseCard)
                {
                    _isNeedResetToDefault = false;
                }
                else
                {
                    _isNeedResetToDefault = true;
                }
            }

            _isFirstTouch = true;

            _swipeState = SwipeState.None;

            ResetScaleToDefault();
        }
    }
Esempio n. 31
0
	public SwipeEventArgs (SwipeState state) {
		this.State = state;
	}
        private void DrawButtons(Canvas canvas, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX,
                                 float dY, int actionState, bool isCurrentlyActive, SwipeState swipeState, bool swipeEnd)
        {
            var validState = isCurrentlyActive || swipeState != SwipeState.Default;


            if (!validState)
            {
                return;
            }

            if (viewHolder is IViewHolderButtonContainer buttonContainer)
            {
                //				int widthSpec = View.MeasureSpec.MakeMeasureSpec(ViewGroup.LayoutParams.WrapContent, MeasureSpecMode.Unspecified);

                int widthSpec  = View.MeasureSpec.MakeMeasureSpec(viewHolder.ItemView.Width, MeasureSpecMode.AtMost);
                int heightSpec = View.MeasureSpec.MakeMeasureSpec(viewHolder.ItemView.Height, MeasureSpecMode.AtMost);

                var containerArea = GetContainerArea(dX);
                var container     = buttonContainer.CreateButtonContainer(containerArea);
                container.Measure(widthSpec, heightSpec);

                var clippedWidth = GetClippedWidth(viewHolder.ItemView.Width, dX, container.MeasuredWidth);
                if (clippedWidth <= 0)
                {
                    return;
                }
                var clippedHeight = GetClippedHeight(viewHolder.ItemView.Height, dY, container.MeasuredHeight);
                if (clippedHeight <= 0)
                {
                    return;
                }

                var viewLeft   = dX >= 0 ? viewHolder.ItemView.Left : viewHolder.ItemView.Right - clippedWidth;
                var viewTop    = viewHolder.ItemView.Top;
                var viewRight  = viewLeft + clippedWidth;
                var viewBottom = viewTop + clippedHeight;

                container.Layout(viewLeft, viewTop, viewRight, viewBottom);

                container.SetBackgroundColor(Color.Orange);

                //				var canvasX = dX >= 0 ? viewHolder.ItemView.Left : viewHolder.ItemView.Left + viewHolder.ItemView.Width;

                //					var paint = new Paint();
                //					paint.Color = Color.Aqua;
                //					canvas.DrawRect(viewLeft, viewTop, viewRight, viewBottom, paint);

                // Translate the canvas so the view is drawn at the proper coordinates
                canvas.Save();
                canvas.Translate(viewLeft, viewHolder.ItemView.Top);

                if (swipeEnd)
                {
                    viewHolder.ItemView.Invalidate();
                    container.Invalidate();
                }

                //Draw the View and clear the translation
                container.Draw(canvas);
                canvas.Restore();
            }
        }
Esempio n. 33
0
    static public void ProcessSwipeInput()
    {

        state = SwipeState.AwaitingInput;

        #if UNITY_ANDROID || UNITY_IPHONE// || UNITY_EDITOR

        if (Input.touchCount > 0){

            // process 1rst touch on a player
            Touch touch = Input.touches[0];

            switch (touch.phase) {
                case TouchPhase.Began:
                    {
                        swipeOrigin = touch.position;
                        swipeEnd = swipeOrigin;
                        state = SwipeState.SwipeStarted;
                        break;
                    }
                case TouchPhase.Ended:
                    {
                        swipeEnd = touch.position;
                        state = SwipeState.SwipeEnded;
                        break;
                    }
                case TouchPhase.Moved:
                    {
                        swipeEnd = touch.position;
                        state = SwipeState.SwipeMoved;
                        break;
                    }

            }

        }

        #elif UNITY_EDITOR || UNITY_STANDALONE

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            swipeOrigin = Input.mousePosition;
            swipeEnd = swipeOrigin;
            state = SwipeState.SwipeStarted;
        }else if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            swipeEnd = Input.mousePosition;
            state = SwipeState.SwipeEnded;
        }else if(Input.GetKey(KeyCode.Mouse0))
        {
            swipeEnd = Input.mousePosition;
            state = SwipeState.SwipeMoved;
        }

        #endif

        swipeDirection = swipeEnd - swipeOrigin;

        swipeWorldOrigin = Camera.main.ScreenToWorldPoint(swipeOrigin);
        swipeWorldEnd = Camera.main.ScreenToWorldPoint(swipeEnd);
        swipeWorldDirection = Camera.main.ScreenToWorldPoint(swipeDirection);

    }
Esempio n. 34
0
    // Update is called once per frame
    void Update()
    {
        if( swipe_state == SwipeState.END )  {
            swipe_state = SwipeState.NONE;

            swipe_startTime = 0.0f;
            swipe_startPos = Vector2.zero;
            swipe_direction = Vector2.zero;
            swipe_duration = 0.0f;
            swipe_length = 0.0f;
        }

        // Mouse Controls
        if (!useTouch) {
            Vector2 mousePos;
            mousePos.x = Input.mousePosition.x;
            mousePos.y = Input.mousePosition.y;

            if( Input.GetMouseButtonDown(1) ) {
                swipe_state = SwipeState.BEGIN;
                isSwipe = true;
                swipe_startTime = Time.time;
                swipe_startPos = mousePos;
            }
            else if( Input.GetMouseButtonUp(1) ) {
                swipe_state = SwipeState.END;
                isSwipe = false;

                swipe_duration = Time.time - swipe_startTime;
                swipe_length = (mousePos - swipe_startPos).magnitude;
                swipe_direction = mousePos - swipe_startPos;
                swipe_direction.Normalize();
            }
            else if( Input.GetMouseButton(1) ) {
                swipe_state = SwipeState.INPROGRESS;
                swipe_direction = mousePos - swipe_startPos;
                swipe_direction.Normalize();
            }
        }

        // Touch Controls
        if (useTouch && Input.touchCount > 0){
            //foreach (Touch touch in Input.touches)
            Touch touch;// = Input.GetTouch(0);
            if( Input.touchCount == 1 ) {
                touch = Input.GetTouch(0);
            }
            else {
                touch = Input.GetTouch(fingerTouchIndex);
            }

            if( touch.position.x > (Screen.width/2) )
            {
                switch (touch.phase)
                {
                case TouchPhase.Began :
                    swipe_state = SwipeState.BEGIN;
                    isSwipe = true;
                    swipe_startTime = Time.time;
                    swipe_startPos = touch.position;
                    break;

                case TouchPhase.Canceled :
                    /* The touch is being canceled */
                    isSwipe = false;
                    swipe_state = SwipeState.NONE;
                    break;

                case TouchPhase.Ended :
                    swipe_state = SwipeState.END;
                    isSwipe = false;

                    swipe_duration = Time.time - swipe_startTime;
                    swipe_length = (touch.position - swipe_startPos).magnitude;
                    swipe_direction = touch.position - swipe_startPos;
                    swipe_direction.Normalize();
                    break;

                case TouchPhase.Moved :
                    swipe_state = SwipeState.INPROGRESS;
                    swipe_direction = touch.position - swipe_startPos;
                    swipe_direction.Normalize();
                    break;
                }
            }
        }
    }
Esempio n. 35
0
	private void UpdateScrollPosition()
	{
		if (null == _uiScrollView)
			return;

		if (_uiScrollView.isDragging)
		{
			if (_isFirstTouch)
			{
				_startTouchPos = _currentPos;
				_isFirstTouch = false;
			}

			float verticalSwipeDistance =  Mathf.Abs(DeltaTouchPos.y);
			float horizontalSwipeDistance =  Mathf.Abs(DeltaTouchPos.x);

			if (_swipeState == SwipeState.None)
			{
				if (verticalSwipeDistance >= TouchDragThreshold)
				{
					_swipeState = SwipeState.UseVerticalScroll;

					_uiScrollView.movement = UIScrollView.Movement.Vertical;
					_begintScrollContainerPos = _uiScrollView.transform.localPosition;
				}
				else if (horizontalSwipeDistance >= TouchDragThreshold)
				{
					_swipeState = SwipeState.UseHorizontalSwipe;
					SetBasicDataBeforeDragging();
				}
			}

			UpdateScrollViewScale();
		}
		else
		{
			if (_uiScrollView.movement != UIScrollView.Movement.Vertical)
			{
				_previousMovementState = _uiScrollView.movement;

				_uiScrollView.customMovement = new Vector2(1, 1);

				_uiScrollView.movement = UIScrollView.Movement.Vertical;

				if (Mathf.Abs(_currentDistance) > _thresholdDistanceToCloseCard )
				{
					_isNeedResetToDefault = false;
				}
				else
				{
					_isNeedResetToDefault = true;
				}

			}

			_isFirstTouch = true;

			_swipeState = SwipeState.None;

			ResetScaleToDefault();
		}
	}