Exemple #1
0
        private void MakeGrid()
        {
            float totalSpan      = transform.GetComponent <RectTransform> ().rect.width - (m_Margin * 2);
            float perBoxSize     = totalSpan / ROW_COL_SIZE;
            float perBoxSizeBody = perBoxSize - (m_Padding * 2);

            float startIndexMultiplier = ROW_COL_SIZE % 2 == 0 ? ROW_COL_SIZE / 2 - 0.5f : ROW_COL_SIZE / 2;
            float startIndexX          = perBoxSize * -startIndexMultiplier;
            float startIndexY          = perBoxSize * startIndexMultiplier;

            float currentX = startIndexX;
            float currentY = startIndexY;

            for (int i = 0; i < ROW_COL_SIZE * ROW_COL_SIZE; i++)
            {
                GridBox gb = Instantiate(m_GridUIPrefab, transform);
                mGridBoxList.Add(gb);
                gb.SetBgSize(perBoxSizeBody);
                gb.transform.localPosition = new Vector2(currentX, currentY);

                currentX += perBoxSize;
                if (i > 0 && ((i + 1) % ROW_COL_SIZE) == 0)
                {
                    currentY -= perBoxSize;
                    currentX  = startIndexX;
                }
            }
        }
Exemple #2
0
        private GridBox GetAnimatingBox()
        {
            foreach (GridBox item in mAnimatingBoxes)
            {
                if (!item.gameObject.activeInHierarchy)
                {
                    return(item);
                }
            }

            GridBox gb = Instantiate(m_GridUIPrefab, transform);

            mAnimatingBoxes.Add(gb);
            return(mAnimatingBoxes[mAnimatingBoxes.Count - 1]);
        }
Exemple #3
0
        private void AnimateBoxToBox(Vector2Int _fromIndex, Vector2Int _toIndex)
        {
            GridBox gbFrom = mGridBoxList[GetMapedInex(_fromIndex.x, _fromIndex.y)];
            GridBox gbTo   = mGridBoxList[GetMapedInex(_toIndex.x, _toIndex.y)];

            //Debug.Log ("converting from " + gbFrom.GetCurrentValue () + " >> " + gbTo.GetCurrentValue ());
            Vector2 posFrom = gbFrom.transform.localPosition;
            Vector2 posTo   = gbTo.transform.localPosition;

            GridBox dummyBox = GetAnimatingBox();

            dummyBox.ModifyValue(gbFrom.GetCurrentValue());
            dummyBox.SetBgSize(gbFrom.GetComponent <RectTransform> ().sizeDelta.x);
            dummyBox.transform.localPosition = posFrom;

            dummyBox.gameObject.SetActive(true);
            gbFrom.ModifyValue(0);

            dummyBox.transform.DOLocalMove(posTo, m_AnimationDuration).OnComplete(() => {
                dummyBox.gameObject.SetActive(false);
                PrintGrid();
            });
        }