public Rect GetTexture(Chunk chunk, BlockPos pos, Direction direction) { if (usesConnectedTextures) { string blockName = chunk.GetBlock(pos).controller.Name(); bool wn = ConnectedTextures.IsSame(chunk, pos, -1, 1, direction, blockName); bool n = ConnectedTextures.IsSame(chunk, pos, 0, 1, direction, blockName); bool ne = ConnectedTextures.IsSame(chunk, pos, 1, 1, direction, blockName); bool w = ConnectedTextures.IsSame(chunk, pos, -1, 0, direction, blockName); bool e = ConnectedTextures.IsSame(chunk, pos, 1, 0, direction, blockName); bool es = ConnectedTextures.IsSame(chunk, pos, 1, -1, direction, blockName); bool s = ConnectedTextures.IsSame(chunk, pos, 0, -1, direction, blockName); bool sw = ConnectedTextures.IsSame(chunk, pos, -1, -1, direction, blockName); return(connectedTextures[ConnectedTextures.GetTexture(n, e, s, w, wn, ne, es, sw)]); } if (textures.Count == 1) { return(textures[0]); } if (textures.Count > 1) { float randomNumber = noiseGen.Generate(pos.x, pos.y, pos.z); randomNumber += 1; randomNumber /= 2; randomNumber *= textures.Count; return(textures[(int)randomNumber]); } Debug.LogError("There were no textures for " + textureName); return(new Rect()); }
public TextureIndex(bool loadEmpty = false) { if (loadEmpty) { return; } List <Texture2D> atlasTextures = new List <Texture2D>(); // Load all files in Textures folder atlasTextures.AddRange(Resources.LoadAll <Texture2D>(Config.Directories.TextureFolder)); //Load and generate all the connected textures List <Texture2D> connectedTextures = new List <Texture2D>(); connectedTextures.AddRange(Resources.LoadAll <Texture2D>(Config.Directories.ConnectedTextureFolder)); if (connectedTextures.Count != 0) { atlasTextures.AddRange(ConnectedTextures.GenerateConnectedTextures(connectedTextures)); } // Create new atlas atlas = new Texture2D(8192, 8192); atlas.filterMode = FilterMode.Point; // Generate atlas Rect[] rects = atlas.PackTextures(atlasTextures.ToArray(), 0, 8192, false); // Add each atlas entry into texture dictionary for (int i = 0; i < atlasTextures.Count; i++) { if (!atlasTextures[i]) { continue; } string[] fileName = atlasTextures[i].name.ToString().Split('-'); Rect texture = rects[i]; string textureName = fileName[0]; int connectedTextureType = -1; //Get the properties associated with this texture for (int n = 1; n < fileName.Length; n++) { switch (fileName[n][0]) { case 'c': int.TryParse(fileName[n].Substring(1), out connectedTextureType); break; default: break; } } //Create a texture collection with this name if it doesn't exist already TextureCollection collection; if (!textures.TryGetValue(textureName, out collection)) { collection = new TextureCollection(textureName); textures.Add(textureName, collection); } collection.AddTexture(texture, connectedTextureType); } }