Beispiel #1
0
    void OnMouseUp()
    {
        if (_activeInputLens != null)
        {
            CameraOrbit.unlockedLens.RemoveRequestsWithContext(this);
            CameraOrbit.inputFreeLens.RemoveRequestsWithContext(this);
            _activeInputLens = null;

            List <BitSlotWidget> bitSlots = GetBreed().GetBitSlots();
            for (int i = 0; i < bitSlots.Count; i++)
            {
                bitSlots[i].SetHighlight(false);
            }

            ResetFadeoutTimer();

            bool allMatched = _spriteToSlotMap.Count == _bitSprites.Length;
            if (allMatched)
            {
                GetBreed().AssignBlock(this);
                Destroy(gameObject);
            }
            else
            {
                GameSounds.PostEvent2D(GameSound.SFX_BlockDeny);

                Vector2 screenMin       = Vector2.zero;
                Vector2 screenMax       = new Vector2(Screen.width, Screen.height);
                Vector2 screenBoundDiff = screenMax - screenMin;
                screenMin += screenBoundDiff * 0.001f;
                screenMax -= screenBoundDiff * 0.001f;
                Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z);

                bool uiOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetBreedRect(), mousePos, Camera.main);
                if (!uiOverlap)
                {
                    Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
                    if (Physics.Raycast(worldPos, Camera.main.transform.forward, out _hitInfo, Mathf.Infinity, _planetLayer, QueryTriggerInteraction.Ignore))
                    {
                        _dropPos = _hitInfo.point + _hitInfo.normal * _dropGroundOffset;
                    }
                }

                if (_changeScaleRoutine != null)
                {
                    StopCoroutine(_changeScaleRoutine);
                }

                _changeScaleRoutine = StartCoroutine(ChangeScaleRoutine(false));
                _dropRoutine        = StartCoroutine(DropRoutine());
            }

            BreedPanel breedPanel = UIManager.GetPanel <BreedPanel>();
            breedPanel.GetLeftRotateRect().gameObject.SetActive(false);
            breedPanel.GetRightRotateRect().gameObject.SetActive(false);
        }
    }
    void PointStemAtTarget()
    {
        Vector3 screenPos = Camera.main.WorldToScreenPoint(_target.position);

        Vector3 targetPos = Vector3.zero;

        RectTransformUtility.ScreenPointToWorldPointInRectangle(_stemBoundsRect, screenPos, null, out targetPos);

        Vector3[] fourCorners = new Vector3[4];
        _stemBoundsRect.GetWorldCorners(fourCorners);

        _spriteStem.transform.position = WadeUtils.Clamp(targetPos, fourCorners[0], fourCorners[2]);
        _spriteStem.transform.LerpLookAt2D(targetPos, Time.deltaTime * _stemLerpSpeed);
    }
Beispiel #3
0
    void OnMouseDown()
    {
        if (CameraOrbit.inputFreeLens && _dropRoutine == null)
        {
            _dropPos = transform.position;
            _groundShadow.enabled = false;

            for (int i = 0; i < _bitSprites.Length; i++)
            {
                _bitSprites[i].sortingOrder = _uiLayerOrder;
            }

            _activeInputLens = new LensHandle <bool>(this, false);

            CameraOrbit.unlockedLens.AddRequest(new LensHandle <bool>(this, false));
            CameraOrbit.inputFreeLens.AddRequest(_activeInputLens);

            Vector2 screenMin = Vector2.zero;
            Vector2 screenMax = new Vector2(Screen.width, Screen.height);
            screenMin += (screenMax - screenMin) * 0.001f;
            screenMax -= (screenMax - screenMin) * 0.001f;
            Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z);

            BreedPanel breedPanel = UIManager.GetPanel <BreedPanel>();
            breedPanel.GetLeftRotateRect().gameObject.SetActive(true);
            breedPanel.GetRightRotateRect().gameObject.SetActive(true);

            if (!breedPanel.gameObject.activeSelf)
            {
                UIManager.GetPanel <SwapPanel>().OnClickBreed();
            }



            _prevUIOverlap = RectTransformUtility.RectangleContainsScreenPoint(breedPanel.GetBreedRect(), mousePos, Camera.main);

            ResetFadeoutTimer();
        }
    }
