Skip to content

Instantly share code, notes, and snippets.

@boformer
Last active April 25, 2019 09:19
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 boformer/2f256537dc26d893e40b138b9580c374 to your computer and use it in GitHub Desktop.
Save boformer/2f256537dc26d893e40b138b9580c374 to your computer and use it in GitHub Desktop.
Rotating props without PropRotatingParams mod (based on a script by Ronyx69) - Single rotating part
// Warning: Do not save vehicles after running this script without a game restart!
// Prop Rotating Script
// Control rotation axis, pivot and speed.
// Run in asset editor and see effects in real time.
// Animated faces must be vertex painted black! The rest reimains white.
// Google how to do vertex color painting in your 3d software of choice!
// The LODs are not rotating, they are like regular props.
var axis = new Vector3(1.0f, 0.0f, 0.0f); // Set to 1 to choose rotation axis.
var pivot = new Vector3(0.0f, 5.0f, 0.0f); // Pivot point - center of rotation.
var speed = 60.0f; // rotations per minute
// --- end of editable values ---
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
if (asset.m_material == null)
{
Debug.LogError("Asset has no texture, unable to apply params!");
return;
}
asset.m_rollParams = new Vector4[4];
asset.m_rollLocation = new Vector4[4];
asset.m_rollParams[0] = new Vector4(axis.x, axis.y, axis.z, speed);
asset.m_rollLocation[0] = new Vector4(pivot.x, pivot.y, pivot.z, 1.0f);
asset.m_rollParams[1] = new Vector4(0, 1, 0, 10);
asset.m_rollLocation[1] = new Vector4(0, 0, 0, 1);
asset.m_rollParams[2] = new Vector4(0, 1, 0, 10);
asset.m_rollLocation[2] = new Vector4(0, 0, 0, 1);
asset.m_rollParams[3] = new Vector4(0, 1, 0, 10);
asset.m_rollLocation[3] = new Vector4(0, 0, 0, 1);
asset.m_material.shader = Shader.Find("Custom/Props/Prop/Rotating");
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]);
}
if (asset.m_lodMaterial != null)
{
asset.m_lodMaterial.shader = Shader.Find("Custom/Props/Prop/Default");
}
asset.m_lodHasDifferentShader = true;
// Tells the asset editor to save _RollParams and _RollLocation shader properties
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