private UI CreateOneGem(int i, int j, GemType[] excudeGemTypes) { GemType random = GemType.FIRE; switch (excudeGemTypes.Length) { case 0: random = BattleMapFactory.GetRandomGemType(BattleMapFactory.gemTypes); break; case 1: random = BattleMapFactory.GetRandomGemTypeExcude(excudeGemTypes[0]); break; case 2: random = BattleMapFactory.GetRandomGemTypeExcude(excudeGemTypes[0], excudeGemTypes[1]); break; } GameObject obj = GameObject.Instantiate(items[random], map.gameObject.transform); Vector2Int key = new Vector2Int(i, j); Vector2Int rawPos; Vector3 pos = Game.Scene.GetComponent <StaticGridComponent>().GetPosInGrid(key, out rawPos); UI gem = ComponentFactory.Create <UI, GameObject>(obj); gem.gameObject.GetComponent <RectTransform>().anchoredPosition = pos; GemComponent gemComp = gem.AddComponent <GemComponent, GemData, GemType>(new GemData(), random); gemComp.SetGridPosition(rawPos); gems.Add(key, gem); return(gem); }
/// <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(); }
public UI CreateOneGemObject(int col, int depth = 1) { GemType random = BattleMapFactory.GetRandomGemType(BattleMapFactory.gemTypes); GameObject obj = GameObject.Instantiate(items[random], map.gameObject.transform); Vector2Int rawPos = Vector2Int.Zero; obj.gameObject.GetComponent <RectTransform>().anchoredPosition = Game.Scene.GetComponent <StaticGridComponent>().GetSpawPos(col, depth, out rawPos); UI gem = ComponentFactory.Create <UI, GameObject>(obj); GemComponent gemComp = gem.AddComponent <GemComponent, GemData, GemType>(new GemData(), random); gemComp.SetGridPosition(rawPos); return(gem); }