Skip to content

Instantly share code, notes, and snippets.

@ronyx69
Last active June 23, 2019 16:07
Show Gist options
  • Save ronyx69/595c837a3141eb9c894168e385727217 to your computer and use it in GitHub Desktop.
Save ronyx69/595c837a3141eb9c894168e385727217 to your computer and use it in GitHub Desktop.
Script for saving PropRotating params in props for multiple rotating parts. (Added modless shader parameter saving method by boformer.)
// Prop Rotating Script for multiple rotating parts.
// Control rotation axis, pivot and speed.
// Run in asset editor and see effects in real time.
// Prop Rotating Params Mod is not required for using the scripts and saving the asset.
// It's only needed to load the data in-game.
// The LODs are not rotating, they are like regular props.
// (added modless shader parameter saving method by boformer)
// Vertex color blue channel for rotating parts must be 0.
// Non-rotating parts remain vertex color white.
// Google how to do vertex color painting in your 3d software of choice!
// You can have 4 different rotating parts, (0 to 3)
// each needs a different value for vertex color green channel.
// If you are making a clock, set clock value to 1.
// rotation for the 12 hour arm is 2,
// for the minute arm it's 24,
// for the second arm it's 1440.
// Part 0 (vertex color green channel = 0)
var axis0 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot0 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed0 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock0 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 1 (vertex color green channel = 64)
var axis1 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot1 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed1 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock1 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 2 (vertex color green channel = 128)
var axis2 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot2 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed2 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock2 = 0.0f; // Set to 1 to tie rotation to game clock.
// Part 3 (vertex color green channel = 192)
var axis3 = new Vector3(0.0f, 1.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot3 = new Vector3(0.0f, 0.0f, 0.0f); // Pivot point - center of rotation.
var speed3 = 1.0f; // Rotations per minute / per day for clocks (negative to reverse direction)
var clock3 = 0.0f; // Set to 1 to tie rotation to game clock.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
if(asset.m_rollParams==null) Array.Resize(ref asset.m_rollParams, 4);
if(asset.m_rollLocation==null) Array.Resize(ref asset.m_rollLocation, 4);
asset.m_rollParams[0] = new Vector4(axis0.x, axis0.y, axis0.z, speed0);
asset.m_rollLocation[0] = new Vector4(pivot0.x, pivot0.y, pivot0.z, 1.0f-clock0);
asset.m_rollParams[1] = new Vector4(axis1.x, axis1.y, axis1.z, speed1);
asset.m_rollLocation[1] = new Vector4(pivot1.x, pivot1.y, pivot1.z, 1.0f-clock1);
asset.m_rollParams[2] = new Vector4(axis2.x, axis2.y, axis2.z, speed2);
asset.m_rollLocation[2] = new Vector4(pivot2.x, pivot2.y, pivot2.z, 1.0f-clock2);
asset.m_rollParams[3] = new Vector4(axis3.x, axis3.y, axis3.z, speed3);
asset.m_rollLocation[3] = new Vector4(pivot3.x, pivot3.y, pivot3.z, 1.0f-clock3);
for (int i = 0; i < 4; i++) {
asset.m_material.SetVector("_RollParams" + i, asset.m_rollParams[i]);
asset.m_material.SetVector("_RollLocation" + i, asset.m_rollLocation[i]); }
var shader = Shader.Find("Custom/Props/Prop/Rotating"); if(asset.m_material != null) asset.m_material.shader = shader;
shader = Shader.Find("Custom/Props/Prop/Default"); if(asset.m_lodMaterial != null) asset.m_lodMaterial.shader = shader;
asset.m_lodHasDifferentShader=true;
var vectorProps = Type.GetType("ColossalFramework.Packaging.ShaderUtil, ColossalManaged").GetField("vectorProps").GetValue(null) as string[];
vectorProps[4] = "_RollLocation0"; vectorProps[5] = "_RollParams0"; vectorProps[6] = "_RollLocation1"; vectorProps[7] = "_RollParams1";
vectorProps[8] = "_RollLocation2"; vectorProps[9] = "_RollParams2"; vectorProps[10] = "_RollLocation3"; vectorProps[11] = "_RollParams3";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment