Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change theme textures and colors ingame.
// scripts to change map theme textures, colors and other stuff ingame
// textures must be located in gamefolder/textures/
// also applies sharp textures mod default settings
// grass.png
if (File.Exists("textures/" + "grass.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "grass.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_grassDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// cliff.png
if (File.Exists("textures/" + "cliff.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "cliff.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_cliffDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// ruined.png
if (File.Exists("textures/" + "ruined.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "ruined.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_ruinedDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// sand.png
if (File.Exists("textures/" + "sand.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "sand.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_sandDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// pavement.png
if (File.Exists("textures/" + "pavement.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "pavement.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_pavementDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// oil.png
if (File.Exists("textures/" + "oil.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "oil.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_oilDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// gravel.png
if (File.Exists("textures/" + "gravel.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "gravel.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_gravelDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// ore.png
if (File.Exists("textures/" + "ore.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "ore.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_oreDiffuse = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// foam.png
if (File.Exists("textures/" + "foam.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "foam.png"));
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_waterFoam = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// road.png
if (File.Exists("textures/" + "road.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "road.png"));
UnityEngine.Object.FindObjectOfType<NetProperties>().m_upwardDiffuse = texture2D; }
NetManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// light.png
if (File.Exists("textures/" + "light.png")) { Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "light.png"));
UnityEngine.Object.FindObjectOfType<BuildingProperties>().m_lightColorPalette = texture2D; }
BuildingManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// waternormal.png
if (File.Exists("textures/" + "waternormal.png")) {
Texture2D texture2D = new Texture2D(1, 1);
texture2D.LoadImage(File.ReadAllBytes("textures/" + "waternormal.png"));
for (int i = 0; i < texture2D.width; i++) for (int j = 0; j < texture2D.height; j++) {
var px = texture2D.GetPixel(i, j); px.a = px.g; px.r = Mathf.LinearToGammaSpace(px.r);
px.g = px.r; px.b = px.r; texture2D.SetPixel(i, j, px); } texture2D.Apply();
UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_waterNormal = texture2D; }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// cliffnormal.png / sandnormal.png (both must be present and same resolution)
if (File.Exists("textures/" + "cliffnormal.png") && File.Exists("textures/" + "sandnormal.png")) {
Texture2D cliff = new Texture2D(1, 1); cliff.LoadImage(File.ReadAllBytes("textures/" + "cliffnormal.png"));
Texture2D sand = new Texture2D(1, 1); sand.LoadImage(File.ReadAllBytes("textures/" + "sandnormal.png"));
if (cliff.width == sand.width && cliff.height == sand.height) {
Texture2D texture2D = new Texture2D(cliff.width, cliff.height);
for (int i = 0; i < cliff.width; i++) for (int j = 0; j < cliff.height; j++) {
var cliffPX = cliff.GetPixel(i, j); var sandPX = sand.GetPixel(i, j); var px = texture2D.GetPixel(i, j);
px.r = Mathf.LinearToGammaSpace(cliffPX.r); px.g = Mathf.LinearToGammaSpace(cliffPX.g);
px.b = Mathf.LinearToGammaSpace(sandPX.r); px.a = sandPX.g; texture2D.SetPixel(i, j, px); }
texture2D.Apply(); UnityEngine.Object.FindObjectOfType<TerrainProperties>().m_cliffSandNormal = texture2D; } }
TerrainManager.instance.m_properties.InitializeShaderProperties();
foreach (var tx in UnityEngine.Object.FindObjectsOfType<Texture2D>()) { tx.anisoLevel=16; tx.mipMapBias=-0.4f; }
// tiling (uncomment the ones you want to change)
var terrain=UnityEngine.Object.FindObjectOfType<TerrainProperties>();
terrain.m_grassTiling=0.100f;
//terrain.m_cliffTiling=0.020f;
//terrain.m_ruinedTiling=0.090f;
//terrain.m_sandTiling=0.020f;
//terrain.m_pavementTiling=0.120f;
//terrain.m_oilTiling=0.020f;
//terrain.m_gravelTiling=0.020f;
//terrain.m_oreTiling=0.020f;
//terrain.m_cliffSandNormalTiling=0.020f;
TerrainManager.instance.m_properties.InitializeShaderProperties();
// decorations (sprites)
var terrain=UnityEngine.Object.FindObjectOfType<TerrainProperties>();
terrain.m_useCliffDecorations = false;
terrain.m_useFertileDecorations = false;
terrain.m_useGrassDecorations = false;
// color offsets
var terrain=UnityEngine.Object.FindObjectOfType<TerrainProperties>();
terrain.m_grassFertilityColorOffset = new Vector3( 0.005f, 0.005f, 0.005f);
terrain.m_grassFieldColorOffset = new Vector3(-0.005f, -0.005f, -0.009f);
terrain.m_grassForestColorOffset = new Vector3(-0.005f, -0.005f, -0.003f);
terrain.m_grassPollutionColorOffset = new Vector3( 0.000f, 0.000f, 0.000f);
TerrainManager.instance.m_properties.InitializeShaderProperties();
// water colors
var terrain=UnityEngine.Object.FindObjectOfType<TerrainProperties>();
terrain.m_waterColorClean = new Color32( 10, 10, 10, 255);
terrain.m_waterColorUnder = new Color32(170, 170, 170, 255);
terrain.m_waterColorDirty = new Color32( 14, 11, 13, 255);
TerrainManager.instance.m_properties.InitializeShaderProperties();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment