Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active February 27, 2021 13:26
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/4f06181c8082188418cd0c224f630a09 to your computer and use it in GitHub Desktop.
Save ronyx69/4f06181c8082188418cd0c224f630a09 to your computer and use it in GitHub Desktop.
Source code for Network Tiling mod. Allows controlling the tiling of network segment and node textures.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICities;
using UnityEngine;
namespace NetworkTiling
{
public class NetworkTilingMod : LoadingExtensionBase, IUserMod
{
public string Name => "Network Tiling";
public string Description => "Allows controlling the tiling of network segment and node textures.";
public override void OnLevelLoaded(LoadMode mode)
{
base.OnLevelLoaded(mode);
ApplyParams();
}
public override void OnLevelUnloading()
{
base.OnLevelUnloading();
}
private void ApplyParams()
{
for (uint i = 0; i < PrefabCollection<NetInfo>.LoadedCount(); i++)
{
var prefab = PrefabCollection<NetInfo>.GetLoaded(i);
if (prefab == null) continue;
if (prefab.m_segments != null) for (uint j = 0; j < prefab.m_segments.Length; j++)
{
if (prefab.m_segments[j].m_material == null) continue;
if (prefab.m_segments[j].m_material.name.Contains("NetworkTiling"))
{
string[] floats = prefab.m_segments[j].m_material.name.Split(' ');
var tiling = Convert.ToSingle(floats[1]);
prefab.m_segments[j].m_material.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_segments[j].m_segmentMaterial != null) prefab.m_segments[j].m_segmentMaterial.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_segments[j].m_lodMaterial != null) prefab.m_segments[j].m_lodMaterial.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_segments[j].m_combinedLod.m_material != null) prefab.m_segments[j].m_combinedLod.m_material.mainTextureScale = new Vector2(1, Math.Abs(tiling));
}
}
if (prefab.m_nodes != null) for (uint j = 0; j < prefab.m_nodes.Length; j++)
{
if (prefab.m_nodes[j].m_material == null) continue;
if (prefab.m_nodes[j].m_material.name.Contains("NetworkTiling"))
{
string[] floats = prefab.m_nodes[j].m_material.name.Split(' ');
var tiling = Convert.ToSingle(floats[1]);
prefab.m_nodes[j].m_material.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_nodes[j].m_nodeMaterial != null) prefab.m_nodes[j].m_nodeMaterial.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_nodes[j].m_lodMaterial != null) prefab.m_nodes[j].m_lodMaterial.mainTextureScale = new Vector2(1, tiling);
if (prefab.m_nodes[j].m_combinedLod.m_material != null) prefab.m_nodes[j].m_combinedLod.m_material.mainTextureScale = new Vector2(1, Math.Abs(tiling));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment