예제 #1
0
 void Start()
 {
     joystickPosition = RectTransformUtility.WorldToScreenPoint(cam, background.position);
 }
예제 #2
0
 public void OnPointerDown(PointerEventData data)
 {
     originalLocalPosition = transform.localPosition; originalLocalRotation = transform.localRotation;
     originalLocalScale    = transform.localScale;
     RectTransformUtility.ScreenPointToLocalPointInRectangle(handRectTransform, data.position, data.pressEventCamera, out originalLocalPointerPosition);
 }
예제 #3
0
 public void OnPointerDown(PointerEventData eventData)
 {
     wheelBeingHeld = true;
     centerPoint    = RectTransformUtility.WorldToScreenPoint(eventData.pressEventCamera, wheelRT.position);
     wheelPrevAngle = Vector2.Angle(Vector2.up, eventData.position - centerPoint);
 }
예제 #4
0
 private void OnInitializePotentialDrag(PointerEventData e)
 {
     //print("OnInitializePotentialDrag");
     originalPanelLocalPosition = window.localPosition;
     RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)window.parent.transform, e.position, e.pressEventCamera, out originalLocalPointerPosition);
 }
 private static bool IsDragEndPositionValid(RectTransform rectTransform)
 {
     return(RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition));
 }
    void DetermineSlideDirection()
    {
        //check if the user is touching the tab area
        isTouching = Input.GetMouseButton(0) || (Input.touchCount > 0);
        Vector2 touchPos = Vector2.zero;

        if (isTouching)
        {
            if (!isPrevTouching)
            {
                if (Input.GetMouseButton(0))
                {
                    touchPos = Input.mousePosition;
                }
                else
                {
                    touchPos = Input.GetTouch(0).position;
                }

                isTouchingTab = RectTransformUtility.RectangleContainsScreenPoint(GetComponent <RectTransform>(), touchPos);
            }
        }
        else
        {
            isTouchingTab   = false;
            prevViewportPos = new Vector2(-999, -999);
        }

        //calculate the velocity
        if (isTouchingTab)
        {
            if (Input.GetMouseButton(0))
            {
                touchPos = Input.mousePosition;
            }
            else
            {
                touchPos = Input.GetTouch(0).position;
            }

            Vector2 viewportPos = Camera.main.ScreenToViewportPoint(touchPos);

            if (prevViewportPos.x != -999)
            {
                velocity = (viewportPos - prevViewportPos) / Time.deltaTime;
            }
            else
            {
                velocity = Vector2.zero;
            }

            prevViewportPos = viewportPos;
        }

        //decide which way should it slide if there is no destination yet
        if (!isTouchingTab && isPrevTouchingTab)
        {
            if (velocity.x < 0 - velocityToSwipe && curTabIndex < tabCount - 1)
            {
                curTabIndex++;
            }
            else if (velocity.x > velocityToSwipe && curTabIndex > 0)
            {
                curTabIndex--;
            }
            else
            {
                RectTransform rt    = content.GetComponent <RectTransform>();
                float         width = transform.GetComponent <RectTransform>().rect.width;

                float curX = 0 - rt.localPosition.x;
                float temp = curX % width;

                if (temp < width / 2)
                {
                    curTabIndex = (int)(curX / width);
                }
                else
                {
                    curTabIndex = (int)(curX / width) + 1;
                }
            }
        }

        if (!isTouchingTab)
        {
            //ContentMoveToX(currentMoveTarget);
            ContentMoveToX(0 - (transform.GetComponent <RectTransform>().rect.width *curTabIndex));
        }

        isPrevTouching    = isTouching;
        isPrevTouchingTab = isTouchingTab;
    }
예제 #7
0
 public override void OnPointerDown(PointerEventData eventData)
 {
     joystickPosition = RectTransformUtility.WorldToScreenPoint(Camera.main, background.position);
     OnDrag(eventData);
 }
예제 #8
0
    public IEnumerator handleMatches(bool playerTurn = true)
    {
        // wait until other stuff finishes
        while (BattleInfo.gameState != GameState.HandlingMatches)
        {
            ;
        }

        List <Vector2>[,] matchGroupLists = getAllMatches();
        Dictionary <GamePieceType, int> matchedPieces = new Dictionary <GamePieceType, int>();

        // start with 0 pieces of each type matched
        foreach (GamePieceType gptype in Enum.GetValues(typeof(GamePieceType)))
        {
            matchedPieces.Add(gptype, 0);
        }

        bool matchedFervor = false;

        bool extraTurn = false;


        foreach (List <Vector2> matchGrp in matchGroupLists)
        {
            if (matchGrp.Count >= 3)
            {
                // record pieces matched so they can have their match effect
                GamePieceType matchType = triangles [(int)matchGrp [0].x, (int)matchGrp [0].y].GetComponent <TriangleHandler> ().type;

                matchedPieces [matchType] += matchGrp.Count;

                if (matchType == GamePieceType.Fervor)
                {
                    matchedFervor = true;
                }


                // if you match enough pieces, you get an extra turn!
                if (matchGrp.Count >= 4)
                {
                    Vector2 positionOfFirstPiece = RectTransformUtility.WorldToScreenPoint(
                        Camera.main, incenters [(int)matchGrp [0].x, (int)matchGrp [0].y]);

                    extraTurn = true;
                    UIHandler.Instance().spawnRisingText(positionOfFirstPiece, "Extra Turn!", Color.red, floatingDistance: 15,
                                                         lifespan: 1.5f, fontSize: 18, fontStyle: FontStyle.Normal);
                }

                yield return(explodePieces(matchGrp));

                yield return(applyMatchedPieces(matchType, matchedPieces[matchType]));
            }
        }

        // if you got an extra turn, let that register briefly before giving next turn.
        // TODO: probably remove this when game pieces slide into place instead of appearing instantly


        if (!matchedFervor)
        {
            if (BattleInfo.playerWentLast)
            {
                BattleInfo.doPlayerFervorDecay();
            }
            else
            {
                BattleInfo.currentEnemy.doFervorDecay();
            }
        }

        fillBoard();

        // if the board is left with no matches, reset it.
        while (getLegalSwaps().Count == 0)
        {
            reset();
        }

        if (extraTurn)
        {
            yield return(new WaitForSeconds(1.5f));
        }

        // TODO: instead of always switching turns after handling matches, wait for falling pieces
        //       to finish falling, handle their matches, and only switch turns once this process yields
        //       no more matches



        // if the game should be over now (someone's health is 0), do end-game popup
        if (BattleInfo.playerHealth == 0)
        {
            UIHandler.Instance().youLostDialog();
            yield break;
        }
        else if (BattleInfo.currentEnemy.health == 0)
        {
            UIHandler.Instance().youWonDialog();
            yield break;
        }


        // Display "Your turn" or "enemy's turn" for some amount of time first,
        float timeToShowTurnSwitch = 1.5f;

        if (!extraTurn)           // only show if it's the beginning of the turn, not an extra turn
        {
            if (BattleInfo.playerWentLast)
            {
                Vector2 middleScreen = RectTransformUtility.WorldToScreenPoint(Camera.main, Camera.main.transform.position);
                UIHandler.Instance().spawnRisingText(middleScreen, "Enemy Turn", Color.red, floatingDistance: 0,
                                                     lifespan: timeToShowTurnSwitch, fontSize: 70, fontStyle: FontStyle.Normal);
            }
            else                 //if ((BattleInfo.playerWentLast && extraTurn) || (!BattleInfo.playerWentLast && !extraTurn))
            {
                Vector2 middleScreen = RectTransformUtility.WorldToScreenPoint(Camera.main, Camera.main.transform.position);
                UIHandler.Instance().spawnRisingText(middleScreen, "Your Turn", Color.cyan, floatingDistance: 0,
                                                     lifespan: timeToShowTurnSwitch, fontSize: 70, fontStyle: FontStyle.Normal);
            }
        }
        yield return(new WaitForSeconds(timeToShowTurnSwitch));

        // then actually change turns
        if ((BattleInfo.playerWentLast && !extraTurn) || (!BattleInfo.playerWentLast && extraTurn))
        {
            // wait a little longer, to feel like the enemy is "thinking"...
            yield return(new WaitForSeconds(timeToShowTurnSwitch));

            BattleInfo.gameState = GameState.EnemyTurn;
        }
        else             // if ((BattleInfo.playerWentLast && extraTurn) || (!BattleInfo.playerWentLast && !extraTurn))
        {
            BattleInfo.gameState = GameState.PlayerTurn;
        }



        yield return(null);
    }
예제 #9
0
    public IEnumerator applyMatchedPieces(GamePieceType type, int numPieces)
    {
        // prep floating text stuff
        GameObject playerSprite = GameObject.Find("Player Sprite");
        Vector2    spritePos    = RectTransformUtility.WorldToScreenPoint(Camera.main, playerSprite.transform.position);

        if (BattleInfo.playerWentLast)
        {
            switch (type)
            {
            case GamePieceType.Damage:
                // player deals damage
                float damageDealt = (1 + BattleInfo.playerFervorMultiplier * BattleInfo.playerFervor) * numPieces;
                if (damageDealt > 0)
                {
                    BattleInfo.currentEnemy.takeDamage(damageDealt);
                }
                break;

            case GamePieceType.Healing:
                float prevHealth = BattleInfo.playerHealth;
                BattleInfo.playerHealth += numPieces;
                BattleInfo.playerHealth  = Mathf.Min(BattleInfo.playerMaxHealth, BattleInfo.playerHealth);

                // floating healing text!
                float roundedHealing = BattleInfo.playerHealth - prevHealth;
                if (roundedHealing > 0)
                {
                    UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedHealing.ToString(),
                                                         Constants.Instance().healingColor, floatingDistance: 90, lifespan: 2.5f);
                }
                break;

            case GamePieceType.Coin:
                float prevCoins = BattleInfo.Coins;
                BattleInfo.Coins += numPieces;

                // floating money text!
                float roundedCoins = BattleInfo.Coins - prevCoins;
                if (roundedCoins > 0)
                {
                    UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedCoins.ToString(),
                                                         Constants.Instance().coinColor, floatingDistance: 90, lifespan: 2.5f);
                }
                break;

            case GamePieceType.Fervor:
                float prevFervor = BattleInfo.playerFervor;
                BattleInfo.playerFervor += numPieces;
                BattleInfo.playerFervor  = Mathf.Min(BattleInfo.playerFervor, BattleInfo.playerMaxFervor);

                // floating fervor text!
                float roundedFervor = BattleInfo.playerFervor - prevFervor;
                if (roundedFervor > 0)
                {
                    UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedFervor.ToString(),
                                                         Constants.Instance().fervorColor, floatingDistance: 90, lifespan: 2.5f);
                }
                break;

            case GamePieceType.Summoning:
                float prevSummoning = BattleInfo.playerSummoning;
                BattleInfo.playerSummoning += numPieces;
                BattleInfo.playerSummoning  = Mathf.Round(Mathf.Min(BattleInfo.playerSummoning, BattleInfo.playerMaxSummoning));

                // floating summoning-gain text!
                float roundedSummoning = BattleInfo.playerSummoning - prevSummoning;
                if (roundedSummoning > 0)
                {
                    UIHandler.Instance().spawnRisingText(spritePos, "+" + roundedSummoning.ToString(),
                                                         Constants.Instance().summoningColor, floatingDistance: 90, lifespan: 2.5f);
                }
                break;

            default:
                yield return(null);

                break;
            }
        }
        else             // player didn't go last
        {
            switch (type)
            {
            case GamePieceType.Damage:
                // enemy deals damage
                float prevValue = BattleInfo.playerHealth;
                BattleInfo.playerHealth -= (1 + BattleInfo.currentEnemy.fervorMultiplier * BattleInfo.currentEnemy.fervor) * numPieces;
                BattleInfo.playerHealth  = Mathf.Round(Mathf.Max(0, BattleInfo.playerHealth));
                float damageDealt = prevValue - BattleInfo.playerHealth;
                // floating damage text!
                if (damageDealt > 0)
                {
                    UIHandler.Instance().spawnRisingText(spritePos, "-" + damageDealt.ToString(),
                                                         Constants.Instance().damageColor, floatingDistance: -90, lifespan: 2.5f);
                }
                break;

            case GamePieceType.Healing:
                BattleInfo.currentEnemy.healDamage(numPieces);
                break;

            case GamePieceType.Coin:
                // nobody's gettin' that gold!

                // maybe some special enemies will collect gold and do something with it, or give more gold
                // when you defeat them.
                break;

            case GamePieceType.Fervor:
                BattleInfo.currentEnemy.addFervor(numPieces);
                break;

            case GamePieceType.Summoning:
                BattleInfo.currentEnemy.addSummoning(numPieces);
                break;

            default:
                yield return(null);

                break;
            }
        }
    }
