Beispiel #1
0
    void UpdateDragging()
    {
        if (!isDragging || !isDraggingEnabled)
        {
            return;
        }

        Vector3 currPos = new Vector3(Input.mousePosition.x /* - _dragOffset.x*/,
                                      Input.mousePosition.y /* - _dragOffset.y*/,
                                      _dragDist.z);

        _nestWorldPos = Camera.main.ScreenToWorldPoint(currPos);

        // clamp worldPos to stay within the bounds of the convert nest highlight
        _nestWorldPos.x = Mathf.Clamp(_nestWorldPos.x,
                                      -highlight.GetComponent <SpriteRenderer>().bounds.extents.x + highlight.transform.position.x,
                                      highlight.GetComponent <SpriteRenderer>().bounds.extents.x + highlight.transform.position.x);
        _nestWorldPos.y = highlight.transform.position.y; // retain nest x and z, but reparenting causes position issues fixed by _animatorOffset
        _nestWorldPos.z = this.transform.position.z;

        this.transform.position = _nestWorldPos;
        //kiwi.transform.position = _nestWorldPos;
        _dragNest.transform.position = _nestWorldPos;

        _highlightPercent = 0.5f - ((_dragNest.transform.position.x - highlight.transform.position.x) / ((highlight.transform.position.x + highlight.GetComponent <SpriteRenderer>().bounds.extents.x) -
                                                                                                         (highlight.transform.position.x - highlight.GetComponent <SpriteRenderer>().bounds.extents.x)));
        // grab chickens (starting from the bottom)
        //   groups: 5 & 10, 4 & 9, 3 & 8, 2 & 7, 1 & 6

        // 5 groups
        //      1: 5, 10    (10%)
        //      2: 4, 9     (30%)
        //      3: 3, 8     (50%)
        //      4: 2, 7     (70%)
        //      5: 1, 6     (90%)

        var animator = _dragNest.GetComponentInChildren <Animator>();

        animator.Play(animator.GetCurrentAnimatorStateInfo(0).tagHash, 0, _highlightPercent);

        // if we've dragged far enough to pick up more creatures, find out which ones and get them from the placeValueCtrl
        if (_highlightPercent > _maxHighlightPercent)
        {
            bool bNewCaptured = false;
            // reparent and 'drag' all creatures that fall under _highlightPercent
            if (_highlightPercent > 0.65f)
            {
                onesColumn.ConvertCapture(_dragNest.transform, _dragNest.transform.FindChild("NestConvertDrag"), 4, 9, 3, 8, 2, 7, 1, 6, 0, 5);
                bNewCaptured = _maxHighlightPercent <= 0.65f;
            }
            else if (_highlightPercent > 0.5f)
            {
                onesColumn.ConvertCapture(_dragNest.transform, _dragNest.transform.FindChild("NestConvertDrag"), 4, 9, 3, 8, 2, 7, 1, 6);
                bNewCaptured = _maxHighlightPercent <= 0.5f;
            }
            else if (_highlightPercent > 0.4f)
            {
                onesColumn.ConvertCapture(_dragNest.transform, _dragNest.transform.FindChild("NestConvertDrag"), 4, 9, 3, 8, 2, 7);
                bNewCaptured = _maxHighlightPercent <= 0.4f;
            }
            else if (_highlightPercent > 0.2f)
            {
                onesColumn.ConvertCapture(_dragNest.transform, _dragNest.transform.FindChild("NestConvertDrag"), 4, 9, 3, 8);
                bNewCaptured = _maxHighlightPercent <= 0.2f;
            }
            else if (_highlightPercent > 0.01f)
            {
                onesColumn.ConvertCapture(_dragNest.transform, _dragNest.transform.FindChild("NestConvertDrag"), 4, 9);
                bNewCaptured = _maxHighlightPercent <= 0.01f;
            }

            if (bNewCaptured)
            {
                SoundManager.instance.PlayRandomOneShot(SoundManager.instance.chickenDrag);
                animator.SetTrigger("collect");
            }

            _maxHighlightPercent = _highlightPercent;
        }

        _prevHighlightPercent = _highlightPercent;

        // if we've passed the rectangle threshold for a successful conversion
        if (_highlightPercent > dragThresholdPercent)
        {
            // continue conversion
            convertHolder.GetComponent <Animator>().SetBool("draggingNest", true);
            onesColumn.onShift(onesColumn);

            SnapBack();
        }
    }