Add Debug UI integration and update TestScript interaction logic
- Implement `DebugUi` component for updating and displaying debug information. - Configure new UI Toolkit assets, including `PanelSettings` and `UIDocument`. - Update TestScript to support dynamic ForceMode, velocity, and difference tracking with debug UI. - Minor adjustments to Rigidbody torque and interaction parameters.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class TestScript : MonoBehaviour
|
||||
{
|
||||
@@ -11,10 +12,15 @@ public class TestScript : MonoBehaviour
|
||||
private ConfigurableJoint _configurableJoint;
|
||||
|
||||
private float _smoothX;
|
||||
|
||||
// max is 0.63
|
||||
// min is 0.15
|
||||
|
||||
private JointDrive _jointDrive;
|
||||
private JointDrive _softJointDrive;
|
||||
|
||||
private double _maxDifference = 0;
|
||||
|
||||
[SerializeField]
|
||||
private float torqueForce;
|
||||
|
||||
@@ -28,7 +34,13 @@ public class TestScript : MonoBehaviour
|
||||
private ForceMode forceMode;
|
||||
|
||||
[SerializeField]
|
||||
private Rigidbody _pump;
|
||||
private Rigidbody pump;
|
||||
|
||||
[SerializeField]
|
||||
private DebugUi debugUi;
|
||||
|
||||
[SerializeField]
|
||||
private float timeScale = 1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -53,6 +65,23 @@ public class TestScript : MonoBehaviour
|
||||
_moveAction.Enable();
|
||||
_jumpAction.Enable();
|
||||
|
||||
_maxDifference = GetDifference();
|
||||
debugUi.UpdateText($"Difference: {_maxDifference}");
|
||||
|
||||
Time.timeScale = timeScale;
|
||||
|
||||
}
|
||||
|
||||
private double GetDifference()
|
||||
{
|
||||
Vector3 axis = transform.up; // this transform's local Y in world space
|
||||
Vector3 toOther = pump.transform.position - transform.position;
|
||||
|
||||
var val = Vector3.Dot(toOther, axis);
|
||||
|
||||
val = Mathf.Abs(val);
|
||||
|
||||
return Math.Round(val, 2); // signed distance along local Y
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -70,13 +99,27 @@ public class TestScript : MonoBehaviour
|
||||
}
|
||||
|
||||
if (_jumpAction.WasReleasedThisFrame()) {
|
||||
_pump.AddForce(transform.up * 10, ForceMode.Impulse);
|
||||
float t = Mathf.InverseLerp(0.15f, 0.63f, (float)GetDifference()); // gives 0 when 0.63, 1 when 0.15
|
||||
float forceMultiplier = Mathf.Lerp(30, 5, t);
|
||||
|
||||
debugUi.UpdateForceMultiplier(forceMultiplier.ToString());
|
||||
|
||||
pump.AddForce(transform.up * forceMultiplier, ForceMode.Impulse);
|
||||
_configurableJoint.yDrive = _jointDrive;
|
||||
}
|
||||
|
||||
if (GetDifference() < _maxDifference) {
|
||||
_maxDifference = GetDifference();
|
||||
}
|
||||
|
||||
debugUi.UpdateVelocity(_rigidbody.linearVelocity.y.ToString());
|
||||
debugUi.UpdateText($"Difference: {_maxDifference}");
|
||||
debugUi.UpdateCurrentText($"Current difference: {GetDifference()}");
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
_rigidbody.AddTorque(new Vector3(0, 0, _smoothX) * torqueForce, forceMode);
|
||||
// inverted to apply correct direction
|
||||
_rigidbody.AddTorque(new Vector3(0, 0, -_smoothX) * torqueForce, forceMode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user