allow for multiple material modification

Allow ModuleRestockLinkedMesh to reference multiple materials including disabled ones
This commit is contained in:
Andrew Cassidy 2019-06-04 11:56:19 -07:00
parent 2d9249d001
commit 2bc203ee64
No known key found for this signature in database
GPG Key ID: 963017B38FD477A1
2 changed files with 14 additions and 6 deletions

View File

@ -17,7 +17,7 @@ namespace Restock
// reference to the material we will be modifying // reference to the material we will be modifying
private Material pipeMaterial; private Material[] pipeMaterials;
// array of property IDs corresponding to the textures // array of property IDs corresponding to the textures
private int[] pipeMaterialIDs; private int[] pipeMaterialIDs;
@ -33,8 +33,13 @@ namespace Restock
{ {
base.OnStart(state); base.OnStart(state);
// only the first material we find is used. complicates things otherwise // get all materials on the line object, including disabled ones
pipeMaterial = line.GetComponentInChildren<MeshRenderer>().material; var renderers = line.GetComponentsInChildren<MeshRenderer>(true);
pipeMaterials = new Material[renderers.Length];
for (int i = 0; i < renderers.Length; i++)
{
pipeMaterials[i] = renderers[i].material;
}
// split texture list and convert to property IDs for easy access // split texture list and convert to property IDs for easy access
var texNames = stretchTextures.Split(' '); var texNames = stretchTextures.Split(' ');
@ -74,10 +79,13 @@ namespace Restock
var stretch = line.localScale.z; var stretch = line.localScale.z;
var scaleVect = Vector2.one; var scaleVect = Vector2.one;
scaleVect[pipeStretchIndex] = stretch / baseStretch; scaleVect[pipeStretchIndex] = stretch / baseStretch;
foreach (var t in pipeMaterialIDs) foreach (var material in pipeMaterials)
{ {
pipeMaterial.SetTextureScale(t, scaleVect); foreach (var id in pipeMaterialIDs)
{
material.SetTextureScale(id, scaleVect);
}
} }
} }
} }