mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Allow ModuleRestockDepthMask to have multiple masks
This commit is contained in:
parent
ee2804f379
commit
ceb3d5d33f
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
@ -25,8 +26,8 @@ namespace Restock
|
|||||||
public int maskRenderQueue = 1999;
|
public int maskRenderQueue = 1999;
|
||||||
|
|
||||||
|
|
||||||
// depth mask object transform
|
// depth mask object transforms
|
||||||
public Transform maskTransformObject;
|
public Transform[] maskTransformObjects;
|
||||||
|
|
||||||
// body object transform
|
// body object transform
|
||||||
public Transform bodyTransformObject;
|
public Transform bodyTransformObject;
|
||||||
@ -38,7 +39,7 @@ namespace Restock
|
|||||||
public override void OnStart(StartState state)
|
public override void OnStart(StartState state)
|
||||||
{
|
{
|
||||||
base.OnStart(state);
|
base.OnStart(state);
|
||||||
UpdatematerialQueue();
|
UpdateAllMaterials();
|
||||||
|
|
||||||
// the part variant system is implemented extremely stupidly
|
// the part variant system is implemented extremely stupidly
|
||||||
// so we have to make this whole module more complicated as a result
|
// so we have to make this whole module more complicated as a result
|
||||||
@ -58,14 +59,14 @@ namespace Restock
|
|||||||
|
|
||||||
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
|
if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return;
|
||||||
|
|
||||||
this.maskTransformObject = base.part.FindModelTransform(maskTransform);
|
this.maskTransformObjects = base.part.FindModelTransforms(maskTransform);
|
||||||
if (this.maskTransformObject == null)
|
if (this.maskTransformObjects.Length == 0 || this.maskTransformObjects == null)
|
||||||
{
|
{
|
||||||
this.LogError($"Can't find transform {maskTransform}");
|
this.LogError($"Can't find transform {maskTransform}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bodyTransform == "")
|
if (bodyTransform.Length == 0)
|
||||||
{
|
{
|
||||||
this.bodyTransformObject = base.part.partTransform;
|
this.bodyTransformObject = base.part.partTransform;
|
||||||
}
|
}
|
||||||
@ -91,34 +92,26 @@ namespace Restock
|
|||||||
public void OnVariantApplied(Part appliedPart, PartVariant variant)
|
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
|
// I dont know why changing part variants resets all the materials to their as-loaded state, but it does
|
||||||
if (appliedPart == this.part) UpdatematerialQueue();
|
if (appliedPart == this.part) UpdateAllMaterials();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void UpdatematerialQueue()
|
private void UpdateAllMaterials()
|
||||||
{
|
{
|
||||||
var windowRenderer = maskTransformObject.GetComponent<MeshRenderer>();
|
var renderers = bodyTransformObject.GetComponentsInChildren<Renderer>(true);
|
||||||
|
|
||||||
windowRenderer.material.shader = depthShader;
|
foreach (var renderer in renderers)
|
||||||
windowRenderer.material.renderQueue = maskRenderQueue;
|
|
||||||
|
|
||||||
var meshRenderers = bodyTransformObject.GetComponentsInChildren<MeshRenderer>(true);
|
|
||||||
var skinnedMeshRenderers = bodyTransformObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
|
|
||||||
|
|
||||||
foreach (var renderer in meshRenderers)
|
|
||||||
{
|
{
|
||||||
if (renderer == windowRenderer) continue;
|
|
||||||
var queue = renderer.material.renderQueue;
|
var queue = renderer.material.renderQueue;
|
||||||
queue = meshRenderQueue + ((queue - 2000) / 2);
|
queue = meshRenderQueue + ((queue - 2000) / 2);
|
||||||
renderer.material.renderQueue = queue;
|
renderer.material.renderQueue = queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var renderer in skinnedMeshRenderers)
|
foreach (var maskObject in maskTransformObjects)
|
||||||
{
|
{
|
||||||
if (renderer == windowRenderer) continue;
|
var renderer = maskObject.GetComponent<Renderer>();
|
||||||
var queue = renderer.material.renderQueue;
|
renderer.material.shader = depthShader;
|
||||||
queue = meshRenderQueue + ((queue - 2000) / 2);
|
renderer.material.renderQueue = maskRenderQueue;
|
||||||
renderer.material.renderQueue = queue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user