Skip to content

Commit a6730ad

Browse files
dartasenMeasurity
authored andcommitted
Add BoxCollider to debugger (SubnauticaNitrox#2676)
1 parent cbb4688 commit a6730ad

6 files changed

Lines changed: 101 additions & 12 deletions

File tree

NitroxClient/Debuggers/Drawer/DrawerManager.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace NitroxClient.Debuggers.Drawer;
2121
/// </summary>
2222
public class DrawerManager
2323
{
24-
private readonly Dictionary<Type, IDrawer<object>> drawers = new();
25-
private readonly Dictionary<Type, IEditorDrawer<object>> editorDrawers = new();
24+
private readonly Dictionary<Type, IDrawer<object>> drawers = [];
25+
private readonly Dictionary<Type, IEditorDrawer<object>> editorDrawers = [];
2626

2727
public DrawerManager(SceneDebugger sceneDebugger)
2828
{
@@ -37,6 +37,7 @@ public DrawerManager(SceneDebugger sceneDebugger)
3737
MaterialDrawer materialDrawer = new();
3838
ImageDrawer imageDrawer = new(colorDrawer, materialDrawer, rectDrawer);
3939
NitroxEntityDrawer nitroxEntityDrawer = new();
40+
RigidbodyDrawer rigidbodyDrawer = new(vectorDrawer);
4041

4142
AddDrawer<NitroxEntityDrawer, NitroxEntity>(nitroxEntityDrawer);
4243
AddDrawer<NitroxEntityDrawer, NitroxId>(nitroxEntityDrawer);
@@ -68,13 +69,14 @@ public DrawerManager(SceneDebugger sceneDebugger)
6869
AddDrawer<TextDrawer, Text>(new(colorDrawer, materialDrawer));
6970
AddDrawer<ToggleDrawer, Toggle>(new(sceneDebugger, selectableDrawer, unityEventDrawer));
7071
AddDrawer<ToggleGroupDrawer, ToggleGroup>();
71-
AddDrawer<RigidbodyDrawer, Rigidbody>(new(vectorDrawer));
72+
AddDrawer<RigidbodyDrawer, Rigidbody>(rigidbodyDrawer);
7273
AddDrawer<TransformDrawer, Transform>(new(sceneDebugger, vectorDrawer));
7374
AddDrawer<UnityEventDrawer, UnityEvent>(unityEventDrawer);
7475
AddDrawer<UnityEventDrawer, UnityEvent<bool>>(unityEventDrawer);
7576
AddDrawer<VFXControllerDrawer, VFXController>(new(vectorDrawer, sceneDebugger));
7677
AddDrawer<AnimatorDrawer, Animator>();
7778
AddDrawer<CharacterControllerDrawer, CharacterController>(new(vectorDrawer));
79+
AddDrawer<BoxColliderDrawer, BoxCollider>(new(vectorDrawer, rigidbodyDrawer));
7880

7981
AddEditor<VectorDrawer, Vector2>(vectorDrawer);
8082
AddEditor<VectorDrawer, Vector3>(vectorDrawer);
@@ -86,6 +88,7 @@ public DrawerManager(SceneDebugger sceneDebugger)
8688
AddEditor<ColorDrawer, Color>(colorDrawer);
8789
AddEditor<ColorDrawer, Color32>(colorDrawer);
8890
AddEditor<MaterialDrawer, Material>(materialDrawer);
91+
AddEditor<MaterialDrawer, PhysicMaterial>(materialDrawer);
8992
AddEditor<RectDrawer, Rect>(rectDrawer);
9093
AddEditor<RectDrawer, RectOffset>(rectDrawer);
9194
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Nitrox.Model.Helper;
2+
using UnityEngine;
3+
using UWE;
4+
5+
namespace NitroxClient.Debuggers.Drawer.Unity;
6+
7+
public sealed class BoxColliderDrawer : IDrawer<BoxCollider>
8+
{
9+
private readonly RigidbodyDrawer rigidbodyDrawer;
10+
private readonly VectorDrawer vectorDrawer;
11+
private const float VECTOR_MAX_WIDTH = 405;
12+
13+
public BoxColliderDrawer(VectorDrawer vectorDrawer, RigidbodyDrawer rigidbodyDrawer)
14+
{
15+
Validate.NotNull(vectorDrawer);
16+
Validate.NotNull(rigidbodyDrawer);
17+
18+
this.vectorDrawer = vectorDrawer;
19+
this.rigidbodyDrawer = rigidbodyDrawer;
20+
}
21+
22+
public void Draw(BoxCollider target)
23+
{
24+
using (new GUILayout.VerticalScope())
25+
{
26+
using (new GUILayout.HorizontalScope())
27+
{
28+
GUILayout.Label("Center", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
29+
NitroxGUILayout.Separator();
30+
target.center = vectorDrawer.Draw(target.center, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
31+
}
32+
33+
using (new GUILayout.HorizontalScope())
34+
{
35+
GUILayout.Label("Size", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
36+
NitroxGUILayout.Separator();
37+
target.size = vectorDrawer.Draw(target.size, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
38+
}
39+
}
40+
41+
GUILayout.Space(10);
42+
43+
using (new GUILayout.VerticalScope())
44+
{
45+
using (new GUILayout.HorizontalScope())
46+
{
47+
GUILayout.Label("Enabled", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
48+
NitroxGUILayout.Separator();
49+
target.enabled = NitroxGUILayout.BoolField(target.enabled);
50+
}
51+
52+
using (new GUILayout.HorizontalScope())
53+
{
54+
GUILayout.Label("Is Trigger", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
55+
NitroxGUILayout.Separator();
56+
target.isTrigger = NitroxGUILayout.BoolField(target.isTrigger);
57+
}
58+
59+
using (new GUILayout.HorizontalScope())
60+
{
61+
GUILayout.Label("Contact Offset", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
62+
NitroxGUILayout.Separator();
63+
target.contactOffset = NitroxGUILayout.FloatField(target.contactOffset);
64+
}
65+
}
66+
67+
GUILayout.Space(10);
68+
69+
using (new GUILayout.HorizontalScope())
70+
{
71+
GUILayout.Label("Attached Rigid Body", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
72+
NitroxGUILayout.Separator();
73+
rigidbodyDrawer.Draw(target.attachedRigidbody);
74+
}
75+
}
76+
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
using UnityEngine;
1+
using UnityEngine;
22

33
namespace NitroxClient.Debuggers.Drawer.Unity;
44

5-
public class MaterialDrawer : IEditorDrawer<Material>
5+
public sealed class MaterialDrawer : IEditorDrawer<Material>, IEditorDrawer<PhysicMaterial>
66
{
77
public Material Draw(Material material)
88
{
99
// TODO: Implement Material picker
1010
GUILayout.Box(material.name, GUILayout.Width(150), GUILayout.Height(20));
1111
return material;
1212
}
13+
14+
public PhysicMaterial Draw(PhysicMaterial target)
15+
{
16+
// TODO: Implement Material picker
17+
GUILayout.Box(target.name, GUILayout.Width(150), GUILayout.Height(20));
18+
return target;
19+
}
1320
}

NitroxClient/Debuggers/Drawer/Unity/RigidbodyDrawer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace NitroxClient.Debuggers.Drawer.Unity;
55

6-
public class RigidbodyDrawer : IDrawer<Rigidbody>
6+
public sealed class RigidbodyDrawer : IDrawer<Rigidbody>
77
{
88
private readonly VectorDrawer vectorDrawer;
99
private const float LABEL_WIDTH = 120;
@@ -16,8 +16,14 @@ public RigidbodyDrawer(VectorDrawer vectorDrawer)
1616
this.vectorDrawer = vectorDrawer;
1717
}
1818

19-
public void Draw(Rigidbody rb)
19+
public void Draw(Rigidbody? rb)
2020
{
21+
if (!rb)
22+
{
23+
GUILayout.TextField("Rigidbody is null", NitroxGUILayout.DrawerLabel);
24+
return;
25+
}
26+
2127
using (new GUILayout.HorizontalScope())
2228
{
2329
GUILayout.Label("Mass", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));

NitroxClient/Debuggers/Drawer/UnityUI/MaskDrawer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System;
21
using UnityEngine;
32
using UnityEngine.UI;
43

54
namespace NitroxClient.Debuggers.Drawer.UnityUI;
65

7-
public class MaskDrawer : IDrawer<Mask>, IDrawer<RectMask2D>
6+
public sealed class MaskDrawer : IDrawer<Mask>, IDrawer<RectMask2D>
87
{
9-
public Type[] ApplicableTypes { get; } = { typeof(Mask), typeof(RectMask2D) };
10-
118
public void Draw(Mask mask)
129
{
1310
using (new GUILayout.HorizontalScope())

NitroxClient/MonoBehaviours/NitroxDebugManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NitroxDebugManager : MonoBehaviour
1717
private readonly HashSet<BaseDebugger> prevActiveDebuggers = [];
1818
private List<BaseDebugger> debuggers;
1919

20-
private bool showDebuggerList;
20+
private bool showDebuggerList = true;
2121
private bool isDebugging;
2222
private Rect windowRect;
2323

0 commit comments

Comments
 (0)