コード例 #1
0
    // Use this for initialization
    public TileSpriteController(World world) : base(world, "Tiles", world.Volume)
    {
        world.OnTileChanged     += OnChanged;
        world.OnTileTypeChanged += OnChanged;

        TileLookup = new Dictionary <string, TileBase>();
        foreach (var tiletype in PrototypeManager.TileType.Values)
        {
            UnityEngine.Tilemaps.Tile tile = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
            Sprite sprite = SpriteManager.GetSprite("Tile", tiletype.Type);
            tile.sprite = sprite;
            tile.name   = tiletype.Type;
            TileLookup[tiletype.Type] = tile;
        }

        TileLookup[TileType.Empty.Type] = null;

        objectParent.AddComponent <Grid>();

        errorTile        = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
        errorTile.sprite = SpriteManager.CreateErrorSprite();
        errorTile.name   = "ErrorTile";
        errorTile.color  = Color.white;

        fogTile        = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
        fogTile.sprite = SpriteManager.CreateBlankSprite();
        fogTile.name   = "FogTile";
        fogTile.color  = Color.gray;

        tilemaps         = new Tilemap[world.Depth];
        tilemapRenderers = new TilemapRenderer[world.Depth];
        for (int z = 0; z < world.Depth; z++)
        {
            GameObject go = new GameObject("Tile layer " + (z + 1));
            go.transform.SetParent(objectParent.transform);
            go.transform.position -= new Vector3(.5f, .5f, -z);

            tilemaps[z]                        = go.AddComponent <Tilemap>();
            tilemaps[z].orientation            = Tilemap.Orientation.XY;
            tilemapRenderers[z]                = go.AddComponent <TilemapRenderer>();
            tilemapRenderers[z].sortingLayerID = SortingLayer.NameToID("Tiles");
            tilemapRenderers[z].sortingOrder   = -z;

            TileBase[] tiles  = new TileBase[world.Width * world.Height];
            BoundsInt  bounds = new BoundsInt(0, 0, 0, world.Width, world.Height, 1);

            for (int y = 0; y < world.Height; y++)
            {
                for (int x = 0; x < world.Width; x++)
                {
                    Tile worldTile = world.GetTileAt(x, y, z);

                    tiles[x + (y * world.Width)] = DetermineTileBaseToUse(worldTile);
                }
            }

            tilemaps[z].SetTilesBlock(bounds, tiles);
        }
    }
コード例 #2
0
ファイル: Cell.cs プロジェクト: ImInfenix/HumankindsFall
 public Cell(Vector3Int positionInBoard, Vector3 worldPosition, UnityEngine.Tilemaps.Tile associatedTileInTilemap, Vector2Int boardSize, Board board)
 {
     _tileMapPosition = positionInBoard;
     _worldPosition   = worldPosition;
     _type            = new TileType(associatedTileInTilemap);
     _boardSize       = boardSize;
     _isColored       = false;
     _board           = board;
 }
コード例 #3
0
 private void InstantiateGridTiles(World world)
 {
     foreach (TileOWW tile in world.GetAllTiles())
     {
         UnityEngine.Tilemaps.Tile t = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
         t.sprite = TileType.Grid;
         t.name   = tile.GetX() + "_" + tile.GetY();
         tilemap.GetComponent <Tilemap>().SetTile(new Vector3Int(tile.GetX(), tile.GetY(), 0), t);
     }
 }
コード例 #4
0
    private static void InitializeTiles()
    {
        sand = new Tile[64];
        for (var i = 0; i < 64; i++)
        {
            sand[i] = Resources.Load <Tile>($"Tilemap/hard_sand/hard_sand_{i}");
        }

        brick = Resources.Load <Tile>("Tilemap/wall/brick");
    }
コード例 #5
0
ファイル: Entity_script.cs プロジェクト: Pikademic/BlackWhite
 IEnumerator ReverseColor()
 {
     Debug.Log("switching color");
     if (mytile == originalTile)
     {
         mytile = othertile;
     }
     else
     {
         mytile = originalTile;
     }
     GetComponent <SpriteRenderer>().color = mytile.color;
     tm.SetTile(Vector3Int.FloorToInt(transform.position), mytile);
     yield return(null);
 }
