Ejemplo n.º 1
0
        private void Awake()
        {
            UpperPositions = new BoardSlotView[14];
            LowerPositions = new BoardSlotView[14];

            PositionCursor = 0;
            _isUpper       = true;

            BoardSlotView tempRef = null;
            GameObject    tempObj = null;

            // Behold my greatest creation
            for (int i = 0; i < 14; i++)
            {
                tempObj = new GameObject("Upper_" + i);
                tempRef = tempObj.AddComponent <BoardSlotView>();

                tempObj.transform.position = UpperPositionsParent.position + Vector3.left * 6.5f + Vector3.right * i;
                tempObj.transform.SetParent(UpperPositionsParent);

                UpperPositions[i] = tempRef;

                tempObj = new GameObject("Lower_" + i);
                tempRef = tempObj.AddComponent <BoardSlotView>();

                tempObj.transform.position = LowerPositionsParent.position + Vector3.left * 6.5f + Vector3.right * i;
                tempObj.transform.SetParent(LowerPositionsParent);

                LowerPositions[i] = tempRef;
            }
        }
Ejemplo n.º 2
0
        public void TranslateToPosition(BoardSlotView p_boardSlotView, Action p_callBack)
        {
            BoardSlotView = p_boardSlotView;

            if (_translationInProgress)
            {
                StopCoroutine(_translationCoroutine);
            }

            _translationCoroutine = StartCoroutine(SmoothMovement(BoardSlotView.transform.position, p_callBack));
        }
Ejemplo n.º 3
0
        private void Update()
        {
            if (!CanTakeInput)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit2D rayHit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition));
                if (rayHit.transform != null)
                {
                    _selectedView = rayHit.transform.gameObject.GetComponent <GameTileView>();
                    if (_selectedView != null)
                    {
                        _lastBoardSlot = _selectedView.BoardSlotView;
                        _lastPosition  = _selectedView.transform.position;
                    }
                }
            }
            else if (Input.GetMouseButton(0))
            {
                if (_selectedView != null)
                {
                    MoveViewToWorldPosition(Input.mousePosition);
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                if (_selectedView != null)
                {
                    CanTakeInput = false;
                    BoardSlotView targetBoardSlot = null;
                    FindPosition(out targetBoardSlot);
                    if (_lastBoardSlot != null)
                    {
                        _lastBoardSlot.UnFill();
                        targetBoardSlot.Fill();

                        _selectedView.TranslateToPosition(targetBoardSlot, () => { ViewMoveFinished(); });
                    }
                    else
                    {
                        _selectedView.TranslateToPosition(_lastPosition, () => { ViewMoveFinished(); });
                    }

                    _selectedView = null;
                }
            }
        }
Ejemplo n.º 4
0
        ///<summary>
        /// Contains wierd double if becuse of the last day rush inside BoardView
        ///</summary>
        private bool FindPosition(out BoardSlotView p_boardView)
        {
            for (int i = 0; i < _playerBoard.UpperPositions.Length; i++)
            {
                if (Vector2.Distance(_playerBoard.UpperPositions[i].transform.position, _selectedView.transform.position) < 1f &&
                    !_playerBoard.UpperPositions[i].IsFilled)
                {
                    p_boardView = _playerBoard.UpperPositions[i];
                    return(true);
                }

                if (Vector2.Distance(_playerBoard.LowerPositions[i].transform.position, _selectedView.transform.position) < 1f &&
                    !_playerBoard.LowerPositions[i].IsFilled)
                {
                    p_boardView = _playerBoard.LowerPositions[i];
                    return(true);
                }
            }

            p_boardView = _lastBoardSlot;
            return(false);
        }