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); }
private void PrepareResource() { BattleMapFactory.Init(); if (items.Count > 0) { return; } #if UNITY_EDITOR m_BattleMap = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/BattleMap.prefab"); GameObject[] gemConfigs = new GameObject[5]; gemConfigs[0] = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/5xingyuansu/Jin.prefab"); gemConfigs[1] = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/5xingyuansu/Mu.prefab"); gemConfigs[2] = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/5xingyuansu/Shui.prefab"); gemConfigs[3] = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/5xingyuansu/Huo.prefab"); gemConfigs[4] = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/AssetBundles/Share/5xingyuansu/Tu.prefab"); for (int i = 0; i < gemConfigs.Length; i++) { GemType type = gemConfigs[i].GetComponent <GemConfig>().gemType; items.Add(type, gemConfigs[i]); } #endif }
private bool CheckAndMarkClearGems() { bool canClear = false; BattleMapFactory battleMapFactory = Game.Scene.GetComponent <UIComponent>().GetUIFactory(UIType.GemMap) as BattleMapFactory; for (int i = 0; i < battleMapFactory.row; i++) { for (int j = 0; j < battleMapFactory.col; j++) { if (j >= 2) { Vector2Int vector2Int = new Vector2Int(i, j); if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent gemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); vector2Int.y--; if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent leftGemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); vector2Int.y--; if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent leftLeftGemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); if (gemComponent.gemType == leftGemComponent.gemType && gemComponent.gemType == leftLeftGemComponent.gemType) { AddClearGemToList(new Vector2Int(i, j), gemComponent.Entity as UI); AddClearGemToList(new Vector2Int(i, j - 1), leftGemComponent.Entity as UI); AddClearGemToList(new Vector2Int(i, j - 2), leftLeftGemComponent.Entity as UI); } } if (i >= 2) { Vector2Int vector2Int = new Vector2Int(i, j); if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent gemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); vector2Int.x--; if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent upGemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); vector2Int.x--; if (!allGemsObject.ContainsKey(vector2Int)) { Log.Error(vector2Int.ToString()); } GemComponent upUpGemComponent = allGemsObject[vector2Int].GetComponent <GemComponent>(); if (gemComponent.gemType == upGemComponent.gemType && gemComponent.gemType == upUpGemComponent.gemType) { AddClearGemToList(new Vector2Int(i, j), gemComponent.Entity as UI); AddClearGemToList(new Vector2Int(i - 1, j), upGemComponent.Entity as UI); AddClearGemToList(new Vector2Int(i - 2, j), upUpGemComponent.Entity as UI); } } } } if (clearGems.Count > 0) { canClear = true; } return(canClear); }