delete duplicate box shape fixer

This commit is contained in:
JohnCorby 2025-01-13 16:49:28 -08:00
parent d5ad5bf84b
commit ed4e43a044
2 changed files with 15 additions and 54 deletions

View File

@ -295,39 +295,4 @@ namespace NewHorizons.Builder.Props
return globalCorners.Select(globalCorner => relativeTo.transform.InverseTransformPoint(globalCorner)).ToArray(); return globalCorners.Select(globalCorner => relativeTo.transform.InverseTransformPoint(globalCorner)).ToArray();
} }
} }
/// <summary>
/// for some reason mesh bounds are wrong unless we wait a bit
/// so this script contiously checks everything until it is correct
///
/// this actually only seems to be a problem with skinned renderers. normal ones work fine
/// TODO: at some point narrow this down to just skinned, instead of doing everything and checking every frame
/// </summary>
public class BoxShapeFixer : MonoBehaviour
{
public BoxShape shape;
public MeshFilter meshFilter;
public SkinnedMeshRenderer skinnedMeshRenderer;
public void Update()
{
if (meshFilter == null && skinnedMeshRenderer == null)
{
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
DestroyImmediate(this);
}
Mesh sharedMesh = null;
if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;
if (skinnedMeshRenderer != null) sharedMesh = skinnedMeshRenderer.sharedMesh;
if (sharedMesh == null) return;
if (sharedMesh.bounds.size == Vector3.zero) return;
shape.size = sharedMesh.bounds.size;
shape.center = sharedMesh.bounds.center;
DestroyImmediate(this);
}
}
} }

View File

@ -3,7 +3,14 @@ using UnityEngine;
namespace NewHorizons.Utility.Geometry; namespace NewHorizons.Utility.Geometry;
internal class BoxShapeFixer : MonoBehaviour /// <summary>
/// for some reason mesh bounds are wrong unless we wait a bit
/// so this script contiously checks everything until it is correct
///
/// this actually only seems to be a problem with skinned renderers. normal ones work fine
/// TODO: at some point narrow this down to just skinned, instead of doing everything and checking every frame
/// </summary>
public class BoxShapeFixer : MonoBehaviour
{ {
public BoxShape shape; public BoxShape shape;
public MeshFilter meshFilter; public MeshFilter meshFilter;
@ -13,31 +20,20 @@ internal class BoxShapeFixer : MonoBehaviour
{ {
if (meshFilter == null && skinnedMeshRenderer == null) if (meshFilter == null && skinnedMeshRenderer == null)
{ {
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); DestroyImmediate(this); NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
DestroyImmediate(this);
} }
Mesh sharedMesh = null; Mesh sharedMesh = null;
if (meshFilter != null) if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;
{ if (skinnedMeshRenderer != null) sharedMesh = skinnedMeshRenderer.sharedMesh;
sharedMesh = meshFilter.sharedMesh;
}
if (skinnedMeshRenderer != null)
{
sharedMesh = skinnedMeshRenderer.sharedMesh;
}
if (sharedMesh == null) if (sharedMesh == null) return;
{ if (sharedMesh.bounds.size == Vector3.zero) return;
return;
}
if (sharedMesh.bounds.size == Vector3.zero)
{
return;
}
shape.size = sharedMesh.bounds.size; shape.size = sharedMesh.bounds.size;
shape.center = sharedMesh.bounds.center; shape.center = sharedMesh.bounds.center;
DestroyImmediate(this); DestroyImmediate(this);
} }
} }