protected void SpawnNewTileInQueue(TileSpawnRule spawnRule)
	{
		Match3Tile newTile = spawnRule.SpawnNewTile();
		newTile.LocalPosition = spawnPoint;
		
		// Deactivate and hide the tile until the spawn queue is processed.
		newTile.gameObject.SetActive(false);

		spawnQueue.Enqueue(newTile);
		
		if ( !isSpawnQueueUpdating )
		{
			StartCoroutine(ProcessSpawnQueue());
		}
	}
예제 #2
0
    public bool FindMatchesAndUndo(bool isBoardSetup)
    {
//		Debug.Log("[MatchesUndoer] FindMatchesAndUndo called...");

        // Look for any tile matches on the given board data.
        if (matchesFinder.FindMatches())
        {
            List <Match3Tile> lastMatches = matchesFinder.lastFoundMatches;
            lastMatchedBoardPieces.Clear();

            // Cache the board pieces from the last matched tiles found.
            for (int i = 0; i < lastMatches.Count; i++)
            {
                // When "isBoardSetup" = true we must undo matches made by all tiles that can have color and that can be matched (so we undo initial locked tiles matches).
                if ((!isBoardSetup || !lastMatches[i].IsTileIgnoredByAntiMatchSystems) &&
                    (lastMatches[i].GetType() == typeof(NormalTile) ||
                     isBoardSetup && lastMatches[i].canHaveColor && lastMatches[i].CanBeMatched && !(lastMatches[i] is TriggerTile)))
                {
                    lastMatchedBoardPieces.Add(lastMatches[i].BoardPiece as Match3BoardPiece);
                }
            }

            // Undo all the matches found by looking at the board positions the matches were found.
//			Debug.Log("Initial matches found: " + lastMatches.Count);
            for (int i = 0; i < lastMatchedBoardPieces.Count; i++)
            {
                // Check if this board piece has an initial spawn rule that contains at least one "randomColor" based RuleEntry
                List <RuleEntry> ruleEntries      = lastMatchedBoardPieces[i].initialTileSpawnRule.ruleEntries;
                bool             tileCanBeChanged = false;
                for (int j = 0; j < ruleEntries.Count; j++)
                {
                    if (ruleEntries[j].randomColor)
                    {
                        tileCanBeChanged = true;
                        break;
                    }
                }

                if (!tileCanBeChanged)
                {
                    continue;
                }

                TileColorType[] ignoreTileColors = ComputeIgnoreColorListFromNeighbors(lastMatchedBoardPieces[i]);

                if (ignoreTileColors != null)
                {
                    TileColorType newTileColor = TileSpawnRule.GetRandomTileColorDifferentFrom(ignoreTileColors);
                    if (newTileColor == TileColorType.None)
                    {
//						Debug.LogWarning("[MatchesUndoer] Couldn't find a color to replace tile for match undo: " + lastMatchedBoardPieces[i].Tile);
                    }
                    else
                    {
//						Debug.Log("Changing tile: " + lastMatchedBoardPieces[i].Tile);

                        System.Type lastTileType = lastMatchedBoardPieces[i].Tile.GetType();

                        GameObject.DestroyImmediate(lastMatchedBoardPieces[i].Tile.gameObject);

                        // Spawn new tile of the same type but random color different from the ones computed above with "ComputeIgnoreTilesListFromNeighbors".
                        Match3Tile newTile = Match3BoardRenderer.Instance.SpawnSpecificTileAt(lastMatchedBoardPieces[i].BoardPosition, lastTileType,
                                                                                              newTileColor, false, isBoardSetup);

                        if (OnNewTileSpawned != null)
                        {
                            OnNewTileSpawned(newTile);
                        }

//						Debug.Log("with tile: " + newTile);
                    }
                }
            }

            return(true);
        }

        return(false);
    }
	protected void AddToImmediateSpawnList(TileColorType dropTileColor)
	{
		TileSpawnRule tileSpawnRule = new TileSpawnRule();
		
		tileSpawnRule.numberOfExecutions = 1;
		tileSpawnRule.ownerList = immediateSpawnList;
		
		RuleEntry ruleEntry = tileSpawnRule.ruleEntries[0];
		
		ruleEntry.RuleTileType = typeof(DropTile);
		ruleEntry.ColorSelection = ColorSelectionMethod.ColorBased;
		ruleEntry.RuleTileColor = dropTileColor;
		ruleEntry.randomColor = false;
		
		immediateSpawnList.Add(tileSpawnRule);
		
//		Debug.LogError("[AddToImmediateSpawnList()]");
	}