Files
BeatSaber/Assets/VRBeatsKit/Modules/VRSDK/VR/VR_Haptics.cs
T
whdwo798 4dad9e5d5b feat: SongCreator 씬 완성 — Beat Sage URL 지원, info.dat 메타데이터 자동 추출
- BeatSageUploader: audio_url 지원(UploadFromUrl), PollAndDownload 공통화, ZIP 500 오류 3회 재시도
- BeatSageConverter: info.dat 파싱(SongMetadata), BPM 자동 감지 → 노트 타이밍 변환에 적용
- SongCreatorManager: title/BPM 필수 입력 제거, 난이도 4개 자동 선택, GenerateFlowFromUrl 버그 수정
- NasPublisher: audioPath null 허용(URL 흐름에서 로컬 파일 없는 경우 스킵)
- .gitignore/.gitattributes 초기 설정

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 23:37:34 +09:00

101 lines
2.9 KiB
C#

using UnityEngine;
#if SDK_STEAM_VR
using Valve.VR;
#endif
namespace VRSDK
{
public class VR_Haptics : MonoBehaviour
{
[SerializeField] private float rate = 0.1f;
[SerializeField] private float multiplier = 1.0f;
private float lastHapticsFeedback = 0.0f;
private bool givingFeedback = false;
private VR_Controller activeController = null;
private VR_Grabbable grabbable = null;
#if SDK_STEAM_VR
private SteamVR_Action_Vibration hapticAction = null;
#endif
private const float MIN_HAPTICS_VALUE = 0.2f;
private void Awake()
{
#if SDK_STEAM_VR
hapticAction = SteamVR_Input.GetAction<SteamVR_Action_Vibration>( "VRShooterKit", "Haptic" );
#endif
grabbable = GetComponent<VR_Grabbable>();
grabbable.OnGrabStateChange.AddListener( OnGrabStateChange );
}
private void OnGrabStateChange(GrabState state)
{
if (state == GrabState.Grab)
{
activeController = grabbable.GrabController;
}
}
private void Update()
{
#if SDK_OCULUS
if (givingFeedback && Time.time - lastHapticsFeedback > rate)
Stop();
#endif
}
public void SetHaptics(float frequency, float amplitud , VR_Controller controller)
{
frequency *= multiplier;
amplitud *= multiplier;
if (amplitud < MIN_HAPTICS_VALUE)
amplitud = MIN_HAPTICS_VALUE;
if (Time.time - lastHapticsFeedback < rate)
return;
if (!givingFeedback)
givingFeedback = true;
lastHapticsFeedback = Time.time;
#if SDK_OCULUS
if(activeController == null) return;
OVRInput.SetControllerVibration(frequency , amplitud , (OVRInput.Controller) activeController.Input.GetControllerType() );
#endif
#if SDK_STEAM_VR
if(controller == null) return;
hapticAction.Execute( 0.0f, rate, Mathf.Min( frequency * 320.0f, 320.0f ), amplitud, (SteamVR_Input_Sources) controller.Input.GetControllerType() );
#endif
activeController = controller;
}
public void SetHaptics(float value , VR_Controller controller)
{
value *= multiplier;
SetHaptics(Random.Range(value / 2.0f , value) , value , controller);
}
public void Stop()
{
givingFeedback = false;
if(activeController == null) return;
#if SDK_OCULUS
OVRInput.SetControllerVibration( 0.0f, 0.0f, (OVRInput.Controller)activeController.Input.GetControllerType());
#endif
#if SDK_STEAM_VR
hapticAction.Execute(0.0f , 0.01f , 0.0f , 0.0f , (SteamVR_Input_Sources) activeController.Input.GetControllerType());
#endif
}
}
}