From e09ad0b2e331a494bafaf734d3a749a3042bc0d2 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 17 Jan 2022 17:43:17 +0100 Subject: [PATCH] Fix HipsTarget animator setting not being persistent --- .../HumanoidFree/Targets/HipsTarget_Editor.cs | 56 ++++++++++++------- .../Scripts/Targets/HipsTarget.cs | 3 + 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Editor/HumanoidFree/Targets/HipsTarget_Editor.cs b/Editor/HumanoidFree/Targets/HipsTarget_Editor.cs index 4ee0b12..134782a 100644 --- a/Editor/HumanoidFree/Targets/HipsTarget_Editor.cs +++ b/Editor/HumanoidFree/Targets/HipsTarget_Editor.cs @@ -59,9 +59,9 @@ namespace Passer { }; } -#endregion + #endregion -#region Disable + #region Disable public void OnDisable() { if (humanoid == null) { // This target is not connected to a humanoid, so we delete it @@ -78,9 +78,9 @@ namespace Passer { foreach (TargetProps props in allProps) props.SetSensor2Target(); } -#endregion + #endregion -#region Inspector + #region Inspector public override void OnInspectorGUI() { if (hipsTarget == null || humanoid == null) @@ -109,7 +109,8 @@ namespace Passer { return foundHumanoid; } -#region Sensors + #region Sensors + public bool showSensors = true; private void SensorInspectors(HipsTarget hipsTarget) { showSensors = EditorGUILayout.Foldout(showSensors, "Controllers", true); @@ -119,14 +120,27 @@ namespace Passer { foreach (TargetProps props in allProps) props.Inspector(); - if (humanoid.animatorEnabled) - hipsTarget.torsoAnimator.enabled = EditorGUILayout.ToggleLeft("Procedural Animation", hipsTarget.torsoAnimator.enabled, GUILayout.MinWidth(80)); + AnimatorInspector(hipsTarget); + EditorGUI.indentLevel--; } } -#endregion -#region Configuration + private void AnimatorInspector(HipsTarget hipsTarget) { + SerializedProperty animatorProp = serializedObject.FindProperty(nameof(HipsTarget.torsoAnimator) + "." + nameof(HipsTarget.torsoAnimator.enabled)); + if (animatorProp == null || hipsTarget.humanoid == null || hipsTarget.humanoid.animatorEnabled) + return; + + GUIContent text = new GUIContent( + "Procedural Animation", + "Controls the hips when no tracking is active" + ); + animatorProp.boolValue = EditorGUILayout.ToggleLeft(text, animatorProp.boolValue, GUILayout.MinWidth(80)); + } + + #endregion + + #region Configuration private void InitConfiguration(HipsTarget target) { if (target.humanoid.avatarRig == null) return; @@ -161,7 +175,7 @@ namespace Passer { UpdateChestBones(target.chest); } -#region Chest + #region Chest private void InitChestConfiguration(HipsTarget.TargetedChestBone upperLeg) { } @@ -184,9 +198,9 @@ namespace Passer { private void UpdateChestBones(HipsTarget.TargetedChestBone chest) { } -#endregion + #endregion -#region Spine + #region Spine private void InitSpineConfiguration(HipsTarget.TargetedSpineBone spine) { } @@ -208,9 +222,9 @@ namespace Passer { private void UpdateSpineBones(HipsTarget.TargetedSpineBone spine) { } -#endregion + #endregion -#region Hips + #region Hips private void InitHipsConfiguration(HipsTarget.TargetedHipsBone hips) { } @@ -220,11 +234,11 @@ namespace Passer { private void UpdateHipsBones(HipsTarget.TargetedHipsBone hips) { } -#endregion + #endregion -#endregion + #endregion -#region Settings + #region Settings protected SerializedProperty bodyRotationProp; @@ -245,11 +259,11 @@ namespace Passer { } } -#endregion + #endregion -#endregion + #endregion -#region Scene + #region Scene public void OnSceneGUI() { if (Application.isPlaying) @@ -279,7 +293,7 @@ namespace Passer { humanoid.UpdateSensorsFromTargets(); } -#endregion + #endregion public abstract class TargetProps { public SerializedProperty enabledProp; diff --git a/Runtime/HumanoidFree/Scripts/Targets/HipsTarget.cs b/Runtime/HumanoidFree/Scripts/Targets/HipsTarget.cs index 3826eb5..cc939fd 100644 --- a/Runtime/HumanoidFree/Scripts/Targets/HipsTarget.cs +++ b/Runtime/HumanoidFree/Scripts/Targets/HipsTarget.cs @@ -57,6 +57,9 @@ namespace Passer.Humanoid { #region Sensors + /// + /// Controls the hips when no tracking is active + /// public TorsoAnimator torsoAnimator = new TorsoAnimator(); public override Passer.Sensor animator { get { return torsoAnimator; } }