예제 #10
0
 void Update()
 {
     //hpBar UI가 몬스터를 따라다니게함
     hpBarUI.transform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, HpBarPos.position);
 }
예제 #11
0
 public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
 {
     return(RectTransformUtility.RectangleContainsScreenPoint(this._target, sp, eventCamera));
 }
예제 #12
0
    //데미지 뜨고 없어지는 코루틴 함수
    IEnumerator DamageUICoroutine(int Damage, bool isCritical)
    {
        if (isAlive == false)
        {
            yield break;
        }

        GameObject DamageUILocal;

        if (isCritical == true)
        {
            DamageUILocal = Instantiate(CriticalDamageUI, new Vector2(-3000, -3000), Quaternion.identity
                                        , GameObject.Find("Canvas").GetComponent <RectTransform>());
        }
        else
        {
            DamageUILocal = Instantiate(DamageUI, RectTransformUtility.WorldToScreenPoint(Camera.main, DamageTextPos.position), Quaternion.identity
                                        , GameObject.Find("Canvas").GetComponent <RectTransform>());
        }

        DamageUILocal.GetComponent <RectTransform>().position = RectTransformUtility.WorldToScreenPoint(Camera.main, DamageTextPos.position);

        if (Damage > 5)
        {
            DamageUILocal.GetComponentInChildren <Text>().text = Damage.ToString();
        }
        else
        {
            if (Random.Range(0, 6) <= 1)
            {
                DamageUILocal.GetComponentInChildren <Text>().text = "MISS";
            }
            else
            {
                DamageUILocal.GetComponentInChildren <Text>().text = Damage.ToString();
            }

            isCritical = false;
        }

        Destroy(DamageUILocal, 0.6f);

        RectTransform rectTr = DamageUILocal.GetComponent <RectTransform>();

        float alpha = 1.0f;

        for (int i = 0; i < 30; i++)
        {
            if (DamageUILocal != null || rectTr != null)
            {
                rectTr.Translate(Vector3.up * 2f);
                DamageUILocal.GetComponentInChildren <Text>().color = new Color(1, 1, 1, alpha);
                if (isCritical)
                {
                    DamageUILocal.GetComponent <Image>().color = new Color(1, 1, 1, alpha);
                }

                alpha -= 0.03f;

                yield return(new WaitForSeconds(0.02f));
            }
        }
    }
예제 #13
0
 private float Distance(Vector2 pos1, Vector2 pos2)
 {
     RectTransformUtility.ScreenPointToLocalPointInRectangle(this.content, pos1, null, out pos1);
     RectTransformUtility.ScreenPointToLocalPointInRectangle(this.content, pos2, null, out pos2);
     return(Vector2.Distance(pos1, pos2));
 }
예제 #14
0
 public virtual bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
 {
     return(!base.isActiveAndEnabled || RectTransformUtility.RectangleContainsScreenPoint(this.rectTransform, sp, eventCamera));
 }
