Example #1
0
        public override InputSimpleTiledModelData GetInputSimpleTiledData()
        {
            if (Application.isPlaying == false)
            {
                FillPrefabMap();
            }

            var tileConfigsData = CreateTileConfigData(tilePrefab =>
            {
                var symmetry = symmetrySets.GetSymmetryByTileName(tilePrefab.name);
                Debug.Log(tilePrefab.name + " " + symmetry);
                var config = new SimpleTiledModelTileConfig(tilePrefab, symmetry);

                return(config);
            });

            var inputData = new InputSimpleTiledModelData(tileConfigsData);
            var tiles     = new SimpleTiledModelTile[width, height, depth];

            ExecuteForEachTile((tileGo, pos, rotation) =>
            {
                tiles[(int)pos.x, (int)pos.y, (int)pos.z] = new SimpleTiledModelTile(tileConfigsData.GetConfig(tileGo.name), rotation);
            });

            var neighbors = new Dictionary <string, NeighborData>();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        var currentTile = tiles[x, y, z];
                        if (currentTile == null)
                        {
                            continue;
                        }

                        SimpleTiledModelTile nextTile;
                        string key;

                        for (var offset = 0; offset < 2; offset++)
                        {
                            var rx = x + 1 - offset;
                            var rz = z + offset;
                            if (rx >= width || rz >= depth)
                            {
                                continue;
                            }

                            var currentTileRotation = Card(currentTile.Rotation + offset);
                            nextTile = tiles[rx, y, rz];

                            if (nextTile == null)
                            {
                                continue;
                            }

                            var nextTileRotation = Card(nextTile.Rotation + offset);

                            key = currentTile.Config.Id + "." + currentTileRotation + " | " + nextTile.Config.Id + "." + nextTileRotation;

                            if (neighbors.ContainsKey(key))
                            {
                                continue;
                            }
                            Debug.Log(key);

                            neighbors.Add(key, new NeighborData(currentTile.Config, nextTile.Config, currentTileRotation, nextTileRotation));
                            DrawDebugLine(new Vector3(x, y - 0.5f, z), new Vector3(rx, y - 0.5f, rz));
                        }

                        if (y == 0)
                        {
                            continue;
                        }
                        nextTile = tiles[x, y - 1, z];
                        if (nextTile == null)
                        {
                            continue;
                        }

                        key = currentTile.Config.Id + "." + currentTile.Rotation + " | " + nextTile.Config.Id + "." + nextTile.Rotation + " |vertical";
                        if (neighbors.ContainsKey(key))
                        {
                            continue;
                        }
                        Debug.Log(key);

                        neighbors.Add(key, new NeighborData(currentTile.Config, nextTile.Config, currentTile.Rotation, nextTile.Rotation, false));
                        DrawDebugLine(new Vector3(x, y, z), new Vector3(x, y - 1, z));
                    }
                }
            }


            inputData.SetNeighbors(neighbors.Values.ToList());

            return(inputData);
        }