using RPGCore.Movement.ObjectModules.UnitMovement; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace RPGCore.Movement.Editor.Drawers { [CustomPropertyDrawer(typeof(UnitMovementModule))] public class UnitMovementModuleDrawer : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) { var root = new VisualElement(); if (Application.isPlaying) root.Add(CreateDebugBox(property)); root.Add(new PropertyField(property)); return root; } private HelpBox CreateDebugBox(SerializedProperty property) { var debugBox = new HelpBox(); debugBox.style.flexDirection = FlexDirection.Column; debugBox.style.alignItems = Align.Stretch; debugBox.SetEnabled(false); debugBox.Add(new Label("RUNTIME DEBUG:")); var groundSteepnessField = new FloatField(nameof(UnitMovementModule.groundSteepness)); debugBox.Add(groundSteepnessField); var isOnGroundField = new Toggle(nameof(UnitMovementModule.isOnGround)); debugBox.Add(isOnGroundField); var rotateYawField = new FloatField(nameof(UnitMovementModule.rotateYaw)); debugBox.Add(rotateYawField); var moveVectorField = new Vector3Field(nameof(UnitMovementModule.accelerationVector)); debugBox.Add(moveVectorField); var linearVelocityField = new Vector3Field(nameof(Rigidbody.linearVelocity)); debugBox.Add(linearVelocityField); var linearVelocityMagnitudeField = new FloatField(nameof(Rigidbody.linearVelocity.magnitude)); debugBox.Add(linearVelocityMagnitudeField); debugBox.schedule.Execute(() => { var module = property.boxedValue as UnitMovementModule; groundSteepnessField.value = module.groundSteepness; isOnGroundField.value = module.isOnGround; rotateYawField.value = module.rotateYaw; moveVectorField.value = module.accelerationVector; linearVelocityField.value = module.parent.rigidbody.linearVelocity; linearVelocityMagnitudeField.value = module.parent.rigidbody.linearVelocity.magnitude; }).Every(100); return debugBox; } } }