예제 #15
0
        public void OnDrag(PointerEventData eventData)
        {
            if (!_isDragging)
            {
                return;
            }
            if (!isValid)
            {
                CancelDrag();
                return;
            }
            //Set dragging object on cursor
            var     canvas = _draggingObject.GetComponentInParent <Canvas>();
            Vector3 worldPoint;

            RectTransformUtility.ScreenPointToWorldPointInRectangle(canvas.GetComponent <RectTransform>(), eventData.position,
                                                                    canvas.renderMode != RenderMode.ScreenSpaceOverlay ? canvas.worldCamera : null, out worldPoint);
            _draggingObject.position = worldPoint;

            ReorderableList _oldReorderableListRaycasted = _currentReorderableListRaycasted;

            //Check everything under the cursor to find a ReorderableList
            EventSystem.current.RaycastAll(eventData, _raycastResults);
            for (int i = 0; i < _raycastResults.Count; i++)
            {
                _currentReorderableListRaycasted = _raycastResults[i].gameObject.GetComponent <ReorderableList>();
                if (_currentReorderableListRaycasted != null)
                {
                    break;
                }
            }

            //If nothing found or the list is not dropable, put the fake element outsite
            if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false ||
                (_oldReorderableListRaycasted != _reorderableList && !IsTransferable) ||
                ((_fakeElement.parent == _currentReorderableListRaycasted.Content
                    ? _currentReorderableListRaycasted.Content.childCount - 1
                    : _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable) ||
                _currentReorderableListRaycasted.maxItems <= 0)
            {
                RefreshSizes();
                _fakeElement.transform.SetParent(_reorderableList.DraggableArea, false);
                // revert the displaced element when not hovering over its list
                if (_displacedObject != null)
                {
                    revertDisplacedElement();
                }
            }
            //Else find the best position on the list and put fake element on the right index
            else
            {
                if (_currentReorderableListRaycasted.Content.childCount < _currentReorderableListRaycasted.maxItems && _fakeElement.parent != _currentReorderableListRaycasted.Content)
                {
                    _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false);
                }

                float minDistance = float.PositiveInfinity;
                int   targetIndex = 0;
                float dist        = 0;
                for (int j = 0; j < _currentReorderableListRaycasted.Content.childCount; j++)
                {
                    var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent <RectTransform>();

                    if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.y - worldPoint.y);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup)
                    {
                        dist = Mathf.Abs(c.position.x - worldPoint.x);
                    }
                    else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup)
                    {
                        dist = (Mathf.Abs(c.position.x - worldPoint.x) + Mathf.Abs(c.position.y - worldPoint.y));
                    }

                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        targetIndex = j;
                    }
                }
                if ((_currentReorderableListRaycasted != _oldReorderableListRaycasted || targetIndex != _displacedFromIndex) &&
                    _currentReorderableListRaycasted.Content.childCount == _currentReorderableListRaycasted.maxItems)
                {
                    Transform toDisplace = _currentReorderableListRaycasted.Content.GetChild(targetIndex);
                    if (_displacedObject != null)
                    {
                        revertDisplacedElement();
                        if (_currentReorderableListRaycasted.Content.childCount > _currentReorderableListRaycasted.maxItems)
                        {
                            displaceElement(targetIndex, toDisplace);
                        }
                    }
                    else if (_fakeElement.parent != _currentReorderableListRaycasted.Content)
                    {
                        _fakeElement.SetParent(_currentReorderableListRaycasted.Content, false);
                        displaceElement(targetIndex, toDisplace);
                    }
                }
                RefreshSizes();
                _fakeElement.SetSiblingIndex(targetIndex);
                _fakeElement.gameObject.SetActive(true);
            }
        }
