176 lines
5.4 KiB
C#
176 lines
5.4 KiB
C#
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class DiapasonPoseTweaker : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private OctoIkArmsImproved _armsSystem;
|
|
[SerializeField] private int _armIndex = 1;
|
|
|
|
[Header("Quick Presets")]
|
|
[SerializeField] private bool _applyPreset1 = false;
|
|
[SerializeField] private bool _applyPreset2 = false;
|
|
[SerializeField] private bool _applyPreset3 = false;
|
|
|
|
[Header("Live Tweaking (Runtime Only)")]
|
|
[SerializeField] private Vector3 _shoulderRotation = new Vector3(20, 0, -10);
|
|
[SerializeField] private Vector3 _elbowRotation = new Vector3(0, 0, 0);
|
|
[SerializeField] private Vector3 _wristRotation = new Vector3(0, 0, 90);
|
|
|
|
[Header("Preview")]
|
|
[SerializeField] private bool _previewPose = false;
|
|
|
|
private ArmEquipment _equipment;
|
|
private bool _wasPreviewActive = false;
|
|
|
|
void Update()
|
|
{
|
|
if (!Application.isPlaying)
|
|
return;
|
|
|
|
if (_armsSystem == null)
|
|
return;
|
|
|
|
if (_equipment == null)
|
|
{
|
|
var armRigField = typeof(OctoIkArmsImproved).GetField("_rightArm",
|
|
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
|
|
|
if (armRigField != null)
|
|
{
|
|
var armRig = armRigField.GetValue(_armsSystem);
|
|
var equipmentField = armRig.GetType().GetField("Equipment");
|
|
if (equipmentField != null)
|
|
{
|
|
_equipment = (ArmEquipment)equipmentField.GetValue(armRig);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (_equipment == null)
|
|
return;
|
|
|
|
if (_previewPose && _equipment.State == ArmState.Environmental)
|
|
{
|
|
ApplyRotations();
|
|
_wasPreviewActive = true;
|
|
}
|
|
else if (_wasPreviewActive && !_previewPose)
|
|
{
|
|
ResetRotations();
|
|
_wasPreviewActive = false;
|
|
}
|
|
|
|
if (_equipment.State == ArmState.Equipped)
|
|
{
|
|
_equipment.ShoulderRotationOffset = _shoulderRotation;
|
|
_equipment.ElbowRotationOffset = _elbowRotation;
|
|
_equipment.WristRotationOffset = _wristRotation;
|
|
}
|
|
}
|
|
|
|
void OnValidate()
|
|
{
|
|
if (_applyPreset1)
|
|
{
|
|
_applyPreset1 = false;
|
|
ApplyPreset1();
|
|
}
|
|
|
|
if (_applyPreset2)
|
|
{
|
|
_applyPreset2 = false;
|
|
ApplyPreset2();
|
|
}
|
|
|
|
if (_applyPreset3)
|
|
{
|
|
_applyPreset3 = false;
|
|
ApplyPreset3();
|
|
}
|
|
}
|
|
|
|
private void ApplyPreset1()
|
|
{
|
|
_shoulderRotation = new Vector3(30, 0, -15);
|
|
_elbowRotation = new Vector3(0, 10, 0);
|
|
_wristRotation = new Vector3(0, 0, 90);
|
|
Debug.Log("[DiapasonPose] Applied Preset 1: Close to body, slight inward");
|
|
}
|
|
|
|
private void ApplyPreset2()
|
|
{
|
|
_shoulderRotation = new Vector3(20, -10, -20);
|
|
_elbowRotation = new Vector3(0, 0, 0);
|
|
_wristRotation = new Vector3(0, -15, 90);
|
|
Debug.Log("[DiapasonPose] Applied Preset 2: Further from left hand, angled");
|
|
}
|
|
|
|
private void ApplyPreset3()
|
|
{
|
|
_shoulderRotation = new Vector3(15, 0, -25);
|
|
_elbowRotation = new Vector3(0, 15, 0);
|
|
_wristRotation = new Vector3(0, 0, 85);
|
|
Debug.Log("[DiapasonPose] Applied Preset 3: Natural grip, centered");
|
|
}
|
|
|
|
private void ApplyRotations()
|
|
{
|
|
if (_equipment.ShoulderBone != null)
|
|
{
|
|
_equipment.ShoulderBone.localRotation = _equipment.OriginalShoulderRotation * Quaternion.Euler(_shoulderRotation);
|
|
}
|
|
|
|
if (_equipment.ElbowBone != null)
|
|
{
|
|
_equipment.ElbowBone.localRotation = _equipment.OriginalElbowRotation * Quaternion.Euler(_elbowRotation);
|
|
}
|
|
|
|
if (_equipment.WristBone != null)
|
|
{
|
|
_equipment.WristBone.localRotation = _equipment.OriginalWristRotation * Quaternion.Euler(_wristRotation);
|
|
}
|
|
}
|
|
|
|
private void ResetRotations()
|
|
{
|
|
if (_equipment.ShoulderBone != null)
|
|
{
|
|
_equipment.ShoulderBone.localRotation = _equipment.OriginalShoulderRotation;
|
|
}
|
|
|
|
if (_equipment.ElbowBone != null)
|
|
{
|
|
_equipment.ElbowBone.localRotation = _equipment.OriginalElbowRotation;
|
|
}
|
|
|
|
if (_equipment.WristBone != null)
|
|
{
|
|
_equipment.WristBone.localRotation = _equipment.OriginalWristRotation;
|
|
}
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
if (!Application.isPlaying)
|
|
return;
|
|
|
|
GUILayout.BeginArea(new Rect(10, 150, 350, 250));
|
|
GUILayout.Label("=== Diapason Pose Tweaker ===");
|
|
|
|
GUILayout.Label($"Shoulder: {_shoulderRotation}");
|
|
GUILayout.Label($"Elbow: {_elbowRotation}");
|
|
GUILayout.Label($"Wrist: {_wristRotation}");
|
|
|
|
GUILayout.Space(10);
|
|
GUILayout.Label("Tips:");
|
|
GUILayout.Label("• Shoulder X: + = down, - = up");
|
|
GUILayout.Label("• Shoulder Y: + = inward, - = outward");
|
|
GUILayout.Label("• Shoulder Z: + = twist out, - = twist in");
|
|
GUILayout.Label("• Elbow Y: + = bend out, - = bend in");
|
|
GUILayout.Label("• Wrist Z: rotation du diapason");
|
|
|
|
GUILayout.EndArea();
|
|
}
|
|
}
|