Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for using AnimUV shader on buildings and building sub meshes.
// Building (and Building Sub Mesh) Anim UV Scripts
// Create scrolling or multi-frame animations for buildings.
// Run in asset editor and see effects in real time.
// Ingame the building might require electricity to animate.
// No mods required, the changes save and load in vanilla.
// Vertex color green channel for animated faces must be 0.
// Non-animated parts remain vertex color white.
// Google how to do vertex color painting in your 3d software of choice!
// The LODs are not UV animated, they are like regular buildings.
// Building AnimUV Simplified Script
// Simple UV scrolling animation
var time = 2; // Length of animation loop in seconds.
var fps = 30; // Frames per second, more than 60 not recommended.
var sideways = false; // Set to true if you want horizontal UV scroll.
var reverse = false; // Set to true to reverse the scrolling direction.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
var shader = Shader.Find("Custom/Buildings/Building/AnimUV");
asset.m_material.shader = shader; asset.m_lodMaterial.shader = shader;
var tx=0f; var ty=0f;
if(sideways==true) tx=1f/(fps*time); else ty=1f/(fps*time);
if(reverse==true) { tx=0-tx; ty=0-ty; }
var frames = 1f*fps*time; var cycles = 60f/time;
asset.m_material.SetVector("_UvAnimation", new Vector4(tx, ty, frames, cycles));
// Building AnimUV Advanced Script
// Full control over AnimUV paramaters
var tx = 0.1f; // X coordinate transform amount, 1f = full width of image
var ty = 0.1f; // Y coordinate transform amount, 1f = full height of image
var frames = 30f; // Amount of transforms per cycle. Amount of animation frames.
var cycles = 60f; // Animation cycles per minute.
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo;
var shader = Shader.Find("Custom/Buildings/Building/AnimUV");
asset.m_material.shader = shader; asset.m_lodMaterial.shader = shader;
asset.m_material.SetVector("_UvAnimation", new Vector4(tx, ty, frames, cycles));
// Building Sub Mesh AnimUV Simplified Script
// Simple UV scrolling animation
var subMesh = 0;
var time = 2; // Length of animation loop in seconds.
var fps = 30; // Frames per second, more than 60 not recommended.
var sideways = false; // Set to true if you want horizontal UV scroll.
var reverse = false; // Set to true to reverse the scrolling direction.
var asset = (ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo).m_subMeshes[subMesh].m_subInfo;
var shader = Shader.Find("Custom/Buildings/Building/AnimUV");
asset.m_material.shader = shader; asset.m_lodMaterial.shader = shader;
var tx=0f; var ty=0f;
if(sideways==true) tx=1f/(fps*time); else ty=1f/(fps*time);
if(reverse==true) { tx=0-tx; ty=0-ty; }
var frames = 1f*fps*time; var cycles = 60f/time;
asset.m_material.SetVector("_UvAnimation", new Vector4(tx, ty, frames, cycles));
// Building Sub Mesh AnimUV Advanced Script
// Full control over AnimUV paramaters
var subMesh = 0;
var tx = 0.1f; // X coordinate transform amount, 1f = full width of image
var ty = 0.1f; // Y coordinate transform amount, 1f = full height of image
var frames = 30f; // Amount of transforms per cycle. Amount of animation frames.
var cycles = 60f; // Animation cycles per minute.
var asset = (ToolsModifierControl.toolController.m_editPrefabInfo as BuildingInfo).m_subMeshes[subMesh].m_subInfo;
var shader = Shader.Find("Custom/Buildings/Building/AnimUV");
asset.m_material.shader = shader; asset.m_lodMaterial.shader = shader;
asset.m_material.SetVector("_UvAnimation", new Vector4(tx, ty, frames, cycles));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment