mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Fix body transform support and some cleaning up
This commit is contained in:
parent
56395c241a
commit
4b51e1ac70
Binary file not shown.
@ -3,11 +3,11 @@ using UnityEngine.Serialization;
|
||||
|
||||
namespace Restock
|
||||
{
|
||||
public class ModuleRestockDepthMask: PartModule
|
||||
public class ModuleRestockDepthMask : PartModule
|
||||
{
|
||||
// The name of the transform that has your mask mesh. The only strictly required property
|
||||
[KSPField]
|
||||
public string maskTransform= "";
|
||||
public string maskTransform = "";
|
||||
|
||||
[KSPField]
|
||||
public string bodyTransform = "";
|
||||
@ -19,40 +19,47 @@ namespace Restock
|
||||
// The render queue value for the mesh, should be less than maskRenderQueue
|
||||
[KSPField]
|
||||
public int meshRenderQueue = 1000;
|
||||
|
||||
|
||||
// the render queue value for the mask, should be less than 2000
|
||||
[KSPField]
|
||||
public int maskRenderQueue = 1999;
|
||||
|
||||
// depth mask object transform
|
||||
public Transform depthMask;
|
||||
|
||||
public Transform bodyRoot;
|
||||
|
||||
// depth mask object transform
|
||||
public Transform maskTransformObject;
|
||||
|
||||
// body object transform
|
||||
public Transform bodyTransformObject;
|
||||
|
||||
// depth mask shader object
|
||||
public Shader depthShader;
|
||||
|
||||
|
||||
public override void OnStart(StartState state)
|
||||
{
|
||||
base.OnStart(state);
|
||||
|
||||
UpdatematerialQueue();
|
||||
|
||||
// the part variant system is implemented extremely stupidly
|
||||
// so we have to make this whole module more complicated as a result
|
||||
GameEvents.onVariantApplied.Add(OnVariantApplied);
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
GameEvents.onVariantApplied.Remove(OnVariantApplied);
|
||||
}
|
||||
|
||||
|
||||
public override void OnLoad(ConfigNode node)
|
||||
{
|
||||
|
||||
base.OnLoad(node);
|
||||
|
||||
|
||||
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
|
||||
|
||||
this.depthMask = base.part.FindModelTransform(maskTransform);
|
||||
if (!(this.depthMask is Transform))
|
||||
this.maskTransformObject = base.part.FindModelTransform(maskTransform);
|
||||
if (this.maskTransformObject == null)
|
||||
{
|
||||
this.LogError($"Can't find transform {maskTransform}");
|
||||
return;
|
||||
@ -60,47 +67,43 @@ namespace Restock
|
||||
|
||||
if (bodyTransform == "")
|
||||
{
|
||||
bodyRoot = base.part.partTransform;
|
||||
this.bodyTransformObject = base.part.partTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bodyRoot = base.part.partTransform.Find(bodyTransform);
|
||||
if (!(this.bodyRoot is Transform))
|
||||
this.bodyTransformObject = base.part.FindModelTransform(bodyTransform);
|
||||
if (this.bodyTransformObject == null)
|
||||
{
|
||||
this.LogError($"Can't find transform {bodyTransform}");
|
||||
return;
|
||||
this.bodyTransformObject = base.part.partTransform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.depthShader = Shader.Find(shaderName);
|
||||
if (!(this.depthShader is Shader))
|
||||
if (this.depthShader == null)
|
||||
{
|
||||
this.LogError($"Can't find shader {shaderName}");
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatematerialQueue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnVariantApplied(Part appliedPart, PartVariant variant)
|
||||
{
|
||||
// I dont know why changing part variants resets all the materials to their as-loaded state, but it does
|
||||
if (appliedPart == this.part) UpdatematerialQueue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdatematerialQueue()
|
||||
{
|
||||
var windowRenderer = depthMask.GetComponent<MeshRenderer>();
|
||||
|
||||
var windowRenderer = maskTransformObject.GetComponent<MeshRenderer>();
|
||||
|
||||
windowRenderer.material.shader = depthShader;
|
||||
windowRenderer.material.renderQueue = maskRenderQueue;
|
||||
|
||||
this.Log(depthShader.name);
|
||||
this.Log(windowRenderer.material.shader.name);
|
||||
|
||||
var meshRenderers = bodyRoot.GetComponentsInChildren<MeshRenderer>(true);
|
||||
var skinnedMeshRenderers = bodyRoot.GetComponentsInChildren<SkinnedMeshRenderer>(true);
|
||||
var meshRenderers = bodyTransformObject.GetComponentsInChildren<MeshRenderer>(true);
|
||||
var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
|
||||
|
||||
foreach (var renderer in meshRenderers)
|
||||
{
|
||||
@ -109,7 +112,7 @@ namespace Restock
|
||||
queue = meshRenderQueue + ((queue - 2000) / 2);
|
||||
renderer.material.renderQueue = queue;
|
||||
}
|
||||
|
||||
|
||||
foreach (var renderer in skinnedMeshRenderers)
|
||||
{
|
||||
if (renderer == windowRenderer) continue;
|
||||
|
Loading…
Reference in New Issue
Block a user