123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.EventSystems;
- namespace SC.XR.Unity.Module_InputSystem.InputDeviceHand {
- public class InputDeviceHandPartTurnLeftRightEvent : InputDeviceHandPartEventBase {
- public InputDeviceHandPartTurnLeftRightEvent(InputDevicePartDispatchEventHand inputDevicePartDispatchEventHand) : base(inputDevicePartDispatchEventHand) {
- }
- enum TurnAround {
- Left = -1,
- Right = 1,
- }
- List<Vector3> DeltaTrendList = new List<Vector3>(new Vector3[6]);
- int DirectionResult = 0;
- protected int currentNum = 0;
- protected float timer = 0;
- protected override void OnUpdateEvent() {
- currentEvent = HandEventType.Null;
- timer += Time.deltaTime;
- if(timer >= samplingTime) {
- timer = 0;
- if(handInfo.isLost == false) {
- DeltaTrendList[currentNum] = handInfo.finger[(int)FINGER.ring].joint[(int)JOINT.Four].localPosition - handInfo.finger[(int)FINGER.forefinger].joint[(int)JOINT.Four].localPosition;
- } else {
- DeltaTrendList[currentNum] = Vector3.zero;
- }
-
-
-
-
-
-
-
-
-
- DirectionResult = 0;
- for(int i = DeltaTrendList.Count - 1; i >= 0; i--) {
-
- if(DeltaTrendList[i].x > (DeltaTrendList[((i - 1) < 0) ? DeltaTrendList.Count - 1 : i - 1].x + noise)) {
- DirectionResult += (int)TurnAround.Right;
- DebugMy.Log("trendList :" + TurnAround.Right + " " + DirectionResult, this);
- } else if((DeltaTrendList[i].x + noise) < DeltaTrendList[((i - 1) < 0) ? DeltaTrendList.Count - 1 : i - 1].x) {
- DirectionResult += (int)TurnAround.Left;
- DebugMy.Log("trendList :" + TurnAround.Left + " " + DirectionResult, this);
- }
-
- }
-
-
- if(DirectionResult >= effect) {
-
- for(int i = 0; i < DeltaTrendList.Count; i++) {
- DeltaTrendList[i] = Vector3.zero;
- }
- currentEvent = HandEventType.TurnLeft;
- } else if(DirectionResult <= -effect) {
-
- for(int i = 0; i < DeltaTrendList.Count; i++) {
- DeltaTrendList[i] = Vector3.zero;
- }
- currentEvent = HandEventType.TurnRight;
- }
- currentNum++;
- if(currentNum == DeltaTrendList.Count) {
- currentNum = 0;
- }
- }
- }
- }
- }
|