Esempio n. 1
0
        public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
        {
            framewait = new WaitForSeconds(1 / (float)frameDelta);

            if (Application.isPlaying)
            {
                go = Instantiate(prefab);
            }

            Tilemap map = tilemap.GetComponent <Tilemap>();

            go.transform.position = map.CellToWorld(position) + Vector3.up * 0.5f * map.cellSize.y + Vector3.right * 0.5f * map.cellSize.x;

            if (Application.isPlaying)
            {
                go.transform.parent = map.transform;
            }
            else
            {
                return(base.StartUp(position, tilemap, null));
            }

            map.RefreshTile(position); //Refresh the tile so that the sprite is null

            return(true);              // base.StartUp(position, tilemap, null);
        }
Esempio n. 2
0
        public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
        {
            // Call base method first
            base.StartUp(position, tilemap, go);

            // Get per-position storage
            var tilemapInfo = tilemap.GetComponent <TilemapInformation>();

            // No TilemapInformation = fail
            if (tilemapInfo == null)
            {
                return(false);
            }

            // Update postion property
            return(tilemapInfo.Set(position, "health", health));
        }
Esempio n. 3
0
 /// <summary>
 /// Retrieves any tile animation data from the scripted tile.
 /// </summary>
 /// <param name="position">Position of the Tile on the Tilemap.</param>
 /// <param name="tilemap">The Tilemap the tile is present on.</param>
 /// <param name="tileAnimationData">Data to run an animation on the tile.</param>
 /// <returns>Whether the call was successful.</returns>
 public override bool GetTileAnimationData(Vector3Int location, ITilemap tileMap, ref TileAnimationData tileAnimationData)
 {
     if (m_AnimatedSprites.Length > 0)
     {
         tileAnimationData.animatedSprites    = m_AnimatedSprites;
         tileAnimationData.animationSpeed     = Random.Range(m_MinSpeed, m_MaxSpeed);
         tileAnimationData.animationStartTime = m_AnimationStartTime;
         if (0 < m_AnimationStartFrame && m_AnimationStartFrame <= m_AnimatedSprites.Length)
         {
             var tilemapComponent = tileMap.GetComponent <Tilemap>();
             if (tilemapComponent != null && tilemapComponent.animationFrameRate > 0)
             {
                 tileAnimationData.animationStartTime = (m_AnimationStartFrame - 1) / tilemapComponent.animationFrameRate;
             }
         }
         return(true);
     }
     return(false);
 }
Esempio n. 4
0
        private void UpdateTile(Vector3Int location, ITilemap tileMap, ref TileData tileData)
        {
            tileData.transform = Matrix4x4.identity;
            if (worldMap == null)
            {
                worldMap = tileMap.GetComponent <TileMapScript>().tilesWorldMap;
                xLength  = worldMap.GetUpperBound(0);
                yLength  = worldMap.GetUpperBound(1);
            }
            var currentTilePosX = location.x;
            var currentTilePosY = location.y;
            int currentId       = worldMap[currentTilePosX, currentTilePosY];

            int xLess = currentTilePosX - 1;
            int xMore = currentTilePosX + 1;
            int yMore = currentTilePosY + 1;
            int yLess = currentTilePosY - 1;
            int mask  = 0;

            if (yMore <= yLength)
            {
                int top = worldMap[currentTilePosX, yMore];
                mask += top > 0 ? 1 : 0;
            }

            if (xMore <= xLength)
            {
                int right = worldMap[xMore, currentTilePosY];
                mask += right > 0 ? 4 : 0;

                if (yMore <= yLength)
                {
                    int diaRightTop = worldMap[xMore, yMore];
                    mask += diaRightTop > 0 ? 2 : 0;
                }

                if (yLess > -1)
                {
                    int diagBottomRight = worldMap[xMore, yLess];
                    mask += diagBottomRight > 0 ? 8 : 0;
                }
            }

            if (yLess > -1)
            {
                int bottom = worldMap[currentTilePosX, yLess];
                mask += bottom > 0 ? 16 : 0;
            }

            if (xLess > -1)
            {
                int left = worldMap[xLess, currentTilePosY];
                mask += left > 0 ? 64 : 0;

                if (yLess > -1)
                {
                    int diagBottomLeft = worldMap[xLess, yLess];
                    mask += diagBottomLeft > 0 ? 32 : 0;
                }

                if (yMore <= yLength)
                {
                    int diagTopLeft = worldMap[xLess, yMore];
                    mask += diagTopLeft > 0 ? 128 : 0;
                }
            }

            byte original = (byte)mask;

            if ((original | 254) < 255)
            {
                mask = mask & 125;
            }
            if ((original | 251) < 255)
            {
                mask = mask & 245;
            }
            if ((original | 239) < 255)
            {
                mask = mask & 215;
            }
            if ((original | 191) < 255)
            {
                mask = mask & 95;
            }
            int index = GetIndex((byte)mask);

            if (index >= 0)
            {
                tileData.sprite    = m_Sprites[index];
                tileData.transform = GetTransform((byte)mask);
                tileData.flags     = TileFlags.LockTransform;
            }
        }
