I have a set of tiles. Each of these tiles has a number attached called the sprite index. When reading these tiles to place them into the world, I take that number and use it to look up a sprite from a scriptable object which holds an array of sprites, called a sprite pallet. I need to access a pallet from the static class that holds the map generation. I also need to be able to set that pallet beforehand and to put sprites in it somehow. I can do one or the other, but not both. I either have a palate I cant use or a sad empty palate that holds no sprites
I have tried making a mono behavior that has an instance variable that is hooked up with get/set into a static class with an array of pallets but It does not show up in the editor, making it rather hard to assign pallets to.
Does anyone know a good way of getting premade, persistent objects, be they scriptable or image-based, into a static class?
I don’t know how much the code will help with this question, but here it is, just in case
[Serializable]
public class Map
{
//map data
public int sizeX;
public int sizeY;
public int spritePallate;
public float[,] heightMap;
public bool[,] walkableMap;
public int[,] spriteIndexMap;
}
public static class MapReader
{
public static Tile[,] GeneratePhysicalMap(Map map)
{
DestroyPhysicalMapTiles();
if (map == null)
{
map = new Map(backupMapSize.x, backupMapSize.y);
}
tileParent = new GameObject("Tile Parent").transform;
tiles = new Tile[map.sizeX,map.sizeY];
Vector2 mapHalfHeight = new Vector2(map.sizeX / 2.5f, map.sizeY / 2.5f);
for (int x = 0; x < map.sizeX; x++)
{
for (int y = 0; y < map.sizeY; y++)
{
Tile tile = map.SetTileProperties(x, y);
GameObject gameObjectTile = InstantateTileGameObject(mapHalfHeight, tile);
gameObjectTile.AddComponent<TileBehaviour>().tile = tile;
tiles[x, y] = tile;
gameObjectTile.AddComponent<BoxCollider>().size = new Vector3(1, 1, .2f);
gameObjectTile.AddComponent<SpriteRenderer>().sprite = GetSpriteFromIndexAndPallete(tile.spriteIndex,/*ERROR*/);
}
}
return tiles;
}
public static Sprite GetSpriteFromIndexAndPallete(int spriteIndex, SpritePallate spritePallate)
{
return spritePallate.sprites[spriteIndex];
}
}
[CreateAssetMenu(fileName = "Pallate", menuName = "SpritePallate", order = 0)]
public class SpritePallate : ScriptableObject
{
public int ID = 0;
public Sprite[] sprites;
}