Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script for creating decals of any size using a premade mesh you can download here: (Based on original script by boformer.)
// Decal Prop Fix Script (based on original script by boformer)
// Removes the need for making a mesh, just import the provided decal mesh
// and this script will automatically change the size you set.
var size = new Vector2(16.0f, 8.0f); // Size of decal in meters - width and length
// (texture width and height will be stretched to match this)
var tile = new Vector3(1.0f, 1.0f); // Tiling amount
var slopeTolerance = -1.0f; // Box mesh height, leave at a negative value to calculate automatically
if (slopeTolerance < 0) slopeTolerance = Mathf.Clamp((size.x + size.y) / 4f, 2f, 32f);
var scale = new Vector4(size.x, slopeTolerance, size.y, 0); var tiling = new Vector4(tile.x, 0, tile.y, 0);
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as PropInfo;
var mesh = asset.m_mesh; var vertices = mesh.vertices; var vertexArray = new Vector3[vertices.Length]; vertices.CopyTo(vertexArray, 0);
for (int i = 0; i < vertices.Length; i++) {
if (vertexArray[i].x > 0) vertexArray[i].x = scale.x/2f; else vertexArray[i].x = -scale.x/2f;
if (vertexArray[i].y > 0) vertexArray[i].y = scale.y/2f; else vertexArray[i].y = -scale.y/2f;
if (vertexArray[i].z > 0) vertexArray[i].z = scale.z/2f; else vertexArray[i].z = -scale.z/2f; }
mesh.vertices = vertexArray; mesh.RecalculateBounds(); asset.CalculateGeneratedInfo();
var shader = Shader.Find("Custom/Props/Decal/Blend"); var marker = new Color(12f/255, 34f/255, 56f/255, 1f);
var data1 = new Color(scale.x/255, scale.y/255, scale.z/255, 1f); var data2 = new Color(tiling.x/255, tiling.y/255, tiling.z/255, 1f);
asset.m_material.shader = shader; asset.m_material.SetVector("_DecalSize", scale); asset.m_material.SetVector("_DecalTiling", tiling);
asset.m_material.SetColor("_ColorV0", marker); asset.m_material.SetColor("_ColorV1", data1);
asset.m_material.SetColor("_ColorV2", data2); asset.m_material.SetColor("_ColorV3", Color.white);
asset.m_lodMesh = null; asset.m_lodMaterial = null; asset.m_lodRenderDistance = 1000;
typeof(PropInfo).GetField("m_UIEditorCategory", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(asset, "PropsResidentialGroundTiles");
asset.m_createRuining = false; asset.m_useColorVariations = false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.