Last active
February 27, 2021 13:26
-
-
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.
This file contains 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 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