Last active
August 21, 2017 13:12
-
-
Save ronyx69/a3fff79130e59fd5b7210ed5228ab812 to your computer and use it in GitHub Desktop.
Source code of the theme decals mod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ColossalFramework.Plugins; | |
using ColossalFramework.UI; | |
using ICities; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Reflection; | |
using System.Xml.Serialization; | |
using UnityEngine; | |
namespace ThemeDecals | |
{ | |
public class ThemeDecalsMod : IUserMod | |
{ | |
public string Name => "Theme Decals"; | |
public string Description => "Adds decals which match the current map theme."; | |
} | |
public class ThemeDecalsLoading : LoadingExtensionBase | |
{ | |
public override void OnLevelUnloading() | |
{ | |
base.OnLevelUnloading(); | |
ThemeDecals.Loaded = false; | |
} | |
} | |
public class ThemeDecalsThreading : ThreadingExtensionBase | |
{ | |
public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) | |
{ | |
base.OnUpdate(realTimeDelta, simulationTimeDelta); | |
if (!ThemeDecals.Loaded && LoadingManager.instance.m_loadingComplete) | |
{ | |
ThemeDecals.ApplyTextures(); | |
ThemeDecals.Loaded = true; | |
} | |
} | |
} | |
public class ThemeDecals | |
{ | |
public static bool Loaded; | |
internal static void ApplyTextures() | |
{ | |
var terrain = UnityEngine.Object.FindObjectOfType<TerrainProperties>(); | |
for (uint i = 0; i < PrefabCollection<PropInfo>.LoadedCount(); i++) | |
{ | |
var prefab = PrefabCollection<PropInfo>.GetLoaded(i); | |
if (prefab == null) continue; | |
if (prefab.m_mesh.name == "themedecal-cliff") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_cliffDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_cliffDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-grass") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_grassDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_grassDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-oil") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_oilDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_oilDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-ore") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_oreDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_oreDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-sand") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_sandDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_sandDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-gravel") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_gravelDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_gravelDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-ruined") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_ruinedDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_ruinedDiffuse); | |
} | |
else if (prefab.m_mesh.name == "themedecal-pavement") | |
{ | |
prefab.m_material.SetTexture("_MainTex", terrain.m_pavementDiffuse); | |
prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrain.m_pavementDiffuse); | |
} | |
ApplyProperties(); | |
} | |
} | |
internal static void ApplyProperties() | |
{ | |
for (uint i = 0; i < PrefabCollection<PropInfo>.LoadedCount(); i++) | |
{ | |
var prefab = PrefabCollection<PropInfo>.GetLoaded(i); | |
if (prefab == null) continue; | |
if (prefab.m_mesh.name == "themedecal-cliff" || | |
prefab.m_mesh.name == "themedecal-grass" || | |
prefab.m_mesh.name == "themedecal-oil" || | |
prefab.m_mesh.name == "themedecal-ore" || | |
prefab.m_mesh.name == "themedecal-sand" || | |
prefab.m_mesh.name == "themedecal-gravel" || | |
prefab.m_mesh.name == "themedecal-ruined" || | |
prefab.m_mesh.name == "themedecal-pavement") | |
{ | |
prefab.m_lodMaterial = prefab.m_material; | |
prefab.m_lodRenderDistance = 18000; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment