Пример #1
0
    private void CheckApplesInCollider()
    {
        InputHandler.HandleMouseInput(MouseInput.leftMouseBtnDown, () =>
        {
            selectionImage.gameObject.SetActive(true);
            startPos = camera.MousePosToWorldPos();
            selectionImage.rectTransform.anchoredPosition = startPos;
        });
        InputHandler.HandleMouseInput(MouseInput.leftMouseBtnPress, () =>
        {
            var area = camera.MousePosToWorldPos() - startPos;
            selectionImage.rectTransform.localScale = new Vector2(area.x, area.y);
            var pointA = camera.MousePosToWorldPos() * trCanvas.localScale;
            var pointB = startPos * trCanvas.localScale;
            var apples = Physics2D.OverlapAreaAll(pointA, pointB);

            if (appleList.Count != mPrevListCount)
            {
                appleList.RemoveAll(apple =>
                {
                    apple.ShowSelectionImage(false);
                    return(apple);
                });
            }
            mPrevListCount = appleList.Count;
            apples.ForEach(apple =>
            {
                UIItemApple itemApple         = null;
                Action <UIItemApple> callback = (_itemApple) => itemApple = _itemApple;
                apple.transform.SendMessage("GetInstance", callback, SendMessageOptions.DontRequireReceiver);

                if (itemApple != null && !appleList.Contains(itemApple))
                {
                    itemApple.ShowSelectionImage(true);
                    appleList.Add(itemApple);
                }
            });
        });
        InputHandler.HandleMouseInput(MouseInput.leftMouseBtnUp, () =>
        {
            ReleaseSelectedApples();
        });
    }
Пример #2
0
    private void GenerateApples()
    {
        mAppleArray = new UIItemApple[x, y];

        for (int _y = 0; _y < y; _y++)
        {
            for (int _x = 0; _x < x; _x++)
            {
                UIItemApple itemApple = null;
                applePool.Spawn(ref itemApple, trStage);
                itemApple.SetIndex(new Index(_x, _y))
                .SetName($"Apple[{_x}, {_y}]")
                .SetNumber(Random.Range(1, 10))
                .SetSize(new Vector2(mCellSize, mCellSize))
                .SetLocalPosition(new Vector2(_x + 0.5f, -_y - 0.5f) * mSpace - offSet)
                .SetLocalRotation(Quaternion.identity);
                mAppleArray[_x, _y] = itemApple;
            }
        }
    }
Пример #3
0
    private void ActivateGravityFall(List <UIItemApple> terminatedApples, Action finishCallback /*사과가 다 내려온 후에 검사 시작*/)
    {
        var orderedAppleList = terminatedApples.ToList();

        orderedAppleList.Sort((apple1, apple2) =>
        {
            if (apple1.index.y < apple2.index.y)
            {
                return(-1);
            }
            else if (apple1.index.y > apple2.index.y)
            {
                return(1);
            }
            else
            {
                if (apple1.index.x < apple2.index.x)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            }
        });

        var firstApple = orderedAppleList[0];
        var lastApple  = orderedAppleList[terminatedApples.Count - 1];

        int xAxisLength = Mathf.Abs(firstApple.index.x - lastApple.index.x) + 1;
        int yAxisLength = Mathf.Abs(firstApple.index.y - lastApple.index.y) + 1;
        var x           = 0;
        var y           = 0;

        orderedAppleList.ForEach(apple =>
        {
            UIItemApple itemApple = null;
            applePool.Spawn(ref itemApple, trStage);

            var index = apple.index;

            for (int _y = index.y - yAxisLength; _y >= 0; _y--)
            {
                var targetApple = mAppleArray[index.x, _y];
                if (!aboutToFallAppleList.Contains(targetApple))
                {
                    aboutToFallAppleList.Add(targetApple);
                }
            }
            if (xAxisLength > 1 && yAxisLength > 1)
            {
                if (x % xAxisLength == 0)
                {
                    y--;
                }
                x++;
            }
            else if (y > -yAxisLength)
            {
                y--;
            }
            index.y = y;
            itemApple.SetIndex(index)
            .SetNumber(Random.Range(1, 10))
            .SetSize(new Vector2(mCellSize, mCellSize))
            .SetLocalPosition(new Vector2(index.x + 0.5f, -index.y - 0.5f) * mSpace - offSet)
            .SetLocalRotation(Quaternion.identity);
            aboutToFallAppleList.Add(itemApple);
        });

        aboutToFallAppleList.ForEach(apple =>
        {
            var targetIndex = apple.index;
            targetIndex.y  += yAxisLength;
            var targetPos   = new Vector2(targetIndex.x + 0.5f, -targetIndex.y - 0.5f) * mSpace - offSet;
            apple.SetIndex(targetIndex)
            .SetName($"Apple[{targetIndex.x}, {targetIndex.y}]")
            .MoveToTarget(targetPos);
            mAppleArray[targetIndex.x, targetIndex.y] = apple;
        });
        aboutToFallAppleList.Clear();
        finishCallback();
    }