Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active August 21, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronyx69/a3fff79130e59fd5b7210ed5228ab812 to your computer and use it in GitHub Desktop.
Save ronyx69/a3fff79130e59fd5b7210ed5228ab812 to your computer and use it in GitHub Desktop.
Source code of the theme decals mod.
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