Merge pull request #1206 from Balint-H:feature/mouse-spring-qol

PiperOrigin-RevId: 590741248
Change-Id: I0228a2e6a27fd869f34f3e96163cd29e5ac99f35
This commit is contained in:
Copybara-Service
2023-12-13 16:04:24 -08:00
2 changed files with 7 additions and 5 deletions
+6 -4
View File
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#if UNITY_EDITOR
using System; using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@@ -23,7 +22,7 @@ namespace Mujoco {
// and left mouse drag will apply a force on the body. Holding shift down will change the applied // and left mouse drag will apply a force on the body. Holding shift down will change the applied
// force direction between World XZ plane and Y[camera-up]. // force direction between World XZ plane and Y[camera-up].
[CustomEditor(typeof(MjBody))] [CustomEditor(typeof(MjComponent), true)]
public class MjMouseSpring : Editor { public class MjMouseSpring : Editor {
private bool _lastShiftKeyState = false; private bool _lastShiftKeyState = false;
@@ -102,7 +101,11 @@ namespace Mujoco {
return; return;
} }
MjBody body = target as MjBody; var targetObject = target as MjComponent;
MjBody body = targetObject.GetComponentInParent<MjBody>();
if(!body)
return;
Vector3 bodyPosition = Vector3 bodyPosition =
body != null ? body.transform.position : Vector3.zero; body != null ? body.transform.position : Vector3.zero;
var scene = MjScene.Instance; var scene = MjScene.Instance;
@@ -188,4 +191,3 @@ namespace Mujoco {
} }
} }
} }
#endif
@@ -22,7 +22,7 @@ namespace Mujoco {
[CustomEditor(typeof(MjShapeComponent), true)] [CustomEditor(typeof(MjShapeComponent), true)]
[CanEditMultipleObjects] [CanEditMultipleObjects]
public class MjShapeComponentEditor : Editor { public class MjShapeComponentEditor : MjMouseSpring {
public override void OnInspectorGUI() { public override void OnInspectorGUI() {