Ejemplo n.º 1
0
        void PreviewStore(Store store)
        {
            FloorPlan floorPlan = null;

            foreach (var layer in store.layers)
            {
                if ((FloorPlan)layer != null)
                {
                    floorPlan = (FloorPlan)layer;
                    break;
                }
            }

            if (floorPlan == null)
            {
                return;
            }

            const int size    = 128;
            var       preview = new Texture2D(size, size);

            preview.filterMode = FilterMode.Point;

            store.tiles = new Dictionary <Vector2Int, TileData>();

            System.Random rnd;

            if (string.IsNullOrEmpty(store.StartingSeed))
            {
                rnd = new System.Random(System.Environment.TickCount);
            }
            else
            {
                rnd = new System.Random(store.StartingSeed.GetHashCode());
            }

            floorPlan.Apply(store, rnd);
            var tiles = floorPlan.GetTiles();

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    preview.SetPixel(x, y, Color.black);
                }
            }

            foreach (var tile in tiles)
            {
                preview.SetPixel(tile.x + (size / 2), tile.y + (size / 2), Color.green);
            }

            preview.Apply();
            pic.normal.background = preview;
        }