Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active April 10, 2021 13:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Script for saving Traffic Light Shader params in props, for Railway Barriers. (Added modless shader parameter saving method by boformer.)
// Traffic Light Shader - Railway Crossing Barriers
// Control rotation axis and pivot.
// Run in asset editor.
// (This used to require the PropRotating mod but that is no longer necessary)
// (added modless shader parameter saving method by boformer)
// Rotating parts must be vertex painted black! The rest reimains white.
// Google how to do vertex color painting in your 3d software of choice!
var axis = new Vector3(0.0f, 0.0f, 1.0f); // Set to 1 to choose rotation axis.
var pivot = new Vector3(0.0f, 1.1f, 0.0f); // Pivot point - center of rotation.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
var shader = Shader.Find("Custom/Props/Prop/TrafficLight");
if(asset.m_material != null) asset.m_material.shader = shader;
if(asset.m_lodMaterial != null) asset.m_lodMaterial.shader = shader;
var vec = new Vector4(axis.x, axis.y, axis.z, 10.0f); asset.m_material.SetVector("_RollParams0", vec);
var vec2 = new Vector4(pivot.x, pivot.y, pivot.z, 1.0f); asset.m_material.SetVector("_RollLocation0", vec2);
var vectorProps = Type.GetType("ColossalFramework.Packaging.ShaderUtil, ColossalManaged").GetField("vectorProps").GetValue(null) as string[];
vectorProps[4] = "_RollLocation0"; vectorProps[5] = "_RollParams0";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment