Skip to content

Commit

Permalink
minor fixes for texture-swap handling (rever to render.material; shar…
Browse files Browse the repository at this point in the history
…edMaterial really is shared in some cases)
  • Loading branch information
shadowmage45 committed Mar 26, 2016
1 parent 3be7489 commit 43c1132
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 25 deletions.
Binary file modified GameData/SSTU/Plugins/SSTUTools.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Module/SSTUDecalSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void enable(Transform transform)
else
{
Texture tex = SSTUUtils.findTexture(texture, false);
transform.renderer.sharedMaterial.mainTexture = tex;
transform.renderer.material.mainTexture = tex;
transform.renderer.enabled = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Module/SSTUFlagDecal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void updateFlagTransform()
{
if (tr.renderer != null)
{
tr.renderer.sharedMaterial.mainTexture = texture;
tr.renderer.material.mainTexture = texture;
tr.renderer.enabled = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Module/SSTUHighlightFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void init()
newObj.transform.NestToParent(part.transform.FindRecursive("model"));

Renderer render = newObj.AddComponent<MeshRenderer>();//add a new render
render.sharedMaterial = SSTUUtils.loadMaterial(null, null);//with an empty dummy material, also it doesn't actually have any mesh
render.material = SSTUUtils.loadMaterial(null, null);//with an empty dummy material, also it doesn't actually have any mesh
dummyTransform = newObj.transform;//cache reference to it for use for updating
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Module/SSTUResizableFairing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void updateTexture()
mpf.FairingMaterial.mainTexture = t;
foreach (var f in mpf.Panels)
{
f.go.renderer.sharedMaterial.mainTexture = t;
f.go.renderer.material.mainTexture = t;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Util/ModelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void enable(GameObject root)
Transform tr = root.transform.FindRecursive(mesh);
if (tr != null && tr.renderer != null)
{
Material m = tr.renderer.sharedMaterial;
Material m = tr.renderer.material;
if (!String.IsNullOrEmpty(diffuseTextureName)) { m.mainTexture = GameDatabase.Instance.GetTexture(diffuseTextureName, false); }
if (!String.IsNullOrEmpty(normalTextureName)) { m.SetTexture("_BumpMap", GameDatabase.Instance.GetTexture(normalTextureName, true)); }
if (!String.IsNullOrEmpty(emissiveTextureName)) { m.SetTexture("_Emissive", GameDatabase.Instance.GetTexture(emissiveTextureName, false)); }
Expand Down
20 changes: 2 additions & 18 deletions Source/Util/SSTUUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,6 @@ public static void destroyChildrenImmediate(Transform tr)
}
}

public static void recursePrintMaterialData(Transform tr)
{
if (tr.renderer != null)
{
Material m = tr.renderer.sharedMaterial;
Texture t = m.mainTexture;
Shader s = m.shader;
MonoBehaviour.print("mat: " + m + " : tex: " + t + " : shad: " + s);
}

foreach (Transform child in tr)
{
recursePrintMaterialData(child);
}
}

public static void recursePrintChildTransforms(Transform tr, String prefix)
{
MonoBehaviour.print("Transform found: " + prefix + tr.name);
Expand Down Expand Up @@ -449,7 +433,7 @@ public static void setTextureRecursive(Transform tr, Texture tex, int id)
{
if (tr != null && tr.renderer != null && tr.renderer.sharedMaterial != null)
{
tr.renderer.sharedMaterial.SetTexture(id, tex);
tr.renderer.material.SetTexture(id, tex);
}
foreach (Transform tr1 in tr)
{
Expand All @@ -459,7 +443,7 @@ public static void setTextureRecursive(Transform tr, Texture tex, int id)

public static void setMaterialRecursive(Transform tr, Material mat)
{
if (tr.gameObject.renderer != null) { tr.gameObject.renderer.sharedMaterial = mat; }
if (tr.gameObject.renderer != null) { tr.gameObject.renderer.material = mat; }
int len = tr.childCount;
for (int i = 0; i < len; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Util/TextureSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ public void enableFromMeshes(Part part)

private void enableTexture(Transform tr)
{
if (tr.renderer == null || tr.renderer.sharedMaterial == null)
if (tr.renderer == null || tr.renderer.material == null)
{
//MonoBehaviour.print("ERROR: transform does not contain a renderer for mesh name: " + tr.name);
return;
}
//TODO check / update the shader for the material
Material m = tr.renderer.sharedMaterial;
Material m = tr.renderer.material;
if (!String.IsNullOrEmpty(diffuseTextureName)) { m.mainTexture = GameDatabase.Instance.GetTexture(diffuseTextureName, false); }
if (!String.IsNullOrEmpty(normalTextureName)) { m.SetTexture("_BumpMap", GameDatabase.Instance.GetTexture(normalTextureName, true)); }
if (!String.IsNullOrEmpty(emissiveTextureName)) { m.SetTexture("_Emissive", GameDatabase.Instance.GetTexture(emissiveTextureName, false)); }
Expand Down

0 comments on commit 43c1132

Please sign in to comment.