Esempio n. 5
0
        private void UpdateTile(Vector3Int location, ITilemap tileMap, ref TileData tileData)
        {
            tileData.transform = Matrix4x4.identity;
            tileData.color     = Color.white;
            // TODO refacto trop consommateur !
            var tileMapScript = tileMap.GetComponent <TileMapScript>();

            if (worldMap == null)
            {
                worldMap = tileMapScript.tilesWorldMap;
                xLength  = worldMap.GetUpperBound(0);
                yLength  = worldMap.GetUpperBound(1);
            }
            var currentTilePosX = tileMapScript.tilePosX + location.x;
            var currentTilePosY = tileMapScript.tilePosY + location.y;
            int currentId       = worldMap[currentTilePosX, currentTilePosY];

            int xLess = currentTilePosX - 1;
            int xMore = currentTilePosX + 1;
            int yMore = currentTilePosY + 1;
            int yLess = currentTilePosY - 1;
            int mask  = 0;

            if (yMore <= yLength)
            {
                int top = worldMap[currentTilePosX, yMore];
                top   = CheckIfSameId(top, currentId) ? top : 0;
                mask += top > 0 ? 1 : 0;
            }

            if (xMore <= xLength)
            {
                int right = worldMap[xMore, currentTilePosY];
                right = CheckIfSameId(right, currentId) ? right : 0;
                mask += right > 0 ? 4 : 0;

                if (yMore <= yLength)
                {
                    int diaRightTop = worldMap[xMore, yMore];
                    diaRightTop = CheckIfSameId(diaRightTop, currentId) ? diaRightTop : 0;
                    mask       += diaRightTop > 0 ? 2 : 0;
                }

                if (yLess > -1)
                {
                    int diagBottomRight = worldMap[xMore, yLess];
                    diagBottomRight = CheckIfSameId(diagBottomRight, currentId) ? diagBottomRight : 0;
                    mask           += diagBottomRight > 0 ? 8 : 0;
                }
            }

            if (yLess > -1)
            {
                int bottom = worldMap[currentTilePosX, yLess];
                bottom = CheckIfSameId(bottom, currentId) ? bottom : 0;
                mask  += bottom > 0 ? 16 : 0;
            }

            if (xLess > -1)
            {
                int left = worldMap[xLess, currentTilePosY];
                left  = CheckIfSameId(left, currentId) ? left : 0;
                mask += left > 0 ? 64 : 0;

                if (yLess > -1)
                {
                    int diagBottomLeft = worldMap[xLess, yLess];
                    diagBottomLeft = CheckIfSameId(diagBottomLeft, currentId) ? diagBottomLeft : 0;
                    mask          += diagBottomLeft > 0 ? 32 : 0;
                }

                if (yMore <= yLength)
                {
                    int diagTopLeft = worldMap[xLess, yMore];
                    diagTopLeft = CheckIfSameId(diagTopLeft, currentId) ? diagTopLeft : 0;
                    mask       += diagTopLeft > 0 ? 128 : 0;
                }
            }

            byte original = (byte)mask;

            if ((original | 254) < 255)
            {
                mask = mask & 125;
            }
            if ((original | 251) < 255)
            {
                mask = mask & 245;
            }
            if ((original | 239) < 255)
            {
                mask = mask & 215;
            }
            if ((original | 191) < 255)
            {
                mask = mask & 95;
            }
            int index = GetIndex((byte)mask);

            if (index >= 0)
            {
                tileData.sprite       = m_Sprites[index];
                tileData.transform    = GetTransform((byte)mask);
                tileData.flags        = TileFlags.LockTransform;
                tileData.colliderType = Tile.ColliderType.Grid;
            }
        }
Esempio n. 6
0
 public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData)
 {
     tileMap.GetComponent <TileMapScript>().SetTileData(location.x, location.y, ref tileData, m_Sprites);
 }