コード例 #6
0
ファイル: SaveTileAsPNG.cs プロジェクト: ZeroWR/AerandyrGame
    private static Texture2D GetTextureForTile(UnityEngine.Tilemaps.Tile tile)
    {
        //var sprite = tile.sprite;
        //var croppedTexture = new Texture2D((int)sprite.rect.width, (int)sprite.rect.height);
        ////var tmp = sprite.texture.GetRawTextureData<Color32>();
        ////Texture2D tmpTexture = new Texture2D(sprite.texture.width, sprite.texture.height);
        ////tmpTexture.LoadRawTextureData(tmp);
        //var pixels = sprite.texture.GetPixels((int)sprite.textureRect.x,
        //										(int)sprite.textureRect.y,
        //										(int)sprite.textureRect.width,
        //										(int)sprite.textureRect.height);
        //croppedTexture.SetPixels(pixels);
        //croppedTexture.Apply();

        //This works
        return(AssetPreview.GetAssetPreview(tile));
    }
コード例 #7
0
    // Update is called once per frame
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 point      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var     worldPoint = new Vector3Int(Mathf.FloorToInt(point.x), Mathf.FloorToInt(point.y), 0);

            var tiles = GameTiles.instance.tiles; // This is our Dictionary of tiles

            if (tiles.TryGetValue(worldPoint, out _tile))
            {
                UnityEngine.Tilemaps.Tile tile = ScriptableObject.CreateInstance <UnityEngine.Tilemaps.Tile>();
                tile.sprite = toChange;
                _tile.TilemapMember.SetTile(_tile.LocalPlace, tile);
                _tile.TileBase = _tile.TilemapMember.GetTile(_tile.LocalPlace);
            }
        }
    }
