コード例 #1
0
 private void Select(GemView gem)
 {
     Deselect();
     selectedGem = gem;
     selectedGem.Select();
     Debug.Log("Select gem " + gem.Entity.Index);
 }
コード例 #2
0
 private void Deselect()
 {
     if (selectedGem != null)
     {
         selectedGem.Deselect();
     }
     selectedGem = null;
 }
コード例 #3
0
        private void InstanceView()
        {
            var gemViewObjInstance = MonoBehaviour.Instantiate(_gemData.gemPrefab);

            _gemView = gemViewObjInstance.AddComponent <GemView>();
            _gemView.SetGem(this);
            _gemView.SetGemData(_gemData);
        }
コード例 #4
0
        private void CheckSwipe(GemView gem1, GemView gem2)
        {
            Debug.Log("Swipe attempt " + gem1.Entity.Index + " - " + gem1.Entity.Index);
            var gem1Position = entityManager.GetComponentData <BoardPositionComponent>(gem1.Entity);
            var gem2Position = entityManager.GetComponentData <BoardPositionComponent>(gem2.Entity);

            if (BoardCalculator.IsNextToEachOther(gem1Position.Position, gem2Position.Position))
            {
                StartSwap(gem1.Entity, gem2.Entity);
            }
        }
コード例 #5
0
        void Update()
        {
            if (gameStateModel.State != Match3State.PlayerTurn)
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                currentGemUnderInput = null;
                var gemUnderMouse = GetGemUnderMouse();
                if (gemUnderMouse != null)
                {
                    currentGemUnderInput = gemUnderMouse;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                var gem = GetGemUnderMouse();

                if (currentGemUnderInput == gem)
                {
                    // Same gem as mouse down
                    if (gem != null)
                    {
                        if (gem != selectedGem)
                        {
                            SelectGem(gem);
                        }
                        else
                        {
                            Deselect();
                        }
                    }
                }
                else
                {
                    if (currentGemUnderInput != null)
                    {
                        CheckSwipe(currentGemUnderInput);
                    }
                }

                currentGemUnderInput = null;
            }
        }
コード例 #6
0
        private void StartSwap(Entity gem1, Entity gem2)
        {
            if (gameStateModel.State != Match3State.PlayerTurn)
            {
                return;
            }

            if (gem1 != Entity.Null && gem2 != Entity.Null)
            {
                var gem1BoardPosition = entityManager.GetComponentData <BoardPositionComponent>(gem1);
                var gem2BoardPosition = entityManager.GetComponentData <BoardPositionComponent>(gem2);
                signalBus.Fire(new Match3Signals.StartSwapSignal(gem1BoardPosition.Position, gem2BoardPosition.Position));

                Deselect();
                currentGemUnderInput = null;
            }
        }
コード例 #7
0
        private void CheckSwipe(GemView fromGem)
        {
            var     touchPosWorld   = cameraMain.ScreenToWorldPoint(Input.mousePosition);
            Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);

            Vector2 swipe = new Vector2(touchPosWorld2D.x - fromGem.transform.position.x, touchPosWorld2D.y - fromGem.transform.position.y);

            if (swipe.magnitude < 0.05f) // Too short swipe
            {
                return;
            }

            var  fromPosition = entityManager.GetComponentData <BoardPositionComponent>(fromGem.Entity);
            int2 nextGemCoord = fromPosition.Position;

            if (Mathf.Abs(swipe.x) > Mathf.Abs(swipe.y))
            {
                if (swipe.x > 0)
                {
                    nextGemCoord.x += 1;
                }
                else
                {
                    nextGemCoord.x -= 1;
                }
            }
            else
            {
                if (swipe.y > 0)
                {
                    nextGemCoord.y += 1;
                }
                else
                {
                    nextGemCoord.y -= 1;
                }
            }

            if (boardModel.IsPositionInBorders(nextGemCoord) && boardModel.HasEntityAt(nextGemCoord))
            {
                StartSwap(fromGem.Entity, boardModel.GetEntityAt(nextGemCoord));
            }
        }
コード例 #8
0
 private void SelectGem(GemView gem)
 {
     if (selectedGem == null)
     {
         Select(gem);
     }
     else
     {
         var gemPosition         = entityManager.GetComponentData <BoardPositionComponent>(gem.Entity);
         var selectedGemPosition = entityManager.GetComponentData <BoardPositionComponent>(selectedGem.Entity);
         Debug.Log("Select second gem " + gem.Entity.Index);
         if (BoardCalculator.IsNextToEachOther(gemPosition.Position, selectedGemPosition.Position))
         {
             StartSwap(gem.Entity, selectedGem.Entity);
         }
         else
         {
             Select(gem);
         }
     }
 }
コード例 #9
0
 private void OnDestructionAnimationComplete(GemView view)
 {
     view.OnDestructionAnimationComplete -= OnDestructionAnimationComplete;
     projectilePool.Return(view);
 }