Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using ICities;
  2. using UnityEngine;
  3. using ColossalFramework;
  4. using ColossalFramework.IO;
  5. using ColossalFramework.Steamworks;
  6. //using System.Xml.Serialization;
  7.  
  8. using System;
  9. using System.IO;
  10. using System.Reflection;
  11.  
  12.  
  13. namespace DarkerRoads4
  14. {
  15.     public class DarkerRoadsMod4 : IUserMod {
  16.         //public const UInt64 workshop_id = 1;
  17.  
  18.         public string Name {
  19.             get { return "Darker Roads"; }
  20.         }
  21.  
  22.         public string Description {
  23.             get { return "Replaces default road textures with a darker version."; }
  24.         }
  25.     }
  26.        
  27.  
  28.     public class DarkerRoadsLoader4 : LoadingExtensionBase {
  29.  
  30.         public static string getModPath() {
  31.             /*string workshopPath = ".";
  32.             foreach(PublishedFileId mod in Steam.workshop.GetSubscribedItems()) {
  33.                 if(mod.AsUInt64 == TerrainTextureReplacerMod2.workshop_id) {
  34.                     workshopPath = Steam.workshop.GetSubscribedItemPath(mod);
  35.                     Debug.Log("TerrainTextureReplacer: Workshop path: " + workshopPath);
  36.                     break;
  37.                 }
  38.             }*/
  39.             string localPath = DataLocation.modsPath + "/DarkerRoads";
  40.             Debug.Log("DarkerRoads: " + localPath);
  41.             if(System.IO.Directory.Exists(localPath)) {
  42.                 Debug.Log("DarkerRoads: Local path exists, looking for assets here: " + localPath);
  43.                 return localPath;
  44.             }
  45.             //return workshopPath;
  46.             return "error";
  47.  
  48.         }
  49.            
  50.         public override void OnLevelLoaded (LoadMode mode){
  51.  
  52.             string path = getModPath ();
  53.             Debug.Log("path: " + path);
  54.             DarkerRoads4.ReplaceNetTextures (path);
  55.         }
  56.  
  57.     }
  58.  
  59.     public class DarkerRoads4 : MonoBehaviour{
  60.  
  61.         public static Texture2D LoadTexture(string texturePath)
  62.         {
  63.             var tex = new Texture2D(1, 1);
  64.             tex.LoadImage(System.IO.File.ReadAllBytes(texturePath));
  65.             return tex;
  66.         }
  67.  
  68.         public static void ReplaceNetTextures(string textureDir)
  69.         {
  70.             var collections = UnityEngine.Object.FindObjectsOfType<NetCollection>();
  71.             foreach (var nc in collections)
  72.             {
  73.                 foreach (var prefab in nc.m_prefabs)
  74.                 {
  75.                     foreach (var node in prefab.m_nodes)
  76.                     {
  77.                        
  78.                         if (System.IO.File.Exists(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_node.png"))){
  79.                             //node.m_material.mainTexture = LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_node.png"));
  80.                             node.m_material.SetTexture("_MainTex", LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_node.png")));
  81.                             node.m_nodeMaterial.SetTexture("_MainTex", LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_node.png")));
  82.                             Debug.Log("Replaced " + prefab.name + " node");
  83.  
  84.                         }
  85.                     }
  86.  
  87.                     foreach (var segment in prefab.m_segments)
  88.                     {
  89.                         if (System.IO.File.Exists(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_segment.png"))){
  90.                             //segment.m_material.mainTexture = LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_segment.png"));
  91.                             segment.m_material.SetTexture("_MainTex", LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_segment.png")));
  92.                             segment.m_segmentMaterial.SetTexture("_MainTex",LoadTexture(Path.Combine(textureDir, prefab.name.Replace(" ", "_").ToLowerInvariant().Trim() + "_segment.png")));
  93.                             Debug.Log("Replaced " + prefab.name + " segment");
  94.                         }
  95.                     }
  96.                 }
  97.  
  98.  
  99.             }
  100.         }
  101.  
  102.     }
  103.  
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement