Exemple #1
0
        /// <summary>
        /// From world to grid
        /// </summary>
        public static Vector2Int GetGridPosition(ptTilemap tilemap, Vector2 locPosition)
        {
            int x = Mathf.FloorToInt(locPosition.x / tilemap.CellSize.x + ptTilemap.CHUNK_SIZE_X / 2f);
            int y = Mathf.FloorToInt(locPosition.y / tilemap.CellSize.y + ptTilemap.CHUNK_SIZE_Y / 2f);

            return(new Vector2Int(x, y));
        }
Exemple #2
0
        public void Init(ptTilemap ptTilemap)
        {
            this.ptTilemap     = ptTilemap;
            spriteRenderer     = gameObject.AddComponent <SpriteRenderer>();
            defaultMat         = new Material(Shader.Find("Sprites/Default"));
            texture            = new Texture2D(ptTilemap.CHUNK_SIZE_X, ptTilemap.CHUNK_SIZE_Y);
            texture.filterMode = FilterMode.Point;
            var sp = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 1);

            colors = new Color[ptTilemap.CHUNK_SIZE_X * ptTilemap.CHUNK_SIZE_Y];
            spriteRenderer.sprite = sp;

            UpdateRenderer();
            UpdateColliderActive();
            Fill(Color.clear);
        }
Exemple #3
0
 /// <summary>
 /// From world x to grid x
 /// </summary>
 public static int GetGridY(ptTilemap tilemap, Vector2 locPosition)
 {
     return(GetGridY(locPosition, tilemap.CellSize));
 }
Exemple #4
0
 /// <summary>
 /// From grid to world
 /// </summary>
 /// <returns></returns>
 public static Vector3 GetGridWorldPos(ptTilemap tilemap, int gridX, int gridY)
 {
     return(tilemap.transform.TransformPoint(new Vector2((gridX + .5f) * tilemap.CellSize.x, (gridY + .5f) * tilemap.CellSize.y)));
 }