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

@ -15,11 +15,11 @@ namespace NewHorizons.Builder.Props
public static void Make(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod, QuantumGroupInfo quantumGroup, GameObject[] propsInGroup)
{
switch(quantumGroup.type)
switch (quantumGroup.type)
{
case QuantumGroupType.Sockets: MakeSocketGroup (go, sector, config, mod, quantumGroup, propsInGroup); return;
case QuantumGroupType.States: MakeStateGroup (go, sector, config, mod, quantumGroup, propsInGroup); return;
// case PropModule.QuantumGroupType.Shuffle: MakeShuffleGroup(go, sector, config, mod, quantumGroup, propsInGroup); return;
case QuantumGroupType.Sockets: MakeSocketGroup(go, sector, config, mod, quantumGroup, propsInGroup); return;
case QuantumGroupType.States: MakeStateGroup(go, sector, config, mod, quantumGroup, propsInGroup); return;
// case PropModule.QuantumGroupType.Shuffle: MakeShuffleGroup(go, sector, config, mod, quantumGroup, propsInGroup); return;
}
}
@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Props
socket.SetActive(true);
}
foreach(var prop in propsInGroup)
foreach (var prop in propsInGroup)
{
prop.SetActive(false);
var quantumObject = prop.AddComponent<SocketedQuantumObject>();
@ -72,7 +72,7 @@ namespace NewHorizons.Builder.Props
groupRoot.transform.localPosition = Vector3.zero;
var states = new List<QuantumState>();
foreach(var prop in propsInGroup)
foreach (var prop in propsInGroup)
{
prop.transform.parent = groupRoot.transform;
var state = prop.AddComponent<QuantumState>();
@ -97,7 +97,7 @@ namespace NewHorizons.Builder.Props
var boxShape = empty.AddComponent<BoxShape>();
boxShape.center = boxBounds.center;
boxShape.extents = boxBounds.size;
if (Main.Debug) empty.AddComponent<BoxShapeVisualizer>();
empty.AddComponent<BoxShapeVisualizer>();
empty.AddComponent<ShapeVisibilityTracker>();
}
@ -136,7 +136,7 @@ namespace NewHorizons.Builder.Props
{
public MeshFilter f;
public SkinnedMeshRenderer s;
public GameObject g;
public GameObject gameObject;
}
public static void AddBoundsVisibility(GameObject g)
@ -145,19 +145,19 @@ namespace NewHorizons.Builder.Props
var skinnedMeshRenderers = g.GetComponentsInChildren<SkinnedMeshRenderer>();
var boxShapeRecievers = meshFilters
.Select(f => new BoxShapeReciever() { f=f, g=f.gameObject })
.Concat (
skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s=s, g=s.gameObject })
.Select(f => new BoxShapeReciever() { f = f, gameObject = f.gameObject })
.Concat(
skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s = s, gameObject = s.gameObject })
)
.ToList();
foreach(var boxshapeReciever in boxShapeRecievers)
foreach (var boxshapeReciever in boxShapeRecievers)
{
var box = boxshapeReciever.g.AddComponent<BoxShape>();
boxshapeReciever.g.AddComponent<ShapeVisibilityTracker>();
if (Main.Debug) boxshapeReciever.g.AddComponent<BoxShapeVisualizer>();
var box = boxshapeReciever.gameObject.AddComponent<BoxShape>();
boxshapeReciever.gameObject.AddComponent<ShapeVisibilityTracker>();
boxshapeReciever.gameObject.AddComponent<BoxShapeVisualizer>();
var fixer = boxshapeReciever.g.AddComponent<BoxShapeFixer>();
var fixer = boxshapeReciever.gameObject.AddComponent<BoxShapeFixer>();
fixer.shape = box;
fixer.meshFilter = boxshapeReciever.f;
fixer.skinnedMeshRenderer = boxshapeReciever.s;
@ -213,9 +213,13 @@ namespace NewHorizons.Builder.Props
public MeshFilter meshFilter;
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;
if (meshFilter != null) sharedMesh = meshFilter.sharedMesh;

View File

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

View File

@ -4,16 +4,19 @@ namespace NewHorizons.Utility.Geometry
{
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,
"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": {
"title": "Verbose Logs",
"type": "toggle",