Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/Unity/Farmlanders/Assets/General/TextureManager.cs
2022-11-12 13:10:03 +01:00

36 lines
1.2 KiB
C#

using System.Drawing;
using Terrain;
using UnityEngine;
namespace General {
public class TextureManager {
public readonly Material Material;
private readonly Vector2Int _tileDimensions;
private readonly Vector2 _tileUVs;
private readonly Vector2Int _tileCount;
public TextureManager(Material material, Vector2Int tileDimensions, World world) {
material.shader = world.noOutline;
Material = material;
_tileDimensions = tileDimensions;
_tileCount = new Vector2Int(
material.mainTexture.width / tileDimensions.x,
material.mainTexture.height / tileDimensions.y
);
_tileUVs = new Vector2(1f / _tileCount.x, 1f / _tileCount.y);
}
public RectangleF GetTile(int row, int col) {
row = _tileCount.y - row - 1;
return new RectangleF(col * _tileUVs.x + 0.0001f, row * _tileUVs.y + 0.0001f, _tileUVs.x - 0.0001f, _tileUVs.y - 0.0001f);
}
public RectangleF GetTile(int id) {
int col = id % _tileCount.y;
int row = id / _tileCount.x;
return GetTile(row, col);
}
}
}