You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.5 KiB
101 lines
3.5 KiB
|
1 month ago
|
using NaughtyAttributes;
|
||
|
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace UDE_HAND_INTERACTION
|
||
|
|
{
|
||
|
|
public class RayController : MonoBehaviour
|
||
|
|
{
|
||
|
|
private SimInputController simInput;
|
||
|
|
private HandInteractor interactor;
|
||
|
|
private HandDriver handDriver;
|
||
|
|
public enum InteractType
|
||
|
|
{
|
||
|
|
AnyFinger,
|
||
|
|
AllFingers,
|
||
|
|
}
|
||
|
|
[Label("Active Ray")]
|
||
|
|
public bool IsUsingRay;
|
||
|
|
[EnableIf("IsUsingRay")]
|
||
|
|
public InteractType RayActiveType;
|
||
|
|
|
||
|
|
[BoxGroup("Thumb"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool Thumb;
|
||
|
|
[BoxGroup("Thumb"), Label(" Intense"), Range(0, 1), ShowIf("IsUsingRay")]
|
||
|
|
public float ThumbIntense;
|
||
|
|
[BoxGroup("Index"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool Index;
|
||
|
|
[BoxGroup("Index"), Label(" Intense"), Range(0, 1), ShowIf("IsUsingRay")]
|
||
|
|
public float IndexIntense;
|
||
|
|
[BoxGroup("Middle"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool Middle;
|
||
|
|
[BoxGroup("Middle"), Label(" Intense"), Range(0, 1), ShowIf("IsUsingRay")]
|
||
|
|
public float MiddleIntense;
|
||
|
|
[BoxGroup("Ring"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool Ring;
|
||
|
|
[BoxGroup("Ring"), Label(" Intense"), Range(0, 1), ShowIf("IsUsingRay")]
|
||
|
|
public float RingIntense;
|
||
|
|
[BoxGroup("Pinky"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool Pinky;
|
||
|
|
[BoxGroup("Pinky"), Label(" Intense"), Range(0, 1), ShowIf("IsUsingRay")]
|
||
|
|
public float PinkyIntense;
|
||
|
|
[BoxGroup("A Button"), Label(" Active"), ShowIf("IsUsingRay")]
|
||
|
|
public bool AButton;
|
||
|
|
|
||
|
|
private bool[] FingersSelectList;
|
||
|
|
private float[] FingersValueList;
|
||
|
|
private bool[] ActiveCnt;
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
simInput = transform.GetComponentInChildren<SimInputController>();
|
||
|
|
interactor = transform.GetComponent<HandInteractor>();
|
||
|
|
handDriver = interactor.HandDriver;
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if(!IsUsingRay)
|
||
|
|
{
|
||
|
|
simInput?.gameObject.SetActive(false);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
simInput.gameObject.SetActive(true);
|
||
|
|
}
|
||
|
|
FingersSelectList = new bool[5] { Thumb, Index, Middle, Ring, Pinky };
|
||
|
|
FingersValueList = new float[5] { ThumbIntense, IndexIntense, MiddleIntense, RingIntense, PinkyIntense };
|
||
|
|
float[] FingerData = new float[5] { handDriver.thumb2.z, handDriver.index2.z, handDriver.middle2.z, handDriver.ring2.z, handDriver.pinky2.z };
|
||
|
|
ActiveCnt = new bool[5];
|
||
|
|
for(int i = 0; i < 5; ++i)
|
||
|
|
{
|
||
|
|
ActiveCnt[i] = FingersSelectList[i] && Math.Abs(FingerData[i]) >= 80f * FingersValueList[i];
|
||
|
|
}
|
||
|
|
|
||
|
|
bool[] ActiveCheck = new bool[2] { false, true };
|
||
|
|
bool res = false;
|
||
|
|
for (int i = 0; i < 5; ++i)
|
||
|
|
{
|
||
|
|
if (RayActiveType == InteractType.AnyFinger)
|
||
|
|
{
|
||
|
|
ActiveCheck[0] |= ActiveCnt[i];
|
||
|
|
res = ActiveCheck[0];
|
||
|
|
}
|
||
|
|
else if (RayActiveType == InteractType.AllFingers)
|
||
|
|
{
|
||
|
|
ActiveCheck[1] &= ActiveCnt[i];
|
||
|
|
res = ActiveCheck[1];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (AButton)
|
||
|
|
{
|
||
|
|
res |= GetComponentInChildren<HandDriver>().inputData.aButton;
|
||
|
|
}
|
||
|
|
simInput.TriggerActive = res;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|