Example #1
0
        /// <summary>
        /// 上移元素石
        /// </summary>
        private void UpTweenGems()
        {
            List <Vector2Int> clearInfo = ClearGems();

            clearInfo = clearInfo.OrderByDescending(item => item.x).ToList();
            List <Vector2Int> checkedInfo = new List <Vector2Int>();

            remappedUIs.Clear();
            StaticGridComponent staticGridComponent = Game.Scene.GetComponent <StaticGridComponent>();
            BattleMapFactory    battleMapFactory    = Game.Scene.GetComponent <UIComponent>().GetUIFactory(UIType.GemMap) as BattleMapFactory;

            for (int i = 0; i < clearInfo.Count; i++)
            {
                Vector2Int clearKey = clearInfo[i];
                if (checkedInfo.Contains(clearKey))
                {
                    continue;
                }
                int depth = 1;
                for (int j = clearKey.x - 1; j >= 0; j--)
                {
                    Vector2Int moveKey = new Vector2Int(j, clearKey.y);
                    if (clearInfo.Contains(moveKey))
                    {
                        depth++;
                        checkedInfo.Add(moveKey);
                        continue;
                    }
                    GemComponent gemComponent = allGemsObject[moveKey].GetComponent <GemComponent>();
                    Vector2Int   pos          = gemComponent.gridPos;
                    pos.y += staticGridComponent.CellSize.y * depth;
                    gemComponent.SetGridPosition(pos);
                    tweenNum++;
                    //Log.Debug(allGemsObject[moveKey].rectTransform.anchoredPosition.ToString());
                    allGemsObject[moveKey].gameObject.transform.DOLocalMove(new Vector3(pos.x, pos.y, 0), tweenInternal * depth).OnComplete(() => { tweenNum--; }).Play();
                    //Log.Debug(allGemsObject[moveKey].rectTransform.anchoredPosition.ToString());
                }
                //Log.Debug(clearKey.ToString()+" depth : " +depth);
                for (int j = 0; j < depth; j++)
                {
                    UI           gem          = battleMapFactory.CreateOneGemObject(clearKey.y, j + 1);
                    GemComponent gemComponent = gem.GetComponent <GemComponent>();
                    Vector2Int   pos          = gemComponent.gridPos;
                    pos.y += staticGridComponent.CellSize.y * depth;
                    gemComponent.SetGridPosition(pos);
                    tweenNum++;
                    //Log.Debug(gem.rectTransform.anchoredPosition.ToString());
                    gem.gameObject.transform.DOLocalMove(new Vector3(pos.x, pos.y, 0), tweenInternal * depth).OnComplete(() => { tweenNum--; }).Play();
                    remappedUIs.Add(gem);
                }
            }
            needRemap = true;
            //Log.Debug("长度1: " + allGemsObject.Count+" 长度2:"+remappedUIs.Count+" tweenNum : "+tweenNum);
            foreach (var pair in allGemsObject)
            {
                remappedUIs.Add(pair.Value);
            }
            allGemsObject.Clear();
        }
Example #2
0
        private void ReMap()
        {
            DOTween.KillAll(true);
            StaticGridComponent staticGridComponent = Game.Scene.GetComponent <StaticGridComponent>();

            foreach (var item in remappedUIs)
            {
                Vector2Int pos = item.GetComponent <GemComponent>().gridPos;
                Vector2Int key = staticGridComponent.GetKeyInGrid(pos);
                allGemsObject[key] = item;
                allGemsObject[key].gameObject.GetComponent <Button>().onClick.RemoveAllListeners();
                AddEventListener(key, allGemsObject[key]);
                // Log.Debug("key: " + key + " position: " + pos);
            }
        }