4dad9e5d5b
- 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>
132 lines
3.9 KiB
C#
132 lines
3.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using System.Collections.Generic;
|
|
using VRSDK.Events;
|
|
|
|
namespace VRSDK
|
|
{
|
|
public enum GesturePhase
|
|
{
|
|
Tracking,
|
|
Processing
|
|
}
|
|
|
|
//this script read gestures in the controller
|
|
//like a rotation a certain speed and angles
|
|
//this is being use for the weapon system for physics base reload, is beinguse in the revolver
|
|
public class VR_ControllerGesture : MonoBehaviour
|
|
{
|
|
private float minAcelerationThreshold = 0.0f;
|
|
private float maxAcelerationThreshold = 0.0f;
|
|
private int sampleCount = 0;
|
|
|
|
private VR_Controller controller = null;
|
|
private GesturePhase rotationGesturePhase = GesturePhase.Tracking;
|
|
private Quaternion rotationGesturefromQuaternion = Quaternion.identity;
|
|
private OnRotationGestureEvent OnRotationGestureEvent = new OnRotationGestureEvent();
|
|
|
|
private const int MAX_SAMPLING_HISTORY = 30;
|
|
|
|
private void Awake()
|
|
{
|
|
controller = GetComponent<VR_Controller>();
|
|
}
|
|
|
|
public void Construct(ControllerGestureConfig config)
|
|
{
|
|
minAcelerationThreshold = config.minAcelerationThreshold;
|
|
maxAcelerationThreshold = config.maxAcelerationThreshold;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateRotationGesture();
|
|
}
|
|
|
|
// set a listener for a rotation gesture
|
|
public void ListenForRotationGesture(UnityAction<RotationGestureInfo> listener)
|
|
{
|
|
OnRotationGestureEvent.AddListener(listener);
|
|
}
|
|
|
|
//remove listener for a rotation gesture
|
|
public void RemoveRotationGestureListener(UnityAction<RotationGestureInfo> listener)
|
|
{
|
|
OnRotationGestureEvent.RemoveListener(listener);
|
|
}
|
|
|
|
private void UpdateRotationGesture()
|
|
{
|
|
switch (rotationGesturePhase)
|
|
{
|
|
case GesturePhase.Tracking:
|
|
RotationGestureTrackingUpdate();
|
|
break;
|
|
case GesturePhase.Processing:
|
|
RotationGestureProcessingUpdate();
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private void RotationGestureTrackingUpdate()
|
|
{
|
|
List<Quaternion> rotationHistory = GetRotationHistory();
|
|
|
|
if (rotationHistory == null || rotationHistory.Count <= 0)
|
|
return;
|
|
|
|
float rotAceleration = Quaternion.Angle( rotationHistory[0], rotationHistory[rotationHistory.Count - 1] );
|
|
|
|
//detect a fast rotation movement
|
|
if (rotAceleration > maxAcelerationThreshold)
|
|
{
|
|
rotationGesturePhase = GesturePhase.Processing;
|
|
}
|
|
|
|
}
|
|
|
|
private List<Quaternion> GetRotationHistory()
|
|
{
|
|
List<Quaternion> rotationHistory = controller.GetRotationHistorySample( MAX_SAMPLING_HISTORY );
|
|
|
|
return rotationHistory;
|
|
}
|
|
|
|
private void RotationGestureProcessingUpdate()
|
|
{
|
|
List<Quaternion> rotationHistory = GetRotationHistory();
|
|
|
|
if (rotationHistory == null || rotationHistory.Count <= 0)
|
|
return;
|
|
|
|
float rotAceleration = Quaternion.Angle( rotationHistory[0], rotationHistory[rotationHistory.Count - 1] );
|
|
|
|
//wait for the hand to stop
|
|
if (rotAceleration < minAcelerationThreshold)
|
|
{
|
|
OnRotationGestureEvent.Invoke( new RotationGestureInfo( rotationGesturefromQuaternion , rotationHistory[rotationHistory.Count - 1] ) );
|
|
rotationGesturePhase = GesturePhase.Tracking;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class RotationGestureInfo
|
|
{
|
|
public Quaternion from;
|
|
public Quaternion to;
|
|
|
|
public RotationGestureInfo(Quaternion from , Quaternion to)
|
|
{
|
|
this.from = from;
|
|
this.to = to;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|