Beispiel #4
0
    void OnMouseDrag()
    {
        if (_activeInputLens != null)
        {
            Vector2 screenMin = Vector2.zero;
            Vector2 screenMax = new Vector2(Screen.width, Screen.height);

            Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z);

            Vector2 screenBoundDiff = screenMax - screenMin;
            screenMin += screenBoundDiff * 0.001f;
            screenMax -= screenBoundDiff * 0.001f;
            mousePos   = ((Vector3)WadeUtils.Clamp((Vector2)mousePos, screenMin, screenMax)).SetZ(mousePos.z);

            Vector3 worldPos          = Camera.main.ScreenToWorldPoint(mousePos);
            Vector3 rotatePivotOffset = _rotatePivot.position - transform.position;
            transform.position = worldPos + Camera.main.transform.forward * _selectedCamOffset - rotatePivotOffset;

            bool uiOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetBreedRect(), mousePos, Camera.main);
            if (uiOverlap != _prevUIOverlap)
            {
                if (_changeScaleRoutine != null)
                {
                    StopCoroutine(_changeScaleRoutine);
                }

                _changeScaleRoutine = StartCoroutine(ChangeScaleRoutine(uiOverlap));

                _groundShadow.GetShadow().gameObject.SetActive(!uiOverlap);
                _prevUIOverlap = uiOverlap;
            }

            if (!uiOverlap)
            {
                if (Physics.Raycast(worldPos, Camera.main.transform.forward - Camera.main.transform.up * 0.17f, out _hitInfo, Mathf.Infinity, _planetLayer, QueryTriggerInteraction.Ignore))
                {
                    _groundShadow.SetPos(_hitInfo.point);
                }
            }

            bool leftOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetLeftRotateRect(), mousePos, Camera.main);
            if (leftOverlap != _prevLeftOverlap)
            {
                if (leftOverlap)
                {
                    GameSounds.PostEvent2D(GameSound.SFX_BlockRotateCounterClockwise);

                    if (_rotateRoutine != null)
                    {
                        StopCoroutine(_rotateRoutine);
                    }

                    _rotateRoutine = StartCoroutine(RotateRoutine(false));
                }

                _prevLeftOverlap = leftOverlap;
            }

            bool rightOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetRightRotateRect(), mousePos, Camera.main);
            if (rightOverlap != _prevRightOverlap)
            {
                if (rightOverlap)
                {
                    GameSounds.PostEvent2D(GameSound.SFX_BlockRotateClockwise);

                    if (_rotateRoutine != null)
                    {
                        StopCoroutine(_rotateRoutine);
                    }

                    _rotateRoutine = StartCoroutine(RotateRoutine(true));
                }

                _prevRightOverlap = rightOverlap;
            }

            _spriteToSlotMap.Clear();
            List <BitSlotWidget> bitSlots = GetBreed().GetBitSlots();
            for (int i = 0; i < bitSlots.Count; i++)
            {
                bitSlots[i].SetHighlight(false);
            }

            for (int i = 0; i < _bitSprites.Length; i++)
            {
                SpriteRenderer bitSprite     = _bitSprites[i];
                Vector3        spriteViewPos = Camera.main.WorldToViewportPoint(bitSprite.transform.position);
                for (int j = 0; j < bitSlots.Count; j++)
                {
                    BitSlotWidget bitSlot = bitSlots[j];
                    if (!bitSlot.used)
                    {
                        Vector3 slotViewPos = Camera.main.WorldToViewportPoint(bitSlot.transform.position);
                        if (Vector2.Distance(spriteViewPos, slotViewPos) < _gridSlotMaxDist)
                        {
                            // Temp-mark used so slots are distinct
                            bitSlot.used = true;
                            bitSlot.SetHighlight(true);
                            _spriteToSlotMap.Add(bitSprite, bitSlot);
                            break;
                        }
                    }
                }
            }

            // Unmark temp-used slots
            foreach (var kvp in _spriteToSlotMap)
            {
                kvp.Value.used = false;
            }

            ResetFadeoutTimer();
        }
    }
Beispiel #5
0
 public Vector4 Clamp(Vector4 v)
 {
     return(WadeUtils.Clamp(v, min, max));
 }