コード例 #8
0
        private void DrawMap(TilesMap map)
        {
            for (int y = 0; y < map.Height; ++y)
            {
                for (int x = 0; x < map.Width; ++x)
                {
                    DataModels.Tile tile = map[y, x];

                    Tile groundTile = GetTileSO(tile.Biom.Ground.AbstractObject as Sprite);
                    groundTilemap.SetTile(new Vector3Int(x, y, 0), groundTile);

                    if (tile.WaterBiom != null)
                    {
                        Tile waterTile = GetTileSO(tile.WaterBiom.Ground.AbstractObject as Sprite);
                        waterTilemap.SetTile(new Vector3Int(x, y, 0), waterTile);
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Loop through a bunch of tile positions and set all of the tiles to thd defined tile
        /// </summary>
        /// <param name="tilePosStart"></param>
        /// <param name="tilePosStop"></param>
        /// <param name="tile"></param>
        /// <param name="tileMap"></param>
        /// <param name="randomTiles">If random tiles is passed in then randomly paint all tiles</param>
        public static void SetTileBlock(Vector3Int tilePosStart, Vector3Int tilePosStop, Tile tile, Tilemap tileMap, Tile[] randomTiles, bool debug = false, bool performanceDebug = false)
        {
            var _myStartX = CalculateStartEnd(tilePosStart.x, tilePosStop.x);
            var _myStartY = CalculateStartEnd(tilePosStart.y, tilePosStop.y);
            // var _myStartZ = CalculateStartEnd( tilePosStart.z, tilePosStop.z );

            var startX = _myStartX.x;
            var startY = _myStartY.x;
            var endX   = _myStartX.y;
            var endY   = _myStartY.y;


            Stopwatch _sw = new Stopwatch();

            if (debug)
            {
                Debug.Log(string.Format("TileTools:SetTileBlock Start X{0},Y{1} - End X{2},Y{3}", startX, startY, endX,
                                        endY));
                if (performanceDebug)
                {
                    // Start timer to check performance
                    _sw.Start();
                }
            }

            // BoundsInt myB = new BoundsInt(-1, -1, 0, 3, 3, 1);
            // BoundsInt bounds = new BoundsInt(startX, startY, 0, endX, endY, 1);
            //BoundsInt(origin, size);
            BoundsInt bounds = new BoundsInt(new Vector3Int(startX, startY, 0), new Vector3Int(Mathf.Clamp(endX - startX, 1, int.MaxValue), Mathf.Clamp(endY - startY, 1, int.MaxValue), 1));

            // TileBase[] tileArray = new TileBase[endX * endY];
            TileBase[] tileArray = new TileBase[bounds.size.x * bounds.size.y * bounds.size.z];
            if (debug)
            {
                Debug.Log(string.Format("tileArray Size {0} Bounds X {1} Y {2} Z {3}", tileArray.Length, bounds.size.x,
                                        bounds.size.y, bounds.size.z));
            }

            for (int index = 0; index < tileArray.Length; index++)
            {
                //If random tiles passed in pick a random tile
                if (randomTiles.Length > 0)
                {
                    tileArray[index] = randomTiles[Random.Range(0, randomTiles.Length)];
                }
                else
                {
                    tileArray[index] = index % 2 == 0 ? tile : tile;
                }
            }

            tileMap.SetTilesBlock(bounds, tileArray);

            if (debug && performanceDebug)
            {
                // Stop timer
                _sw.Stop();
                var m_testResult = string.Format("[PerformanceTester] Execution time for loop: {0}ms",
                                                 _sw.ElapsedMilliseconds);
                Debug.Log(m_testResult);
            }
        }
コード例 #10
0
 public static void SetTileBlock(Vector3Int tilePosStart, Vector3Int tilePosStop, Tile tile, Tilemap tileMap, bool debug = false)
 {
     SetTileBlock(tilePosStart, tilePosStop, tile, tileMap, new Tile[0], debug);
 }
コード例 #11
0
        /// <summary>
        /// Loop through a bunch of tile positions and set all of the tiles to thd defined tile
        /// Less efficient then the bulk option but around for history sake
        /// </summary>
        /// <param name="tilePosStart"></param>
        /// <param name="tilePosStop"></param>
        /// <param name="tile"></param>
        /// <param name="tileMap"></param>
        public static void SetTileBlockLegacy(Vector3Int tilePosStart, Vector3Int tilePosStop, Tile tile, Tilemap tileMap, Tile[] randomTiles, bool debug = false)
        {
            var startX = tilePosStart.x;
            var startY = tilePosStart.y;
            var endX   = tilePosStop.x;
            var endY   = tilePosStop.y;

            Stopwatch _sw = new Stopwatch();

            if (debug)
            {
                Debug.Log(string.Format("TileTools:SetTileBlock Start X{0},Y{1} - End X{2},Y{3}", startX, startY, endX,
                                        endY));
                // Start timer to check performance
                _sw.Start();
            }

            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    if (randomTiles.Length > 0)
                    {
                        tileMap.SetTile(new Vector3Int(x, y, 0), randomTiles[Random.Range(0, randomTiles.Length)]);
                    }
                    else
                    {
                        tileMap.SetTile(new Vector3Int(x, y, 0), tile);
                    }
                }
            }

            if (debug)
            {
                // Stop timer
                _sw.Stop();

                var m_testResult = string.Format("[PerformanceTester] Execution time for loop: {0}ms",
                                                 _sw.ElapsedMilliseconds);
                Debug.Log(m_testResult);
            }
        }
コード例 #12
0
 /// <summary>
 /// Set a tile on a tilemap
 /// </summary>
 /// <param name="tilePos">Location to paint a tile</param>
 /// <param name="tile">What is the tile to be painted</param>
 /// <param name="tileMap">Tilemap to paint on</param>
 public static void SetTile(Vector3Int tilePos, Tilemap tileMap, Tile tile)
 {
     tileMap.SetTile(tilePos, tile);
 }
コード例 #13
0
 public void BlueColor()
 {
     paintTile = blueTile;
 }
コード例 #14
0
 public void GreenColor()
 {
     paintTile = greenTile;
 }