Add option to toggle quantum object visualization separate from debug (#1011)

## Improvements

- Added option separate from Debug for visualizing quantum object
visibility shapes
This commit is contained in:
xen-42 2025-01-06 10:42:55 -05:00 committed by GitHub
commit b9e0eb3b43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 37 deletions

View File

@ -97,7 +97,7 @@ namespace NewHorizons.Builder.Props
var boxShape = empty.AddComponent<BoxShape>(); var boxShape = empty.AddComponent<BoxShape>();
boxShape.center = boxBounds.center; boxShape.center = boxBounds.center;
boxShape.extents = boxBounds.size; boxShape.extents = boxBounds.size;
if (Main.Debug) empty.AddComponent<BoxShapeVisualizer>(); empty.AddComponent<BoxShapeVisualizer>();
empty.AddComponent<ShapeVisibilityTracker>(); empty.AddComponent<ShapeVisibilityTracker>();
} }
@ -136,7 +136,7 @@ namespace NewHorizons.Builder.Props
{ {
public MeshFilter f; public MeshFilter f;
public SkinnedMeshRenderer s; public SkinnedMeshRenderer s;
public GameObject g; public GameObject gameObject;
} }
public static void AddBoundsVisibility(GameObject g) public static void AddBoundsVisibility(GameObject g)
@ -145,19 +145,19 @@ namespace NewHorizons.Builder.Props
var skinnedMeshRenderers = g.GetComponentsInChildren<SkinnedMeshRenderer>(); var skinnedMeshRenderers = g.GetComponentsInChildren<SkinnedMeshRenderer>();
var boxShapeRecievers = meshFilters var boxShapeRecievers = meshFilters
.Select(f => new BoxShapeReciever() { f=f, g=f.gameObject }) .Select(f => new BoxShapeReciever() { f = f, gameObject = f.gameObject })
.Concat( .Concat(
skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s=s, g=s.gameObject }) skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s = s, gameObject = s.gameObject })
) )
.ToList(); .ToList();
foreach (var boxshapeReciever in boxShapeRecievers) foreach (var boxshapeReciever in boxShapeRecievers)
{ {
var box = boxshapeReciever.g.AddComponent<BoxShape>(); var box = boxshapeReciever.gameObject.AddComponent<BoxShape>();
boxshapeReciever.g.AddComponent<ShapeVisibilityTracker>(); boxshapeReciever.gameObject.AddComponent<ShapeVisibilityTracker>();
if (Main.Debug) boxshapeReciever.g.AddComponent<BoxShapeVisualizer>(); boxshapeReciever.gameObject.AddComponent<BoxShapeVisualizer>();
var fixer = boxshapeReciever.g.AddComponent<BoxShapeFixer>(); var fixer = boxshapeReciever.gameObject.AddComponent<BoxShapeFixer>();
fixer.shape = box; fixer.shape = box;
fixer.meshFilter = boxshapeReciever.f; fixer.meshFilter = boxshapeReciever.f;
fixer.skinnedMeshRenderer = boxshapeReciever.s; fixer.skinnedMeshRenderer = boxshapeReciever.s;
@ -213,9 +213,13 @@ namespace NewHorizons.Builder.Props
public MeshFilter meshFilter; public MeshFilter meshFilter;
public SkinnedMeshRenderer skinnedMeshRenderer; public SkinnedMeshRenderer skinnedMeshRenderer;
void Update() public void Update()
{ {
if (meshFilter == null && skinnedMeshRenderer == null) { NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); DestroyImmediate(this); } if (meshFilter == null && skinnedMeshRenderer == null)
{
NHLogger.LogVerbose("Useless BoxShapeFixer, destroying");
DestroyImmediate(this);
}
Mesh sharedMesh = null; Mesh sharedMesh = null;
if (meshFilter != null) sharedMesh = meshFilter.sharedMesh; if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;

View File

@ -47,6 +47,7 @@ namespace NewHorizons
// Settings // Settings
public static bool Debug { get; private set; } public static bool Debug { get; private set; }
public static bool VisualizeQuantumObjects { get; private set; }
public static bool VerboseLogs { get; private set; } public static bool VerboseLogs { get; private set; }
public static bool SequentialPreCaching { get; private set; } public static bool SequentialPreCaching { get; private set; }
public static bool CustomTitleScreen { get; private set; } public static bool CustomTitleScreen { get; private set; }
@ -134,6 +135,7 @@ namespace NewHorizons
var currentScene = SceneManager.GetActiveScene().name; var currentScene = SceneManager.GetActiveScene().name;
Debug = config.GetSettingsValue<bool>(nameof(Debug)); Debug = config.GetSettingsValue<bool>(nameof(Debug));
VisualizeQuantumObjects = config.GetSettingsValue<bool>(nameof(VisualizeQuantumObjects));
VerboseLogs = config.GetSettingsValue<bool>(nameof(VerboseLogs)); VerboseLogs = config.GetSettingsValue<bool>(nameof(VerboseLogs));
SequentialPreCaching = config.GetSettingsValue<bool>(nameof(SequentialPreCaching)); SequentialPreCaching = config.GetSettingsValue<bool>(nameof(SequentialPreCaching));

View File

@ -4,16 +4,19 @@ namespace NewHorizons.Utility.Geometry
{ {
public class BoxShapeVisualizer : MonoBehaviour public class BoxShapeVisualizer : MonoBehaviour
{ {
BoxShape box; private BoxShape _box;
void Awake() public void Awake()
{ {
box = GetComponent<BoxShape>(); _box = GetComponent<BoxShape>();
} }
void OnRenderObject() public void OnRenderObject()
{ {
Popcron.Gizmos.Cube(transform.TransformPoint(box.center), transform.rotation, Vector3.Scale(box.size, transform.lossyScale)); if (Main.Debug && Main.VisualizeQuantumObjects)
{
Popcron.Gizmos.Cube(transform.TransformPoint(_box.center), transform.rotation, Vector3.Scale(_box.size, transform.lossyScale));
}
} }
} }
} }

View File

@ -16,6 +16,12 @@
"value": false, "value": false,
"tooltip": "Enables the debug raycast, visible quantum object colliders, and debug options menu." "tooltip": "Enables the debug raycast, visible quantum object colliders, and debug options menu."
}, },
"VisualizeQuantumObjects": {
"title": "Visualize Quantum Objects",
"type": "toggle",
"value": false,
"tooltip": "Draws boundaries around quantum objects when Debug mode is on."
},
"VerboseLogs": { "VerboseLogs": {
"title": "Verbose Logs", "title": "Verbose Logs",
"type": "toggle", "type": "toggle",