예제 #16
0
파일: ETCDPad.cs 프로젝트: lswzzz/BombMan
    private void GetTouchDirectionDown(Vector2 position, Camera cam)
    {
        Vector2 localPoint;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(cachedRectTransform, position, cam, out localPoint);

        Vector2 buttonSize = this.rectTransform().sizeDelta / 3f;

        tmpAxis = Vector2.zero;

        if (localPoint.y >= -buttonSize.y / 2f && localPoint.y <= buttonSize.y / 2f && localPoint.x >= -buttonSize.x / 2f && localPoint.x <= buttonSize.x / 2f)
        {
            axisCenter.ResetAxis();
            axisCenter.axisState = ETCAxis.AxisState.Down;
        }

        Vector2 LeftUp    = new Vector2(-this.rectTransform().sizeDelta.x / 2f, this.rectTransform().sizeDelta.y / 2f);
        Vector2 LeftDown  = new Vector2(-this.rectTransform().sizeDelta.x / 2f, -this.rectTransform().sizeDelta.y / 2f);
        Vector2 RightUp   = new Vector2(this.rectTransform().sizeDelta.x / 2f, this.rectTransform().sizeDelta.y / 2f);
        Vector2 RightDown = new Vector2(this.rectTransform().sizeDelta.x / 2f, -this.rectTransform().sizeDelta.y / 2f);

        if ((localPoint.x < -buttonSize.x / 2f && Vector2.Dot(localPoint, LeftUp) > 0 && Vector2.Dot(localPoint, LeftDown) > 0 && dPadAxisCount == DPadAxis.Two_Axis) ||
            (dPadAxisCount == DPadAxis.Four_Axis && localPoint.x < -buttonSize.x / 2f))
        {
            tmpAxis.x = -1;
        }

        // right
        if ((localPoint.x > buttonSize.x / 2f && Vector2.Dot(localPoint, RightUp) > 0 && Vector2.Dot(localPoint, RightDown) > 0 && dPadAxisCount == DPadAxis.Two_Axis) ||
            (dPadAxisCount == DPadAxis.Four_Axis && localPoint.x > buttonSize.x / 2f))
        {
            tmpAxis.x = 1;
        }


        // Up
        if ((localPoint.y > buttonSize.y / 2f && Vector2.Dot(localPoint, LeftUp) > 0 && Vector2.Dot(localPoint, RightUp) > 0 && dPadAxisCount == DPadAxis.Two_Axis) ||
            (dPadAxisCount == DPadAxis.Four_Axis && localPoint.y > buttonSize.y / 2f))
        {
            tmpAxis.y = 1;
        }


        // Down
        if ((localPoint.y < -buttonSize.y / 2f && Vector2.Dot(localPoint, LeftDown) > 0 && Vector2.Dot(localPoint, RightDown) > 0 && dPadAxisCount == DPadAxis.Two_Axis) ||
            (dPadAxisCount == DPadAxis.Four_Axis && localPoint.y < -buttonSize.y / 2f))
        {
            tmpAxis.y = -1;
        }

        // Left
        //      if ( (localPoint.x < -buttonSize.x/2f && localPoint.y > -buttonSize.y/2f && localPoint.y< buttonSize.y/2f && dPadAxisCount== DPadAxis.Two_Axis)
        //    || (dPadAxisCount== DPadAxis.Four_Axis &&  localPoint.x < -buttonSize.x/2f) ){
        //	tmpAxis.x = -1;
        //}

        //// right
        //if ( (localPoint.x > buttonSize.x/2f && localPoint.y> -buttonSize.y/2f && localPoint.y< buttonSize.y/2f && dPadAxisCount== DPadAxis.Two_Axis)
        //	|| (dPadAxisCount== DPadAxis.Four_Axis &&  localPoint.x > buttonSize.x/2f) ){
        //	tmpAxis.x = 1;
        //}


        //// Up
        //if ( (localPoint.y > buttonSize.y/2f && localPoint.x>-buttonSize.x/2f && localPoint.x<buttonSize.x/2f && dPadAxisCount == DPadAxis.Two_Axis)
        //	|| (dPadAxisCount== DPadAxis.Four_Axis &&  localPoint.y > buttonSize.y/2f) ){
        //	tmpAxis.y = 1;
        //}


        //// Down
        //if ( (localPoint.y < -buttonSize.y/2f && localPoint.x>-buttonSize.x/2f && localPoint.x<buttonSize.x/2f && dPadAxisCount == DPadAxis.Two_Axis)
        //	|| (dPadAxisCount== DPadAxis.Four_Axis &&  localPoint.y <- buttonSize.y/2f) ){
        //	tmpAxis.y = -1;
        //}
    }
