Complete reorga
This commit is contained in:
@@ -1,445 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public enum ArmState
|
||||
{
|
||||
Environmental,
|
||||
TransitionToEquipped,
|
||||
Equipped,
|
||||
TransitionToEnvironmental
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class ArmEquipment
|
||||
{
|
||||
[Header("Arm References")]
|
||||
public OctoIkLimb IkLimb;
|
||||
public Transform HandSocket;
|
||||
|
||||
[Header("Bone References (for procedural animation)")]
|
||||
[Tooltip("Shoulder bone (optional)")]
|
||||
public Transform ShoulderBone;
|
||||
|
||||
[Tooltip("Elbow bone (optional)")]
|
||||
public Transform ElbowBone;
|
||||
|
||||
[Tooltip("Wrist bone (required for rotation)")]
|
||||
public Transform WristBone;
|
||||
|
||||
[Header("Equipped Pose Settings")]
|
||||
[Tooltip("Rotation to apply to shoulder when equipped")]
|
||||
public Vector3 ShoulderRotationOffset = Vector3.zero;
|
||||
|
||||
[Tooltip("Rotation to apply to elbow when equipped")]
|
||||
public Vector3 ElbowRotationOffset = Vector3.zero;
|
||||
|
||||
[Tooltip("Rotation to apply to wrist when equipped")]
|
||||
public Vector3 WristRotationOffset = new Vector3(0, 0, 90);
|
||||
|
||||
[Tooltip("Speed of rotation lerp")]
|
||||
[Range(1f, 20f)]
|
||||
public float RotationSpeed = 10f;
|
||||
|
||||
[Tooltip("Duration of IK blend after unequip transition")]
|
||||
[Range(0.1f, 1f)]
|
||||
public float IkBlendDuration = 0.3f;
|
||||
|
||||
[Header("Transition Settings")]
|
||||
[Tooltip("Position offset where arm exits camera view")]
|
||||
public Vector3 TransitionOffset = new Vector3(0.5f, -0.3f, 0.2f);
|
||||
|
||||
[Tooltip("Duration for arm to move out of view")]
|
||||
public float TransitionOutDuration = 0.3f;
|
||||
|
||||
[Tooltip("Duration for arm to return to view")]
|
||||
public float TransitionInDuration = 0.3f;
|
||||
|
||||
[Tooltip("Curve for transition movement")]
|
||||
public AnimationCurve TransitionCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
|
||||
|
||||
[HideInInspector] public ArmState State = ArmState.Environmental;
|
||||
[HideInInspector] public Vector3 OriginalTargetPosition;
|
||||
[HideInInspector] public Quaternion OriginalTargetRotation;
|
||||
[HideInInspector] public GameObject EquippedObject;
|
||||
[HideInInspector] public float IkWeight = 1f;
|
||||
|
||||
[HideInInspector] public Quaternion OriginalShoulderRotation;
|
||||
[HideInInspector] public Quaternion OriginalElbowRotation;
|
||||
[HideInInspector] public Quaternion OriginalWristRotation;
|
||||
|
||||
private int _transitionTweenId = -1;
|
||||
private int _ikWeightTweenId = -1;
|
||||
private int _ikBlendTweenId = -1;
|
||||
private bool _isBlendingToIk = false;
|
||||
|
||||
private int _tapTweenId = -1;
|
||||
private bool _isShaking = false;
|
||||
private TapAnimationSettings _currentShakeSettings;
|
||||
|
||||
private Quaternion _transitionStartShoulder;
|
||||
private Quaternion _transitionStartElbow;
|
||||
private Quaternion _transitionStartWrist;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (IkLimb != null && IkLimb.Target != null)
|
||||
{
|
||||
OriginalTargetPosition = IkLimb.Target.localPosition;
|
||||
OriginalTargetRotation = IkLimb.Target.localRotation;
|
||||
}
|
||||
|
||||
if (ShoulderBone != null)
|
||||
OriginalShoulderRotation = ShoulderBone.localRotation;
|
||||
|
||||
if (ElbowBone != null)
|
||||
OriginalElbowRotation = ElbowBone.localRotation;
|
||||
|
||||
if (WristBone != null)
|
||||
OriginalWristRotation = WristBone.localRotation;
|
||||
|
||||
State = ArmState.Environmental;
|
||||
IkWeight = 1f;
|
||||
}
|
||||
|
||||
public void StartTransitionToEquipped(GameObject objectToEquip, System.Action onTransitionComplete)
|
||||
{
|
||||
if (State != ArmState.Environmental)
|
||||
return;
|
||||
|
||||
State = ArmState.TransitionToEquipped;
|
||||
EquippedObject = objectToEquip;
|
||||
|
||||
CancelActiveTweens();
|
||||
|
||||
if (IkLimb == null || IkLimb.Target == null)
|
||||
{
|
||||
CompleteEquip(onTransitionComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 transitionTarget = OriginalTargetPosition + TransitionOffset;
|
||||
|
||||
_transitionTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, TransitionOutDuration)
|
||||
.setEase(TransitionCurve)
|
||||
.setOnUpdate((float t) => {
|
||||
if (IkLimb != null && IkLimb.Target != null)
|
||||
{
|
||||
IkLimb.Target.localPosition = Vector3.Lerp(IkLimb.Target.localPosition, transitionTarget, t);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_transitionTweenId = -1;
|
||||
CompleteEquip(onTransitionComplete);
|
||||
}).id;
|
||||
|
||||
_ikWeightTweenId = LeanTween.value(IkLimb.gameObject, IkWeight, 0f, TransitionOutDuration * 0.5f)
|
||||
.setOnUpdate((float val) => {
|
||||
IkWeight = val;
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_ikWeightTweenId = -1;
|
||||
}).id;
|
||||
}
|
||||
|
||||
private void CompleteEquip(System.Action onComplete)
|
||||
{
|
||||
State = ArmState.Equipped;
|
||||
|
||||
if (IkLimb != null)
|
||||
{
|
||||
IkLimb.enabled = false;
|
||||
}
|
||||
|
||||
if (EquippedObject != null && HandSocket != null)
|
||||
{
|
||||
EquippedObject.transform.SetParent(HandSocket, false);
|
||||
EquippedObject.transform.localPosition = Vector3.zero;
|
||||
EquippedObject.transform.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateEquippedPose()
|
||||
{
|
||||
if (State != ArmState.Equipped && !_isBlendingToIk)
|
||||
return;
|
||||
|
||||
if (_isShaking)
|
||||
{
|
||||
UpdateShake();
|
||||
return;
|
||||
}
|
||||
|
||||
if (State == ArmState.Equipped)
|
||||
{
|
||||
float deltaTime = UnityEngine.Time.deltaTime;
|
||||
float lerpSpeed = 1f - Mathf.Exp(-RotationSpeed * deltaTime);
|
||||
|
||||
if (ShoulderBone != null)
|
||||
{
|
||||
Quaternion targetRot = OriginalShoulderRotation * Quaternion.Euler(ShoulderRotationOffset);
|
||||
ShoulderBone.localRotation = Quaternion.Slerp(ShoulderBone.localRotation, targetRot, lerpSpeed);
|
||||
}
|
||||
|
||||
if (ElbowBone != null)
|
||||
{
|
||||
Quaternion targetRot = OriginalElbowRotation * Quaternion.Euler(ElbowRotationOffset);
|
||||
ElbowBone.localRotation = Quaternion.Slerp(ElbowBone.localRotation, targetRot, lerpSpeed);
|
||||
}
|
||||
|
||||
if (WristBone != null)
|
||||
{
|
||||
Quaternion targetRot = OriginalWristRotation * Quaternion.Euler(WristRotationOffset);
|
||||
WristBone.localRotation = Quaternion.Slerp(WristBone.localRotation, targetRot, lerpSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTransitionToEnvironmental(System.Action onTransitionComplete)
|
||||
{
|
||||
if (State != ArmState.Equipped)
|
||||
return;
|
||||
|
||||
State = ArmState.TransitionToEnvironmental;
|
||||
|
||||
CancelActiveTweens();
|
||||
|
||||
_transitionStartShoulder = ShoulderBone != null ? ShoulderBone.localRotation : Quaternion.identity;
|
||||
_transitionStartElbow = ElbowBone != null ? ElbowBone.localRotation : Quaternion.identity;
|
||||
_transitionStartWrist = WristBone != null ? WristBone.localRotation : Quaternion.identity;
|
||||
|
||||
if (IkLimb == null || IkLimb.Target == null)
|
||||
{
|
||||
CompleteUnequip(onTransitionComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 currentPosition = IkLimb.Target.localPosition;
|
||||
Vector3 transitionTarget = OriginalTargetPosition + TransitionOffset;
|
||||
|
||||
_ikWeightTweenId = LeanTween.value(IkLimb.gameObject, IkWeight, 0f, TransitionInDuration * 0.5f)
|
||||
.setOnUpdate((float val) => {
|
||||
IkWeight = val;
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_ikWeightTweenId = -1;
|
||||
}).id;
|
||||
|
||||
_transitionTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, TransitionInDuration)
|
||||
.setEase(TransitionCurve)
|
||||
.setOnUpdate((float t) => {
|
||||
if (IkLimb != null && IkLimb.Target != null)
|
||||
{
|
||||
IkLimb.Target.localPosition = Vector3.Lerp(currentPosition, transitionTarget, t);
|
||||
}
|
||||
|
||||
if (ShoulderBone != null)
|
||||
ShoulderBone.localRotation = Quaternion.Slerp(_transitionStartShoulder, OriginalShoulderRotation, t);
|
||||
|
||||
if (ElbowBone != null)
|
||||
ElbowBone.localRotation = Quaternion.Slerp(_transitionStartElbow, OriginalElbowRotation, t);
|
||||
|
||||
if (WristBone != null)
|
||||
WristBone.localRotation = Quaternion.Slerp(_transitionStartWrist, OriginalWristRotation, t);
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_transitionTweenId = -1;
|
||||
StartIkBlend(onTransitionComplete);
|
||||
}).id;
|
||||
}
|
||||
|
||||
private void StartIkBlend(System.Action onTransitionComplete)
|
||||
{
|
||||
if (IkLimb != null)
|
||||
{
|
||||
IkLimb.enabled = true;
|
||||
}
|
||||
|
||||
if (EquippedObject != null)
|
||||
{
|
||||
if (HandSocket != null)
|
||||
EquippedObject.transform.SetParent(null);
|
||||
|
||||
UnityEngine.Object.Destroy(EquippedObject);
|
||||
EquippedObject = null;
|
||||
}
|
||||
|
||||
_isBlendingToIk = true;
|
||||
|
||||
Quaternion startShoulder = ShoulderBone != null ? ShoulderBone.localRotation : Quaternion.identity;
|
||||
Quaternion startElbow = ElbowBone != null ? ElbowBone.localRotation : Quaternion.identity;
|
||||
Quaternion startWrist = WristBone != null ? WristBone.localRotation : Quaternion.identity;
|
||||
Vector3 startTargetPos = IkLimb != null && IkLimb.Target != null ? IkLimb.Target.localPosition : Vector3.zero;
|
||||
Quaternion startTargetRot = IkLimb != null && IkLimb.Target != null ? IkLimb.Target.localRotation : Quaternion.identity;
|
||||
|
||||
if (IkLimb != null && IkLimb.gameObject != null)
|
||||
{
|
||||
_ikBlendTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, IkBlendDuration)
|
||||
.setEase(LeanTweenType.easeOutQuad)
|
||||
.setOnUpdate((float t) => {
|
||||
if (ShoulderBone != null)
|
||||
ShoulderBone.localRotation = Quaternion.Slerp(startShoulder, OriginalShoulderRotation, t);
|
||||
|
||||
if (ElbowBone != null)
|
||||
ElbowBone.localRotation = Quaternion.Slerp(startElbow, OriginalElbowRotation, t);
|
||||
|
||||
if (WristBone != null)
|
||||
WristBone.localRotation = Quaternion.Slerp(startWrist, OriginalWristRotation, t);
|
||||
|
||||
if (IkLimb != null && IkLimb.Target != null)
|
||||
{
|
||||
IkLimb.Target.localPosition = Vector3.Lerp(startTargetPos, OriginalTargetPosition, t);
|
||||
IkLimb.Target.localRotation = Quaternion.Slerp(startTargetRot, OriginalTargetRotation, t);
|
||||
}
|
||||
|
||||
IkWeight = t;
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_ikBlendTweenId = -1;
|
||||
CompleteUnequip(onTransitionComplete);
|
||||
}).id;
|
||||
}
|
||||
else
|
||||
{
|
||||
CompleteUnequip(onTransitionComplete);
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteUnequip(System.Action onComplete)
|
||||
{
|
||||
State = ArmState.Environmental;
|
||||
_isBlendingToIk = false;
|
||||
|
||||
if (IkLimb != null && IkLimb.Target != null)
|
||||
{
|
||||
IkLimb.Target.localPosition = OriginalTargetPosition;
|
||||
IkLimb.Target.localRotation = OriginalTargetRotation;
|
||||
}
|
||||
|
||||
if (ShoulderBone != null)
|
||||
ShoulderBone.localRotation = OriginalShoulderRotation;
|
||||
|
||||
if (ElbowBone != null)
|
||||
ElbowBone.localRotation = OriginalElbowRotation;
|
||||
|
||||
if (WristBone != null)
|
||||
WristBone.localRotation = OriginalWristRotation;
|
||||
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
|
||||
public void CancelActiveTweens()
|
||||
{
|
||||
if (_transitionTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_transitionTweenId);
|
||||
_transitionTweenId = -1;
|
||||
}
|
||||
|
||||
if (_ikWeightTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_ikWeightTweenId);
|
||||
_ikWeightTweenId = -1;
|
||||
}
|
||||
|
||||
if (_ikBlendTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_ikBlendTweenId);
|
||||
_ikBlendTweenId = -1;
|
||||
}
|
||||
|
||||
if (_tapTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_tapTweenId);
|
||||
_tapTweenId = -1;
|
||||
}
|
||||
|
||||
_isBlendingToIk = false;
|
||||
_isShaking = false;
|
||||
}
|
||||
|
||||
public void PlayTapAnimation(TapAnimationSettings settings)
|
||||
{
|
||||
if (State != ArmState.Equipped || settings == null)
|
||||
return;
|
||||
|
||||
if (_tapTweenId != -1)
|
||||
{
|
||||
LeanTween.cancel(_tapTweenId);
|
||||
}
|
||||
|
||||
Quaternion elbowStart = ElbowBone != null ? ElbowBone.localRotation : Quaternion.identity;
|
||||
Quaternion wristStart = WristBone != null ? WristBone.localRotation : Quaternion.identity;
|
||||
|
||||
Quaternion elbowWindup = elbowStart * Quaternion.Euler(0, 0, -settings.WindupRotation);
|
||||
Quaternion elbowStrike = elbowStart * Quaternion.Euler(0, 0, settings.WindupRotation * 0.3f);
|
||||
|
||||
Quaternion wristWindup = wristStart;
|
||||
Quaternion wristStrike = wristStart * Quaternion.Euler(0, 0, -settings.WristSnapRotation);
|
||||
|
||||
_tapTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, settings.WindupDuration)
|
||||
.setOnUpdate((float t) => {
|
||||
if (ElbowBone != null)
|
||||
{
|
||||
ElbowBone.localRotation = Quaternion.Slerp(elbowStart, elbowWindup, t);
|
||||
}
|
||||
if (WristBone != null)
|
||||
{
|
||||
WristBone.localRotation = Quaternion.Slerp(wristStart, wristWindup, t);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_tapTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, settings.StrikeDuration)
|
||||
.setOnUpdate((float t) => {
|
||||
if (ElbowBone != null)
|
||||
{
|
||||
ElbowBone.localRotation = Quaternion.Slerp(elbowWindup, elbowStrike, t);
|
||||
}
|
||||
if (WristBone != null)
|
||||
{
|
||||
WristBone.localRotation = Quaternion.Slerp(wristWindup, wristStrike, t);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_tapTweenId = LeanTween.value(IkLimb.gameObject, 0f, 1f, 0.1f)
|
||||
.setOnUpdate((float t) => {
|
||||
if (ElbowBone != null)
|
||||
{
|
||||
ElbowBone.localRotation = Quaternion.Slerp(elbowStrike, elbowStart, t);
|
||||
}
|
||||
if (WristBone != null)
|
||||
{
|
||||
WristBone.localRotation = Quaternion.Slerp(wristStrike, wristStart, t);
|
||||
}
|
||||
})
|
||||
.setOnComplete(() => {
|
||||
_tapTweenId = -1;
|
||||
}).id;
|
||||
}).id;
|
||||
}).id;
|
||||
}
|
||||
|
||||
public void StartShake(TapAnimationSettings settings)
|
||||
{
|
||||
_isShaking = true;
|
||||
_currentShakeSettings = settings;
|
||||
}
|
||||
|
||||
public void StopShake()
|
||||
{
|
||||
_isShaking = false;
|
||||
_currentShakeSettings = null;
|
||||
}
|
||||
|
||||
public void UpdateShake()
|
||||
{
|
||||
if (!_isShaking || State != ArmState.Equipped || WristBone == null || _currentShakeSettings == null)
|
||||
return;
|
||||
|
||||
float shake = Mathf.Sin(UnityEngine.Time.time * _currentShakeSettings.ShakeSpeed) * _currentShakeSettings.ShakeIntensity;
|
||||
Quaternion shakeRotation = Quaternion.Euler(shake, shake * 0.5f, 0);
|
||||
|
||||
Quaternion targetRot = OriginalWristRotation * Quaternion.Euler(WristRotationOffset) * shakeRotation;
|
||||
WristBone.localRotation = targetRot;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80d59ec0ac09852429c56ca6c42464c2
|
||||
@@ -1,367 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Unheimlich.Audio;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public class DiapasonEquipmentManager : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private OctoIkArmsImproved _armsSystem;
|
||||
[SerializeField] private GameObject _diapasonPrefab;
|
||||
[SerializeField] private int _equipmentArmIndex = 1;
|
||||
|
||||
[Header("Detection Settings")]
|
||||
[SerializeField] private LayerMask _soundEmitterLayer;
|
||||
[SerializeField] private float _detectionRadius = 0.15f;
|
||||
[SerializeField] private Transform[] _detectionPoints;
|
||||
|
||||
[Header("Visual Feedback")]
|
||||
[SerializeField] private GameObject _contactFeedbackPrefab;
|
||||
|
||||
[Header("Diapason Animation")]
|
||||
[SerializeField] private string _vibratingBoolParam = "IsVibrating";
|
||||
[SerializeField] private string _tapTriggerParam = "Tap";
|
||||
|
||||
[Header("Tap Settings")]
|
||||
[SerializeField] private AudioClip _tapSound;
|
||||
[SerializeField] [Range(0f, 1f)] private float _tapVolume = 1f;
|
||||
[SerializeField] private float _vibrationDuration = 15f;
|
||||
|
||||
public bool IsEquipped => _isEquipped;
|
||||
public AudioListenable CurrentDetectedEmitter => _currentDetectedEmitter;
|
||||
public bool CanTap => _isEquipped && _currentDetectedEmitter != null && !_isVibrating && !_currentDetectedEmitter.HasBeenTapped;
|
||||
|
||||
public event Action<AudioListenable> OnEmitterDetected;
|
||||
public event Action<AudioListenable> OnEmitterLost;
|
||||
|
||||
private GameObject _spawnedDiapason;
|
||||
private bool _isEquipped = false;
|
||||
private AudioListenable _currentDetectedEmitter;
|
||||
private GameObject _contactFeedback;
|
||||
private bool _isVibrating = false;
|
||||
private AudioSource _audioSource;
|
||||
private Coroutine _vibrationCoroutine;
|
||||
private Animator _diapasonAnimator;
|
||||
private ParticleSystem _diapasonParticles;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (_armsSystem == null)
|
||||
{
|
||||
_armsSystem = GetComponent<OctoIkArmsImproved>();
|
||||
if (_armsSystem == null)
|
||||
{
|
||||
Debug.LogError("[DiapasonEquipment] OctoIkArmsImproved not found!");
|
||||
}
|
||||
}
|
||||
|
||||
_audioSource = GetComponent<AudioSource>();
|
||||
if (_audioSource == null)
|
||||
{
|
||||
_audioSource = gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_isEquipped && _armsSystem.GetArmState(_equipmentArmIndex) == ArmState.Equipped)
|
||||
{
|
||||
CheckForSoundEmitters();
|
||||
|
||||
if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
if (CanTap)
|
||||
{
|
||||
TapDiapason();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EquipDiapason()
|
||||
{
|
||||
if (_isEquipped)
|
||||
{
|
||||
Debug.LogWarning("[DiapasonEquipment] Diapason already equipped!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_diapasonPrefab == null)
|
||||
{
|
||||
Debug.LogError("[DiapasonEquipment] Diapason prefab not assigned!");
|
||||
return;
|
||||
}
|
||||
|
||||
_spawnedDiapason = Instantiate(_diapasonPrefab);
|
||||
_spawnedDiapason.SetActive(true);
|
||||
|
||||
_diapasonAnimator = _spawnedDiapason.GetComponentInChildren<Animator>(true);
|
||||
if (_diapasonAnimator == null)
|
||||
{
|
||||
Debug.LogWarning("[DiapasonEquipment] No Animator found on spawned diapason");
|
||||
}
|
||||
else
|
||||
{
|
||||
_diapasonAnimator.enabled = false;
|
||||
}
|
||||
|
||||
_diapasonParticles = _spawnedDiapason.GetComponentInChildren<ParticleSystem>(true);
|
||||
if (_diapasonParticles == null)
|
||||
{
|
||||
Debug.LogWarning("[DiapasonEquipment] No ParticleSystem found on spawned diapason");
|
||||
}
|
||||
|
||||
_armsSystem.EquipObjectOnArm(_equipmentArmIndex, _spawnedDiapason, () => {
|
||||
_isEquipped = true;
|
||||
OnDiapasonEquipped();
|
||||
});
|
||||
}
|
||||
|
||||
public void UnequipDiapason()
|
||||
{
|
||||
if (!_isEquipped)
|
||||
{
|
||||
Debug.LogWarning("[DiapasonEquipment] Diapason not equipped!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_vibrationCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_vibrationCoroutine);
|
||||
_vibrationCoroutine = null;
|
||||
}
|
||||
|
||||
if (_currentDetectedEmitter != null)
|
||||
{
|
||||
_currentDetectedEmitter.SetConcentrating(false);
|
||||
_currentDetectedEmitter.StopListening(cancelConcentrationFade: false);
|
||||
_currentDetectedEmitter = null;
|
||||
}
|
||||
|
||||
_armsSystem.UnequipObjectFromArm(_equipmentArmIndex, () => {
|
||||
_isEquipped = false;
|
||||
_spawnedDiapason = null;
|
||||
OnDiapasonUnequipped();
|
||||
});
|
||||
}
|
||||
|
||||
private void CheckForSoundEmitters()
|
||||
{
|
||||
if (_detectionPoints == null || _detectionPoints.Length == 0)
|
||||
return;
|
||||
|
||||
AudioListenable closestEmitter = null;
|
||||
float closestDistance = float.MaxValue;
|
||||
|
||||
foreach (Transform detectionPoint in _detectionPoints)
|
||||
{
|
||||
if (detectionPoint == null)
|
||||
continue;
|
||||
|
||||
Collider[] hits = Physics.OverlapSphere(detectionPoint.position, _detectionRadius, _soundEmitterLayer);
|
||||
|
||||
foreach (Collider hit in hits)
|
||||
{
|
||||
AudioListenable emitter = hit.GetComponent<AudioListenable>();
|
||||
|
||||
if (emitter != null)
|
||||
{
|
||||
float distance = Vector3.Distance(detectionPoint.position, hit.transform.position);
|
||||
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestEmitter = emitter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (closestEmitter != _currentDetectedEmitter)
|
||||
{
|
||||
if (_currentDetectedEmitter != null)
|
||||
{
|
||||
OnEmitterExited(_currentDetectedEmitter);
|
||||
}
|
||||
|
||||
_currentDetectedEmitter = closestEmitter;
|
||||
|
||||
if (_currentDetectedEmitter != null)
|
||||
{
|
||||
OnEmitterEntered(_currentDetectedEmitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDiapasonEquipped()
|
||||
{
|
||||
if (_diapasonAnimator != null)
|
||||
{
|
||||
_diapasonAnimator.enabled = true;
|
||||
_diapasonAnimator.SetBool(_vibratingBoolParam, false);
|
||||
}
|
||||
|
||||
if (_diapasonParticles != null)
|
||||
{
|
||||
_diapasonParticles.Stop();
|
||||
var emission = _diapasonParticles.emission;
|
||||
emission.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDiapasonUnequipped()
|
||||
{
|
||||
_isVibrating = false;
|
||||
_diapasonAnimator = null;
|
||||
_diapasonParticles = null;
|
||||
}
|
||||
|
||||
public void TapDiapason()
|
||||
{
|
||||
if (!CanTap)
|
||||
{
|
||||
Debug.LogWarning("[DiapasonEquipment] Cannot tap: not equipped, no contact, or already tapped");
|
||||
return;
|
||||
}
|
||||
|
||||
TapAnimationSettings tapSettings = null;
|
||||
if (_spawnedDiapason != null)
|
||||
{
|
||||
EquippableTapSettings equippable = _spawnedDiapason.GetComponent<EquippableTapSettings>();
|
||||
if (equippable != null)
|
||||
{
|
||||
tapSettings = equippable.TapSettings;
|
||||
}
|
||||
}
|
||||
|
||||
ArmEquipment equipment = _armsSystem.GetArmEquipment(_equipmentArmIndex);
|
||||
if (equipment != null && tapSettings != null)
|
||||
{
|
||||
equipment.PlayTapAnimation(tapSettings);
|
||||
equipment.StartShake(tapSettings);
|
||||
}
|
||||
|
||||
if (_tapSound != null && _audioSource != null)
|
||||
{
|
||||
_audioSource.PlayOneShot(_tapSound, _tapVolume);
|
||||
}
|
||||
|
||||
if (_diapasonAnimator != null)
|
||||
{
|
||||
_diapasonAnimator.SetTrigger(_tapTriggerParam);
|
||||
_diapasonAnimator.SetBool(_vibratingBoolParam, true);
|
||||
}
|
||||
|
||||
if (_diapasonParticles != null)
|
||||
{
|
||||
var emission = _diapasonParticles.emission;
|
||||
emission.enabled = true;
|
||||
_diapasonParticles.Play();
|
||||
}
|
||||
|
||||
_isVibrating = true;
|
||||
|
||||
if (_currentDetectedEmitter != null)
|
||||
{
|
||||
_currentDetectedEmitter.StartListening(transform.position);
|
||||
}
|
||||
|
||||
if (_vibrationCoroutine != null)
|
||||
StopCoroutine(_vibrationCoroutine);
|
||||
_vibrationCoroutine = StartCoroutine(StopVibrationAfterDuration());
|
||||
}
|
||||
|
||||
private IEnumerator StopVibrationAfterDuration()
|
||||
{
|
||||
yield return new WaitForSeconds(_vibrationDuration);
|
||||
|
||||
if (_diapasonAnimator != null)
|
||||
{
|
||||
_diapasonAnimator.SetBool(_vibratingBoolParam, false);
|
||||
}
|
||||
|
||||
if (_diapasonParticles != null)
|
||||
{
|
||||
_diapasonParticles.Stop();
|
||||
var emission = _diapasonParticles.emission;
|
||||
emission.enabled = false;
|
||||
}
|
||||
|
||||
if (_currentDetectedEmitter != null)
|
||||
{
|
||||
_currentDetectedEmitter.StopListening();
|
||||
}
|
||||
|
||||
ArmEquipment equipment = _armsSystem.GetArmEquipment(_equipmentArmIndex);
|
||||
if (equipment != null)
|
||||
{
|
||||
equipment.StopShake();
|
||||
}
|
||||
|
||||
_isVibrating = false;
|
||||
_vibrationCoroutine = null;
|
||||
}
|
||||
|
||||
private void OnEmitterEntered(AudioListenable emitter)
|
||||
{
|
||||
|
||||
emitter.SetConcentrating(true);
|
||||
|
||||
if (_contactFeedbackPrefab != null && _contactFeedback == null)
|
||||
{
|
||||
_contactFeedback = Instantiate(_contactFeedbackPrefab, emitter.transform);
|
||||
_contactFeedback.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
|
||||
OnEmitterDetected?.Invoke(emitter);
|
||||
}
|
||||
|
||||
private void OnEmitterExited(AudioListenable emitter)
|
||||
{
|
||||
emitter.SetConcentrating(false);
|
||||
|
||||
if (!emitter.HasBeenTapped)
|
||||
{
|
||||
emitter.StopListening();
|
||||
}
|
||||
|
||||
if (_contactFeedback != null)
|
||||
{
|
||||
Destroy(_contactFeedback);
|
||||
_contactFeedback = null;
|
||||
}
|
||||
|
||||
if (_diapasonAnimator != null)
|
||||
{
|
||||
_diapasonAnimator.SetBool(_vibratingBoolParam, false);
|
||||
}
|
||||
|
||||
if (_diapasonParticles != null)
|
||||
{
|
||||
_diapasonParticles.Stop();
|
||||
var emission = _diapasonParticles.emission;
|
||||
emission.enabled = false;
|
||||
}
|
||||
|
||||
_isVibrating = false;
|
||||
|
||||
OnEmitterLost?.Invoke(emitter);
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_detectionPoints == null || !_isEquipped)
|
||||
return;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
|
||||
foreach (Transform detectionPoint in _detectionPoints)
|
||||
{
|
||||
if (detectionPoint != null)
|
||||
{
|
||||
Gizmos.DrawWireSphere(detectionPoint.position, _detectionRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38b80731eb88f834ab3d79a566e40b48
|
||||
@@ -1,41 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class DiapasonEquipmentTester : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private DiapasonEquipmentManager _equipmentManager;
|
||||
|
||||
[Header("Input")]
|
||||
[SerializeField] private Key _equipKey = Key.E;
|
||||
[SerializeField] private Key _unequipKey = Key.R;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_equipmentManager == null)
|
||||
return;
|
||||
|
||||
if (Keyboard.current[_equipKey].wasPressedThisFrame)
|
||||
{
|
||||
_equipmentManager.EquipDiapason();
|
||||
}
|
||||
|
||||
if (Keyboard.current[_unequipKey].wasPressedThisFrame)
|
||||
{
|
||||
_equipmentManager.UnequipDiapason();
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.BeginArea(new Rect(10, 10, 350, 150));
|
||||
GUILayout.Label("=== Diapason Equipment System ===");
|
||||
GUILayout.Label($"Press {_equipKey} to Equip Diapason");
|
||||
GUILayout.Label($"Press {_unequipKey} to Unequip Diapason");
|
||||
GUILayout.Label("");
|
||||
GUILayout.Label("When equipped:");
|
||||
GUILayout.Label("• Move LEFT hand to touch AudioListenable");
|
||||
GUILayout.Label("• LEFT CLICK to tap and activate");
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9279e0fb73118d14ba6f2cf05170a660
|
||||
@@ -1,175 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d1a1f500877b404fa6d23dff3bfa8c8
|
||||
@@ -1,32 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class TapAnimationSettings
|
||||
{
|
||||
[Header("Tap Motion")]
|
||||
[Tooltip("Elbow rotation during windup (degrees)")]
|
||||
public float WindupRotation = 15f;
|
||||
|
||||
[Tooltip("Duration of windup (pull back)")]
|
||||
public float WindupDuration = 0.1f;
|
||||
|
||||
[Tooltip("Duration of strike (forward snap)")]
|
||||
public float StrikeDuration = 0.05f;
|
||||
|
||||
[Tooltip("Wrist snap rotation during strike (degrees)")]
|
||||
public float WristSnapRotation = 10f;
|
||||
|
||||
[Header("Vibration Shake")]
|
||||
[Tooltip("Shake intensity during vibration")]
|
||||
public float ShakeIntensity = 2f;
|
||||
|
||||
[Tooltip("Shake speed (frequency)")]
|
||||
public float ShakeSpeed = 30f;
|
||||
}
|
||||
|
||||
public class EquippableTapSettings : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TapAnimationSettings _tapSettings = new TapAnimationSettings();
|
||||
|
||||
public TapAnimationSettings TapSettings => _tapSettings;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b46af809fa8f34d49b3dec606a505c5e
|
||||
@@ -1,423 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class OctoIkArmsImproved : MonoBehaviour
|
||||
{
|
||||
// Stores raycast hit information
|
||||
private class RaycastInfos
|
||||
{
|
||||
public bool HasHit;
|
||||
public float Distance;
|
||||
public float MaxDistance;
|
||||
public Vector3 Position;
|
||||
public Vector3 Normal;
|
||||
public Transform Transform;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class RaycastRig
|
||||
{
|
||||
public Transform Root;
|
||||
public float Distance = 1f;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class ArmRig
|
||||
{
|
||||
public bool Enabled = true;
|
||||
public OctoIkLimb Arm;
|
||||
public Vector3 RotationOffset;
|
||||
public RaycastRig[] Raycasts;
|
||||
|
||||
[Header("Equipment System")]
|
||||
public ArmEquipment Equipment;
|
||||
|
||||
[HideInInspector] public Vector3 TargetOriginPos;
|
||||
[HideInInspector] public Quaternion TargetOriginRot;
|
||||
[HideInInspector] public Vector3 PoleOriginPos;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (Arm)
|
||||
{
|
||||
if (Arm.Target)
|
||||
{
|
||||
TargetOriginPos = Arm.Target.localPosition;
|
||||
TargetOriginRot = Arm.Target.localRotation;
|
||||
}
|
||||
|
||||
if (Arm.Pole)
|
||||
{
|
||||
PoleOriginPos = Arm.Pole.localPosition;
|
||||
}
|
||||
}
|
||||
|
||||
if (Equipment != null)
|
||||
{
|
||||
Equipment.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnvironmentalIkActive()
|
||||
{
|
||||
if (Equipment == null)
|
||||
return Enabled;
|
||||
|
||||
return Enabled && Equipment.State == ArmState.Environmental;
|
||||
}
|
||||
|
||||
public float GetEnvironmentalIkWeight()
|
||||
{
|
||||
if (Equipment == null)
|
||||
return 1f;
|
||||
|
||||
return Equipment.IkWeight;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class Settings
|
||||
{
|
||||
[Header("Raycast")]
|
||||
public LayerMask LayerMask;
|
||||
|
||||
[Header("Stickiness")]
|
||||
[Tooltip("Distance to start sticking (meters)")]
|
||||
[Range(0.1f, 2f)]
|
||||
public float StickStartDistance = 0.8f;
|
||||
|
||||
[Tooltip("Distance to fully release (meters)")]
|
||||
[Range(0.5f, 3f)]
|
||||
public float StickReleaseDistance = 1.2f;
|
||||
|
||||
[Header("Smoothing")]
|
||||
[Tooltip("Stick speed (units/sec)")]
|
||||
[Range(1f, 20f)]
|
||||
public float StickSpeed = 10f;
|
||||
|
||||
[Tooltip("Release speed (units/sec)")]
|
||||
[Range(1f, 20f)]
|
||||
public float ReleaseSpeed = 6f;
|
||||
|
||||
[Tooltip("Rotation speed (deg/sec)")]
|
||||
[Range(90f, 720f)]
|
||||
public float RotationSpeed = 360f;
|
||||
|
||||
[Header("Arm Selection")]
|
||||
[Tooltip("Can both arms stick at the same time?")]
|
||||
public bool AllowBothArms = true;
|
||||
|
||||
[Tooltip("Max surface angle to accept sticking (degrees)")]
|
||||
[Range(0f, 90f)]
|
||||
public float MaxSurfaceAngle = 60f;
|
||||
|
||||
[Header("Temporal Smoothing")]
|
||||
[Tooltip("Frames before releasing (prevents flickering)")]
|
||||
[Range(0, 10)]
|
||||
public int StabilityFrames = 3;
|
||||
}
|
||||
|
||||
[SerializeField] private ArmRig _leftArm;
|
||||
[SerializeField] private ArmRig _rightArm;
|
||||
[SerializeField] private Settings _settings;
|
||||
|
||||
private ArmRig[] _arms;
|
||||
private RaycastInfos[][] _raycasts = new RaycastInfos[2][];
|
||||
private RaycastInfos[] _nearestHitRaycasts = new RaycastInfos[2];
|
||||
private int[] _noHitFrameCount = new int[2];
|
||||
private float[] _currentStickiness = new float[2];
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_arms = new ArmRig[2] { _leftArm, _rightArm };
|
||||
foreach (ArmRig armRig in _arms)
|
||||
armRig.Init();
|
||||
|
||||
// Initialize raycast arrays for both arms
|
||||
_raycasts = new RaycastInfos[_arms.Length][];
|
||||
for (int i = 0; i < _arms.Length; i++)
|
||||
{
|
||||
_raycasts[i] = new RaycastInfos[_arms[i].Raycasts.Length];
|
||||
for (int u = 0; u < _raycasts[i].Length; u++)
|
||||
_raycasts[i][u] = new RaycastInfos() { MaxDistance = 1 };
|
||||
}
|
||||
|
||||
_nearestHitRaycasts = new RaycastInfos[_arms.Length];
|
||||
for (int i = 0; i < _nearestHitRaycasts.Length; i++)
|
||||
_nearestHitRaycasts[i] = new RaycastInfos() { MaxDistance = 1 };
|
||||
|
||||
_noHitFrameCount = new int[_arms.Length];
|
||||
_currentStickiness = new float[_arms.Length];
|
||||
}
|
||||
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
if (Application.isPlaying || !enabled) return;
|
||||
|
||||
foreach (ArmRig armRig in new ArmRig[2] { _leftArm, _rightArm })
|
||||
{
|
||||
if (armRig.Raycasts == null) continue;
|
||||
|
||||
for (int i = 0; i < armRig.Raycasts.Length; i++)
|
||||
{
|
||||
RaycastRig raycastRig = armRig.Raycasts[i];
|
||||
if (raycastRig.Root == null) continue;
|
||||
|
||||
Debug.DrawRay(raycastRig.Root.position, raycastRig.Root.TransformDirection(Vector3.forward) * raycastRig.Distance, Color.cyan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
PerformRaycasts();
|
||||
FindNearestHits();
|
||||
UpdateArmPositions();
|
||||
UpdateEquippedPoses();
|
||||
}
|
||||
|
||||
private void UpdateEquippedPoses()
|
||||
{
|
||||
for (int i = 0; i < _arms.Length; i++)
|
||||
{
|
||||
ArmRig armRig = _arms[i];
|
||||
if (armRig.Equipment != null)
|
||||
{
|
||||
armRig.Equipment.UpdateEquippedPose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cast all configured raycasts and store results
|
||||
private void PerformRaycasts()
|
||||
{
|
||||
for (int i = 0; i < _arms.Length; i++)
|
||||
{
|
||||
ArmRig armRig = _arms[i];
|
||||
|
||||
if (!armRig.IsEnvironmentalIkActive() || armRig.Raycasts == null)
|
||||
continue;
|
||||
|
||||
for (int u = 0; u < armRig.Raycasts.Length; u++)
|
||||
{
|
||||
RaycastRig raycastRig = armRig.Raycasts[u];
|
||||
if (raycastRig.Root == null) continue;
|
||||
|
||||
RaycastInfos raycastInfos = _raycasts[i][u];
|
||||
RaycastHit hit;
|
||||
|
||||
Vector3 origin = raycastRig.Root.position;
|
||||
Vector3 direction = raycastRig.Root.TransformDirection(Vector3.forward);
|
||||
|
||||
if (Physics.Raycast(origin, direction, out hit, raycastRig.Distance, _settings.LayerMask))
|
||||
{
|
||||
Debug.DrawRay(origin, direction * hit.distance, Color.green);
|
||||
|
||||
raycastInfos.HasHit = true;
|
||||
raycastInfos.Distance = hit.distance;
|
||||
raycastInfos.MaxDistance = raycastRig.Distance;
|
||||
raycastInfos.Position = hit.point;
|
||||
raycastInfos.Normal = hit.normal;
|
||||
raycastInfos.Transform = hit.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.DrawRay(origin, direction * raycastRig.Distance, Color.red);
|
||||
|
||||
raycastInfos.HasHit = false;
|
||||
raycastInfos.Distance = raycastRig.Distance;
|
||||
raycastInfos.MaxDistance = raycastRig.Distance;
|
||||
raycastInfos.Position = Vector3.zero;
|
||||
raycastInfos.Normal = Vector3.zero;
|
||||
raycastInfos.Transform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the closest raycast hit for each arm
|
||||
private void FindNearestHits()
|
||||
{
|
||||
for (int i = 0; i < _arms.Length; i++)
|
||||
{
|
||||
ArmRig armRig = _arms[i];
|
||||
RaycastInfos nearest = _nearestHitRaycasts[i];
|
||||
|
||||
nearest.HasHit = false;
|
||||
float closestDistance = float.MaxValue;
|
||||
|
||||
if (armRig.Raycasts == null) continue;
|
||||
|
||||
// Find the closest hit among all raycasts for this arm
|
||||
for (int u = 0; u < armRig.Raycasts.Length; u++)
|
||||
{
|
||||
RaycastInfos raycastInfos = _raycasts[i][u];
|
||||
|
||||
if (raycastInfos.HasHit && raycastInfos.Distance < closestDistance)
|
||||
{
|
||||
closestDistance = raycastInfos.Distance;
|
||||
|
||||
nearest.HasHit = true;
|
||||
nearest.Distance = raycastInfos.Distance;
|
||||
nearest.MaxDistance = raycastInfos.MaxDistance;
|
||||
nearest.Position = raycastInfos.Position;
|
||||
nearest.Normal = raycastInfos.Normal;
|
||||
nearest.Transform = raycastInfos.Transform;
|
||||
}
|
||||
}
|
||||
|
||||
// Track frames without hits for temporal smoothing
|
||||
if (!nearest.HasHit)
|
||||
{
|
||||
_noHitFrameCount[i]++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_noHitFrameCount[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update arm positions based on raycast hits
|
||||
private void UpdateArmPositions()
|
||||
{
|
||||
for (int i = 0; i < _arms.Length; i++)
|
||||
{
|
||||
ArmRig armRig = _arms[i];
|
||||
if (armRig.Arm == null || armRig.Arm.Target == null) continue;
|
||||
|
||||
if (!armRig.IsEnvironmentalIkActive())
|
||||
continue;
|
||||
|
||||
RaycastInfos raycastInfos = _nearestHitRaycasts[i];
|
||||
|
||||
Vector3 targetPos = armRig.TargetOriginPos;
|
||||
Quaternion targetRot = armRig.TargetOriginRot;
|
||||
|
||||
bool shouldStick = false;
|
||||
|
||||
if (raycastInfos.HasHit && _noHitFrameCount[i] < _settings.StabilityFrames)
|
||||
{
|
||||
if (IsValidSurface(raycastInfos, i))
|
||||
{
|
||||
targetPos = armRig.Arm.Target.parent.InverseTransformPoint(raycastInfos.Position);
|
||||
|
||||
targetRot = Quaternion.LookRotation(
|
||||
-armRig.Arm.Target.parent.InverseTransformDirection(raycastInfos.Normal),
|
||||
transform.up
|
||||
) * Quaternion.Euler(armRig.RotationOffset);
|
||||
|
||||
shouldStick = true;
|
||||
}
|
||||
}
|
||||
|
||||
float targetStickiness = shouldStick ? 1f : 0f;
|
||||
float stickinessSpeed = shouldStick ? _settings.StickSpeed : _settings.ReleaseSpeed;
|
||||
_currentStickiness[i] = Mathf.MoveTowards(_currentStickiness[i], targetStickiness, stickinessSpeed * Time.deltaTime);
|
||||
|
||||
float distanceFactor = 0f;
|
||||
if (shouldStick && raycastInfos.HasHit)
|
||||
{
|
||||
distanceFactor = 1f - Mathf.InverseLerp(_settings.StickStartDistance, _settings.StickReleaseDistance, raycastInfos.Distance);
|
||||
distanceFactor = Mathf.Clamp01(distanceFactor);
|
||||
}
|
||||
|
||||
float finalStickiness = _currentStickiness[i] * distanceFactor * armRig.GetEnvironmentalIkWeight();
|
||||
|
||||
float posSpeed = Mathf.Lerp(_settings.ReleaseSpeed, _settings.StickSpeed, finalStickiness);
|
||||
float rotSpeed = _settings.RotationSpeed * Mathf.Deg2Rad;
|
||||
|
||||
float tPos = 1f - Mathf.Exp(-posSpeed * Time.deltaTime);
|
||||
float tRot = 1f - Mathf.Exp(-rotSpeed * Time.deltaTime);
|
||||
|
||||
armRig.Arm.Target.localPosition = Vector3.Lerp(armRig.Arm.Target.localPosition, targetPos, tPos);
|
||||
armRig.Arm.Target.localRotation = Quaternion.Slerp(armRig.Arm.Target.localRotation, targetRot, tRot);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the surface is valid for sticking
|
||||
private bool IsValidSurface(RaycastInfos raycast, int armIndex)
|
||||
{
|
||||
if (raycast.Transform == null)
|
||||
return false;
|
||||
|
||||
// Check surface angle (reject surfaces too angled)
|
||||
float surfaceAngle = Vector3.Angle(-raycast.Normal, transform.forward);
|
||||
if (surfaceAngle > _settings.MaxSurfaceAngle)
|
||||
return false;
|
||||
|
||||
// If not allowing both arms, check if arm is on correct side
|
||||
if (!_settings.AllowBothArms)
|
||||
{
|
||||
Vector3 hitLocalPos = transform.InverseTransformPoint(raycast.Position);
|
||||
bool isLeftSide = hitLocalPos.x < 0;
|
||||
bool isLeftArm = armIndex == 0;
|
||||
|
||||
if (isLeftSide != isLeftArm)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void EquipObjectOnArm(int armIndex, GameObject objectToEquip, System.Action onComplete = null)
|
||||
{
|
||||
if (armIndex < 0 || armIndex >= _arms.Length)
|
||||
{
|
||||
Debug.LogError($"[OctoIkArms] Invalid arm index: {armIndex}");
|
||||
return;
|
||||
}
|
||||
|
||||
ArmRig armRig = _arms[armIndex];
|
||||
|
||||
if (armRig.Equipment == null)
|
||||
{
|
||||
Debug.LogError($"[OctoIkArms] Arm {armIndex} has no Equipment system configured!");
|
||||
return;
|
||||
}
|
||||
|
||||
armRig.Equipment.StartTransitionToEquipped(objectToEquip, onComplete);
|
||||
}
|
||||
|
||||
public void UnequipObjectFromArm(int armIndex, System.Action onComplete = null)
|
||||
{
|
||||
if (armIndex < 0 || armIndex >= _arms.Length)
|
||||
{
|
||||
Debug.LogError($"[OctoIkArms] Invalid arm index: {armIndex}");
|
||||
return;
|
||||
}
|
||||
|
||||
ArmRig armRig = _arms[armIndex];
|
||||
|
||||
if (armRig.Equipment == null)
|
||||
{
|
||||
Debug.LogError($"[OctoIkArms] Arm {armIndex} has no Equipment system configured!");
|
||||
return;
|
||||
}
|
||||
|
||||
armRig.Equipment.StartTransitionToEnvironmental(onComplete);
|
||||
}
|
||||
|
||||
public ArmState GetArmState(int armIndex)
|
||||
{
|
||||
if (armIndex < 0 || armIndex >= _arms.Length)
|
||||
return ArmState.Environmental;
|
||||
|
||||
if (_arms[armIndex].Equipment == null)
|
||||
return ArmState.Environmental;
|
||||
|
||||
return _arms[armIndex].Equipment.State;
|
||||
}
|
||||
|
||||
public bool IsArmInEnvironmentalMode(int armIndex)
|
||||
{
|
||||
return GetArmState(armIndex) == ArmState.Environmental;
|
||||
}
|
||||
|
||||
public ArmEquipment GetArmEquipment(int armIndex)
|
||||
{
|
||||
if (armIndex < 0 || armIndex >= _arms.Length)
|
||||
return null;
|
||||
|
||||
return _arms[armIndex].Equipment;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97777a4e863d974428be79c0d8a40883
|
||||
@@ -1,94 +0,0 @@
|
||||
using UnityEngine;
|
||||
using Unheimlich.Gameplay.Player;
|
||||
|
||||
public class SecurityCameraController : MonoBehaviour
|
||||
{
|
||||
[Header("Tracking Settings")]
|
||||
[SerializeField] private float _trackingDistance = 10f;
|
||||
[SerializeField] private float _rotationSpeed = 2f;
|
||||
[SerializeField] private Transform _pivotPoint;
|
||||
|
||||
[Header("LED Settings")]
|
||||
[SerializeField] private MeshRenderer _ledRenderer;
|
||||
[SerializeField] private float _blinkSpeed = 2f;
|
||||
[SerializeField] private float _minSmoothness = 0f;
|
||||
[SerializeField] private float _maxSmoothness = 0.5f;
|
||||
|
||||
private CharacterController _playerController;
|
||||
private Material _ledMaterial;
|
||||
private float _blinkTimer;
|
||||
private bool _isTracking;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (PlayerController.Instance != null)
|
||||
_playerController = PlayerController.Instance.GetComponent<CharacterController>();
|
||||
|
||||
if (_ledRenderer != null)
|
||||
{
|
||||
_ledMaterial = _ledRenderer.material;
|
||||
}
|
||||
|
||||
if (_pivotPoint == null)
|
||||
_pivotPoint = transform;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_playerController == null) return;
|
||||
|
||||
float distanceToPlayer = Vector3.Distance(_pivotPoint.position, _playerController.transform.position);
|
||||
_isTracking = distanceToPlayer <= _trackingDistance;
|
||||
|
||||
if (_isTracking)
|
||||
{
|
||||
TrackPlayer();
|
||||
}
|
||||
|
||||
UpdateLedBlink();
|
||||
}
|
||||
|
||||
void TrackPlayer()
|
||||
{
|
||||
Vector3 directionToPlayer = _playerController.transform.position - _pivotPoint.position;
|
||||
|
||||
if (directionToPlayer.sqrMagnitude > 0.001f)
|
||||
{
|
||||
Vector3 forward = -directionToPlayer.normalized;
|
||||
Vector3 right = Vector3.Cross(Vector3.up, forward).normalized;
|
||||
Vector3 up = Vector3.Cross(forward, right);
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(up, forward);
|
||||
_pivotPoint.rotation = Quaternion.Slerp(_pivotPoint.rotation, targetRotation, Time.deltaTime * _rotationSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateLedBlink()
|
||||
{
|
||||
if (_ledMaterial == null) return;
|
||||
|
||||
_blinkTimer += Time.deltaTime * _blinkSpeed;
|
||||
|
||||
float smoothness = Mathf.Lerp(_minSmoothness, _maxSmoothness, Mathf.PingPong(_blinkTimer, 1f));
|
||||
|
||||
_ledMaterial.SetFloat("_Smoothness", smoothness);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ledMaterial != null)
|
||||
Destroy(_ledMaterial);
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if (_pivotPoint == null)
|
||||
_pivotPoint = transform;
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(_pivotPoint.position, _trackingDistance);
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(_pivotPoint.position, _pivotPoint.position + _pivotPoint.forward * 2f);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17a573927733b4343acc662995710bc2
|
||||
Reference in New Issue
Block a user