first commit
This commit is contained in:
119
NitroxClient/Debuggers/Drawer/Unity/CharacterControllerDrawer.cs
Normal file
119
NitroxClient/Debuggers/Drawer/Unity/CharacterControllerDrawer.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using NitroxModel.Helper;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
/// <summary>
|
||||
/// Draws a <see cref="CharacterController"/> component on the gameobjects in the <see cref="SceneDebugger"/>
|
||||
/// </summary>
|
||||
public class CharacterControllerDrawer : IDrawer<CharacterController>
|
||||
{
|
||||
private readonly VectorDrawer vectorDrawer;
|
||||
private const float LABEL_WIDTH = 120;
|
||||
private const float VALUE_MAX_WIDTH = 405;
|
||||
|
||||
public CharacterControllerDrawer(VectorDrawer vectorDrawer)
|
||||
{
|
||||
Validate.NotNull(vectorDrawer);
|
||||
|
||||
this.vectorDrawer = vectorDrawer;
|
||||
}
|
||||
|
||||
public void Draw(CharacterController cc)
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Slope Limit (°)", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.slopeLimit = NitroxGUILayout.FloatField(cc.slopeLimit, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Step Offset", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.stepOffset = NitroxGUILayout.FloatField(cc.stepOffset, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Skin Width", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.skinWidth = NitroxGUILayout.FloatField(cc.skinWidth, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Min Move Distance", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.minMoveDistance = NitroxGUILayout.FloatField(cc.minMoveDistance, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Center", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.center = vectorDrawer.Draw(cc.center);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Radius", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.radius = NitroxGUILayout.FloatField(cc.radius, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Height", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.height = NitroxGUILayout.FloatField(cc.height, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Velocity", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(cc.velocity);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Is Grounded", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
NitroxGUILayout.BoolField(cc.isGrounded, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Detect Collisions", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.detectCollisions = NitroxGUILayout.BoolField(cc.detectCollisions, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Enable Overlap Recovery", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH + 30));
|
||||
NitroxGUILayout.Separator();
|
||||
cc.enableOverlapRecovery = NitroxGUILayout.BoolField(cc.enableOverlapRecovery, VALUE_MAX_WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
46
NitroxClient/Debuggers/Drawer/Unity/ColorDrawer.cs
Normal file
46
NitroxClient/Debuggers/Drawer/Unity/ColorDrawer.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class ColorDrawer : IEditorDrawer<Color>, IEditorDrawer<Color32>
|
||||
{
|
||||
private static readonly Texture2D tex = new((int)NitroxGUILayout.VALUE_WIDTH, 25);
|
||||
private static Color lastColor;
|
||||
|
||||
public Color32 Draw(Color32 color) => Draw((Color)color);
|
||||
|
||||
public Color Draw(Color color)
|
||||
{
|
||||
if (color != lastColor)
|
||||
{
|
||||
for (int y = 0; y < 6; y++)
|
||||
{
|
||||
int separator = (int)(tex.width * color.a);
|
||||
for (int x = 0; x < separator; x++)
|
||||
{
|
||||
tex.SetPixel(x, y, Color.white);
|
||||
}
|
||||
|
||||
for (int x = separator; x < tex.width; x++)
|
||||
{
|
||||
tex.SetPixel(x, y, Color.black);
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 6; y < tex.height; y++)
|
||||
{
|
||||
for (int x = 0; x < tex.width; x++)
|
||||
{
|
||||
tex.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
tex.Apply();
|
||||
lastColor = color;
|
||||
}
|
||||
|
||||
// TODO: Implement Color picker
|
||||
GUILayout.Button(tex, GUILayout.Width(tex.width));
|
||||
return color;
|
||||
}
|
||||
}
|
13
NitroxClient/Debuggers/Drawer/Unity/MaterialDrawer.cs
Normal file
13
NitroxClient/Debuggers/Drawer/Unity/MaterialDrawer.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class MaterialDrawer : IEditorDrawer<Material>
|
||||
{
|
||||
public Material Draw(Material material)
|
||||
{
|
||||
// TODO: Implement Material picker
|
||||
GUILayout.Box(material.name, GUILayout.Width(150), GUILayout.Height(20));
|
||||
return material;
|
||||
}
|
||||
}
|
79
NitroxClient/Debuggers/Drawer/Unity/RectDrawer.cs
Normal file
79
NitroxClient/Debuggers/Drawer/Unity/RectDrawer.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class RectDrawer : IEditorDrawer<Rect, RectDrawer.DrawOptions>, IEditorDrawer<RectOffset>
|
||||
{
|
||||
private const float MAX_WIDTH = 400;
|
||||
|
||||
public Rect Draw(Rect rect, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions();
|
||||
var (valueWidth, maxWidth) = (options.Width, options.MaxWidth);
|
||||
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(maxWidth)))
|
||||
{
|
||||
using (new GUILayout.VerticalScope())
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("X:", NitroxGUILayout.DrawerLabel);
|
||||
rect.x = NitroxGUILayout.FloatField(rect.x, valueWidth);
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Y:", NitroxGUILayout.DrawerLabel);
|
||||
rect.y = NitroxGUILayout.FloatField(rect.y, valueWidth);
|
||||
}
|
||||
}
|
||||
|
||||
using (new GUILayout.VerticalScope())
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("W:", NitroxGUILayout.DrawerLabel);
|
||||
rect.width = NitroxGUILayout.FloatField(rect.width, valueWidth);
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("H:", NitroxGUILayout.DrawerLabel);
|
||||
rect.height = NitroxGUILayout.FloatField(rect.height, valueWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public Rect Draw(Rect rect)
|
||||
{
|
||||
return Draw(rect, null);
|
||||
}
|
||||
|
||||
public RectOffset Draw(RectOffset rect, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions(Width: MAX_WIDTH);
|
||||
|
||||
float valueWidth = options.MaxWidth / 4 - 6;
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(options.MaxWidth)))
|
||||
{
|
||||
rect.left = NitroxGUILayout.IntField(rect.left, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
rect.right = NitroxGUILayout.IntField(rect.right, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
rect.top = NitroxGUILayout.IntField(rect.top, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
rect.bottom = NitroxGUILayout.IntField(rect.bottom, valueWidth);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
public RectOffset Draw(RectOffset rect)
|
||||
{
|
||||
return Draw(rect, null);
|
||||
}
|
||||
|
||||
public record DrawOptions(float Width = 100, float MaxWidth = 215);
|
||||
}
|
118
NitroxClient/Debuggers/Drawer/Unity/RigidbodyDrawer.cs
Normal file
118
NitroxClient/Debuggers/Drawer/Unity/RigidbodyDrawer.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using NitroxModel.Helper;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class RigidbodyDrawer : IDrawer<Rigidbody>
|
||||
{
|
||||
private readonly VectorDrawer vectorDrawer;
|
||||
private const float LABEL_WIDTH = 120;
|
||||
private const float VALUE_MAX_WIDTH = 405;
|
||||
|
||||
public RigidbodyDrawer(VectorDrawer vectorDrawer)
|
||||
{
|
||||
Validate.NotNull(vectorDrawer);
|
||||
|
||||
this.vectorDrawer = vectorDrawer;
|
||||
}
|
||||
|
||||
public void Draw(Rigidbody rb)
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Mass", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.mass = NitroxGUILayout.FloatField(rb.mass, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Drag", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.drag = NitroxGUILayout.FloatField(rb.drag, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Angular Drag", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.angularDrag = NitroxGUILayout.FloatField(rb.angularDrag, VALUE_MAX_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Use Gravity");
|
||||
NitroxGUILayout.Separator();
|
||||
rb.useGravity = NitroxGUILayout.BoolField(rb.useGravity);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Is Kinematic");
|
||||
NitroxGUILayout.Separator();
|
||||
rb.isKinematic = NitroxGUILayout.BoolField(rb.isKinematic);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Interpolate", GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.interpolation = NitroxGUILayout.EnumPopup(rb.interpolation, NitroxGUILayout.VALUE_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Collision Detection", GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.collisionDetectionMode = NitroxGUILayout.EnumPopup(rb.collisionDetectionMode, NitroxGUILayout.VALUE_WIDTH);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Freeze Rotation");
|
||||
NitroxGUILayout.Separator();
|
||||
rb.freezeRotation = NitroxGUILayout.BoolField(rb.freezeRotation);
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Velocity", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(rb.velocity, new VectorDrawer.DrawOptions(VALUE_MAX_WIDTH));
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Angular Velocity", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(rb.angularVelocity, new VectorDrawer.DrawOptions(VALUE_MAX_WIDTH));
|
||||
}
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Detect Collisions", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
rb.detectCollisions = NitroxGUILayout.BoolField(rb.detectCollisions, NitroxGUILayout.VALUE_WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
107
NitroxClient/Debuggers/Drawer/Unity/TransformDrawer.cs
Normal file
107
NitroxClient/Debuggers/Drawer/Unity/TransformDrawer.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using NitroxModel.Helper;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class TransformDrawer : IDrawer<Transform>
|
||||
{
|
||||
private readonly SceneDebugger sceneDebugger;
|
||||
private readonly VectorDrawer vectorDrawer;
|
||||
private const float LABEL_WIDTH = 100;
|
||||
private const float VECTOR_MAX_WIDTH = 405;
|
||||
|
||||
private bool showGlobal;
|
||||
|
||||
public TransformDrawer(SceneDebugger sceneDebugger, VectorDrawer vectorDrawer)
|
||||
{
|
||||
Validate.NotNull(sceneDebugger);
|
||||
Validate.NotNull(vectorDrawer);
|
||||
|
||||
this.sceneDebugger = sceneDebugger;
|
||||
this.vectorDrawer = vectorDrawer;
|
||||
}
|
||||
|
||||
public void Draw(Transform transform)
|
||||
{
|
||||
using (new GUILayout.VerticalScope())
|
||||
{
|
||||
if (showGlobal)
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Global Position", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(transform.position, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Global Rotation", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(transform.rotation.eulerAngles, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Lossy Scale", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
vectorDrawer.Draw(transform.lossyScale, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Local Position", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
transform.localPosition = vectorDrawer.Draw(transform.localPosition, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Local Rotation", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
transform.localRotation = Quaternion.Euler(vectorDrawer.Draw(transform.localRotation.eulerAngles, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH)));
|
||||
}
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label("Local Scale", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
transform.localScale = vectorDrawer.Draw(transform.localScale, new VectorDrawer.DrawOptions(VECTOR_MAX_WIDTH));
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Toggle Local/Global", GUILayout.MaxWidth(125)))
|
||||
{
|
||||
showGlobal = !showGlobal;
|
||||
}
|
||||
if (GUILayout.Button("Destroy GameObject", GUILayout.MaxWidth(150)))
|
||||
{
|
||||
if (transform)
|
||||
{
|
||||
if (transform.parent)
|
||||
{
|
||||
sceneDebugger.JumpToComponent(transform.parent);
|
||||
}
|
||||
UnityEngine.Object.Destroy(transform.gameObject);
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("Goto", GUILayout.MaxWidth(75)) && Player.main)
|
||||
{
|
||||
SubRoot subRoot = transform.GetComponentInParent<SubRoot>(true);
|
||||
Player.main.SetCurrentSub(subRoot, true);
|
||||
Player.main.SetPosition(transform.position);
|
||||
}
|
||||
if (GUILayout.Button($"Set {(transform.gameObject.activeSelf ? "inactive" : "active")}", GUILayout.MaxWidth(125)))
|
||||
{
|
||||
transform.gameObject.SetActive(!transform.gameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
NitroxClient/Debuggers/Drawer/Unity/UnityEventDrawer.cs
Normal file
67
NitroxClient/Debuggers/Drawer/Unity/UnityEventDrawer.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class UnityEventDrawer : IDrawer<UnityEvent, UnityEventDrawer.DrawOptions>, IDrawer<UnityEvent<bool>, UnityEventDrawer.DrawOptions>
|
||||
{
|
||||
private const float LABEL_WIDTH = 250;
|
||||
|
||||
public void Draw(UnityEvent unityEvent, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions();
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label(options.Name, NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
if (GUILayout.Button("Invoke All", GUILayout.Width(100)))
|
||||
{
|
||||
unityEvent.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
DrawUnityEventBase(unityEvent);
|
||||
}
|
||||
|
||||
public void Draw(UnityEvent<bool> unityEvent, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions();
|
||||
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Label(options.Name, NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
NitroxGUILayout.Separator();
|
||||
if (GUILayout.Button("Invoke All (true)", GUILayout.Width(100)))
|
||||
{
|
||||
unityEvent.Invoke(true);
|
||||
}
|
||||
if (GUILayout.Button("Invoke All (false)", GUILayout.Width(100)))
|
||||
{
|
||||
unityEvent.Invoke(false);
|
||||
}
|
||||
}
|
||||
|
||||
DrawUnityEventBase(unityEvent);
|
||||
}
|
||||
|
||||
private static void DrawUnityEventBase(UnityEventBase unityEventBase)
|
||||
{
|
||||
for (int index = 0; index < unityEventBase.GetPersistentEventCount(); index++)
|
||||
{
|
||||
using (new GUILayout.HorizontalScope())
|
||||
{
|
||||
NitroxGUILayout.Separator();
|
||||
Object target = unityEventBase.GetPersistentTarget(index);
|
||||
string labelText = target ? $"{target.GetType().Name}.{unityEventBase.GetPersistentMethodName(index)}()" : $"{unityEventBase.GetPersistentMethodName(index)}()";
|
||||
GUILayout.Label(labelText, NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public record DrawOptions(string Name = "NoName");
|
||||
|
||||
public void Draw(UnityEvent unityEvent) => Draw(unityEvent, null);
|
||||
|
||||
public void Draw(UnityEvent<bool> unityEvent) => Draw(unityEvent, null);
|
||||
}
|
100
NitroxClient/Debuggers/Drawer/Unity/VectorDrawer.cs
Normal file
100
NitroxClient/Debuggers/Drawer/Unity/VectorDrawer.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using NitroxModel_Subnautica.DataStructures;
|
||||
using NitroxModel.DataStructures.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.Debuggers.Drawer.Unity;
|
||||
|
||||
public class VectorDrawer : IEditorDrawer<Vector2, VectorDrawer.DrawOptions>, IEditorDrawer<Vector3, VectorDrawer.DrawOptions>, IEditorDrawer<NitroxVector3>, IEditorDrawer<Vector4>, IEditorDrawer<NitroxVector4>, IEditorDrawer<Quaternion>,
|
||||
IEditorDrawer<Int3>
|
||||
{
|
||||
private const float MAX_WIDTH = 400;
|
||||
|
||||
public Vector2 Draw(Vector2 vector2, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions();
|
||||
|
||||
float valueWidth = options.MaxWidth / 2 - 5;
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(options.MaxWidth)))
|
||||
{
|
||||
vector2.x = NitroxGUILayout.FloatField(vector2.x, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector2.y = NitroxGUILayout.FloatField(vector2.y, valueWidth);
|
||||
return vector2;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 Draw(Vector3 vector3, DrawOptions options)
|
||||
{
|
||||
options ??= new DrawOptions();
|
||||
|
||||
float valueWidth = options.MaxWidth / 3 - 5;
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(options.MaxWidth)))
|
||||
{
|
||||
vector3.x = NitroxGUILayout.FloatField(vector3.x, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector3.y = NitroxGUILayout.FloatField(vector3.y, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector3.z = NitroxGUILayout.FloatField(vector3.z, valueWidth);
|
||||
return vector3;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector4 Draw(Vector4 vector)
|
||||
{
|
||||
float valueWidth = MAX_WIDTH / 4 - 6;
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(MAX_WIDTH)))
|
||||
{
|
||||
vector.x = NitroxGUILayout.FloatField(vector.x, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector.y = NitroxGUILayout.FloatField(vector.y, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector.z = NitroxGUILayout.FloatField(vector.z, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector.w = NitroxGUILayout.FloatField(vector.w, valueWidth);
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
|
||||
public Quaternion Draw(Quaternion vector)
|
||||
{
|
||||
Vector4 vector4 = new(vector.x, vector.y, vector.z, vector.w);
|
||||
vector4 = Draw(vector4);
|
||||
return new Quaternion(vector4.x, vector4.y, vector4.z, vector4.w);
|
||||
}
|
||||
|
||||
public Int3 Draw(Int3 vector)
|
||||
{
|
||||
float valueWidth = MAX_WIDTH / 3 - 5;
|
||||
using (new GUILayout.HorizontalScope(GUILayout.MaxWidth(MAX_WIDTH)))
|
||||
{
|
||||
vector.x = NitroxGUILayout.IntField(vector.x, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector.y = NitroxGUILayout.IntField(vector.y, valueWidth);
|
||||
NitroxGUILayout.Separator();
|
||||
vector.z = NitroxGUILayout.IntField(vector.z, valueWidth);
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
|
||||
public NitroxVector3 Draw(NitroxVector3 vector)
|
||||
{
|
||||
return Draw(vector.ToUnity()).ToDto();
|
||||
}
|
||||
|
||||
public NitroxVector4 Draw(NitroxVector4 vector)
|
||||
{
|
||||
return Draw(vector.ToUnity()).ToDto();
|
||||
}
|
||||
|
||||
public record DrawOptions(float MaxWidth = MAX_WIDTH);
|
||||
|
||||
public Vector2 Draw(Vector2 vector)
|
||||
{
|
||||
return Draw(vector, null);
|
||||
}
|
||||
|
||||
public Vector3 Draw(Vector3 vector)
|
||||
{
|
||||
return Draw(vector, null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user