예제 #17
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();

            Rect pixelRect = RectTransformUtility.PixelAdjustRect(rectTransform, canvas);

            float pixelSizeScaler = 1.0f;

            if (canvas != null)
            {
                pixelSizeScaler = 1.0f / canvas.scaleFactor;
            }

            float adjustedLineWeight = LineWeight * pixelSizeScaler;

            switch (SnappedProperties.Position)
            {
            case GeoUtils.SnappedPositionAndOrientationProperties.PositionTypes.Center:
                center.x = pixelRect.center.x;
                center.y = pixelRect.center.y;
                break;

            case GeoUtils.SnappedPositionAndOrientationProperties.PositionTypes.Top:
                center.x = pixelRect.center.x;
                center.y = pixelRect.yMax - adjustedLineWeight;
                break;

            case GeoUtils.SnappedPositionAndOrientationProperties.PositionTypes.Bottom:
                center.x = pixelRect.center.x;
                center.y = pixelRect.yMin;
                break;

            case GeoUtils.SnappedPositionAndOrientationProperties.PositionTypes.Left:
                center.x = pixelRect.xMin;
                center.y = pixelRect.center.y;
                break;

            case GeoUtils.SnappedPositionAndOrientationProperties.PositionTypes.Right:
                center.x = pixelRect.xMax;
                center.y = pixelRect.center.y;
                break;

            default:
                throw new System.ArgumentOutOfRangeException();
            }

            float width  = 0.0f;
            float height = 0.0f;

            switch (SnappedProperties.Orientation)
            {
            case GeoUtils.SnappedPositionAndOrientationProperties.OrientationTypes.Horizontal:
                width  = pixelRect.width;
                height = adjustedLineWeight;

                //				topLeft.x -= width * 0.5f + adjustedLineWeight;
                break;

            case GeoUtils.SnappedPositionAndOrientationProperties.OrientationTypes.Vertical:
                width  = adjustedLineWeight;
                height = pixelRect.height;

                //				topLeft.y += height * 0.5f - adjustedLineWeight;
                break;

            default:
                throw new System.ArgumentOutOfRangeException();
            }

            ShapeUtils.Rects.AddRect(
                ref vh,
                center,
                width,
                height,
                color,
                GeoUtils.ZeroV2
                );
        }
예제 #18
0
    protected override void LateUpdate()
    {
        if (content == null || viewport == null)
        {
            return;                                      //refuse to work.
        }
#if (UNITY_EDITOR || UNITY_STANDALONE_WIN) && !ART_USE
        if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            if (InputManager.Instance.GetPointerOverUI(-1) == content.gameObject)
            {
                Vector2 pos = Input.mousePosition;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(content, pos, GameObjectUtil.GetUICamera(), out pos);

                float w = Input.GetAxis("Mouse ScrollWheel");
                if (Mathf.Abs(w) > 0.01f)
                {
                    ScaleContain(w * MouseWheelSensitivity, pos);

                    if (draggingPointer != null)
                    {
                        //Debug.Log("OnEndDrag " + draggingPointer.pointerId + "/" + draggingPointer.position);
                        base.OnEndDrag(draggingPointer);
                        draggingPointer = null;
                    }

                    for (int i = 0; i < pointerList.Count; i++)
                    {
                        pointerList[i].eligibleForClick = false;
                    }
                }
            }
        }
#endif

        ////*********Debug
        //DebugInfo();
        ////*********

        if (pointerList.Count == 2)
        {
            Vector2 posA;
            Vector2 posB;
            Vector2 posA_O;
            Vector2 posB_O;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(content, pointerList[1].pressPosition + pointerList[1].delta, pointerList[1].pressEventCamera, out posA);
            RectTransformUtility.ScreenPointToLocalPointInRectangle(content, pointerList[0].pressPosition + pointerList[0].delta, pointerList[0].pressEventCamera, out posB);
            RectTransformUtility.ScreenPointToLocalPointInRectangle(content, pointerList[1].pressPosition, pointerList[1].pressEventCamera, out posA_O);
            RectTransformUtility.ScreenPointToLocalPointInRectangle(content, pointerList[0].pressPosition, pointerList[0].pressEventCamera, out posB_O);

            float delta_pos = (posA - posB).magnitude / (posA_O - posB_O).magnitude;
            delta_pos -= 1;

            if (Mathf.Abs(delta_pos) > 0.01f)
            {
                delta_pos *= GetTouchSpeed();

                Vector2 center_pos = (posA_O + posB_O) * 0.5f;
                ScaleContain(delta_pos, center_pos);
            }
        }

        base.LateUpdate();
    }