2026.06.25 Fishing scene
This commit is contained in:
@@ -8,6 +8,7 @@ public class FishingHapticManager : MonoBehaviour
|
||||
|
||||
[Header("Haptic Settings")]
|
||||
[SerializeField] private bool useHaptic = true;
|
||||
[SerializeField] private bool showHapticDebugLog = false;
|
||||
|
||||
[SerializeField] private float perfectAmplitude = 1f;
|
||||
[SerializeField] private float perfectDuration = 0.2f;
|
||||
@@ -18,6 +19,19 @@ public class FishingHapticManager : MonoBehaviour
|
||||
[SerializeField] private float missAmplitude = 0.2f;
|
||||
[SerializeField] private float missDuration = 0.05f;
|
||||
|
||||
public XRNode TargetHand => targetHand;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
perfectAmplitude = Mathf.Clamp01(perfectAmplitude);
|
||||
goodAmplitude = Mathf.Clamp01(goodAmplitude);
|
||||
missAmplitude = Mathf.Clamp01(missAmplitude);
|
||||
|
||||
perfectDuration = Mathf.Max(0f, perfectDuration);
|
||||
goodDuration = Mathf.Max(0f, goodDuration);
|
||||
missDuration = Mathf.Max(0f, missDuration);
|
||||
}
|
||||
|
||||
private void SendHaptic(float amplitude, float duration)
|
||||
{
|
||||
if (!useHaptic)
|
||||
@@ -26,15 +40,46 @@ private void SendHaptic(float amplitude, float duration)
|
||||
InputDevice device = InputDevices.GetDeviceAtXRNode(targetHand);
|
||||
|
||||
if (!device.isValid)
|
||||
return;
|
||||
|
||||
if (device.TryGetHapticCapabilities(out HapticCapabilities capabilities))
|
||||
{
|
||||
if (!capabilities.supportsImpulse)
|
||||
return;
|
||||
LogHapticWarning("Haptic device not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
device.SendHapticImpulse(0u, Mathf.Clamp01(amplitude), duration);
|
||||
if (!device.TryGetHapticCapabilities(out HapticCapabilities capabilities))
|
||||
{
|
||||
LogHapticWarning("Haptic capabilities not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!capabilities.supportsImpulse)
|
||||
{
|
||||
LogHapticWarning("Haptic impulse is not supported on this device.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (capabilities.numChannels < 1)
|
||||
{
|
||||
LogHapticWarning("Haptic channel count is zero.");
|
||||
return;
|
||||
}
|
||||
|
||||
device.SendHapticImpulse(0u, Mathf.Clamp01(amplitude), Mathf.Max(0f, duration));
|
||||
}
|
||||
|
||||
private void LogHapticWarning(string message)
|
||||
{
|
||||
if (showHapticDebugLog)
|
||||
Debug.LogWarning($"[FishingHapticManager] {message}", this);
|
||||
}
|
||||
|
||||
public void SetTargetHand(XRNode hand)
|
||||
{
|
||||
targetHand = hand;
|
||||
}
|
||||
|
||||
public void SetUseHaptic(bool value)
|
||||
{
|
||||
useHaptic = value;
|
||||
}
|
||||
|
||||
public void Perfect()
|
||||
@@ -51,4 +96,4 @@ public void Miss()
|
||||
{
|
||||
SendHaptic(missAmplitude, missDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user