コード例 #1
0
ファイル: GameManager.cs プロジェクト: punsal/HexFall-Clone
    private IEnumerator SwapItems(SwipeDirection swipeDirection)
    {
        if (currentSelectedGridItems.root == null)
        {
            yield break;
        }

        inputPanel.SetActive(false);

        IsScored = false;
        var swappingCount = 0;

        while (!IsScored)
        {
            swappingCount++;

            if (currentSelectedGridItems.neighbor1.Position.rowPosition + 1 == currentSelectedGridItems.root.Position.rowPosition)
            {
                if (((int)currentSelectedGridItems.neighbor1Direction + 1) % 6 != (int)currentSelectedGridItems.neighbor2Direction)
                {
                    Debug.Log("Weird things are happening.");
                    var newCurrentSelectedItems = currentSelectedGridItems;
                    newCurrentSelectedItems.neighbor2 = currentSelectedGridItems.neighbor1;
                    newCurrentSelectedItems.neighbor1 = currentSelectedGridItems.neighbor2;

                    currentSelectedGridItems = newCurrentSelectedItems;
                }
            }
            var rootPosition      = currentSelectedGridItems.root.transform.position;
            var neighbor1Position = currentSelectedGridItems.neighbor1.transform.position;
            var neighbor2Position = currentSelectedGridItems.neighbor2.transform.position;

            switch (swipeDirection)
            {
            case SwipeDirection.Left:
                GridSystem.Instance.Swap(
                    currentSelectedGridItems.root.Position,
                    currentSelectedGridItems.neighbor2.Position);

                GridSystem.Instance.Swap(
                    currentSelectedGridItems.neighbor1.Position,
                    currentSelectedGridItems.neighbor2.Position);

                currentSelectedGridItems.root.Move(neighbor2Position);
                currentSelectedGridItems.neighbor1.Move(rootPosition);
                currentSelectedGridItems.neighbor2.Move(neighbor1Position);
                break;

            case SwipeDirection.Right:
                GridSystem.Instance.Swap(
                    currentSelectedGridItems.root.Position,
                    currentSelectedGridItems.neighbor1.Position);

                GridSystem.Instance.Swap(
                    currentSelectedGridItems.neighbor1.Position,
                    currentSelectedGridItems.neighbor2.Position);

                currentSelectedGridItems.root.Move(neighbor1Position);
                currentSelectedGridItems.neighbor1.Move(neighbor2Position);
                currentSelectedGridItems.neighbor2.Move(rootPosition);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(swipeDirection), swipeDirection, null);
            }

            yield return(new WaitForSeconds(0.25f));

            PublisherSubscriber.Publish(GameEventType.CheckNeighbors);

            GridSystem.Instance.CheckScore();

            yield return(new WaitForSeconds(1f));

            while (IsChecking)
            {
                yield return(new WaitForSeconds(Time.deltaTime));
            }

            GridSystem.Instance.SelectGridItem(currentSelectedGridItems.gridPosition, currentSelectedGridItems.inputPosition);

            if (swappingCount == 3)
            {
                break;
            }
        }

        inputPanel.SetActive(true);

        if (!IsScored)
        {
            yield break;
        }
        TotalMoveCount++;
        PublisherSubscriber.Publish(GameEventType.UpdateMoveCount);
        totalPossibleMoveCount = GridSystem.Instance.GetPossibleMoveCount();
        CheckPossibleMoveCount();
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: punsal/HexFall-Clone
 private void OnSelectedGridItemsHandler(SelectedGridItems selectedGridItems)
 {
     currentSelectedGridItems = selectedGridItems;
 }