Files
PrinceOfGlory/Assets/__Test/Test/InputTest.cs
kridoo ac041525cc 1
2026-01-12 09:39:28 +08:00

104 lines
2.5 KiB
C#

using BigSpace.Logic;
using BigSpace.XRCore.Event;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.XR;
public class InputTest : MonoBehaviour
{
private PlayableDirector timeLine;
// Start is called before the first frame update
void Start()
{
timeLine = this.GetComponent<PlayableDirector>();
GlobalEventMgr.Listen(GameEvent.EventPlayTimeline, GameDataManage_EventPlayTimeline);
}
void GameDataManage_EventPlayTimeline()
{
timeLine.Play();
}
bool buttonA = false;
bool buttonB = false;
//计时相关
bool isRun_A = false;
float waitTime_A = 1f;
float runTime_A = 0;
//计时相关
bool isRun_B = false;
float waitTime_B = 1f;
float runTime_B = 0;
double speed = 1;
double speedMax = 8;
// Update is called once per frame
void Update()
{
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.primaryButton,out buttonA);
if (buttonA) //要加锁
{
if (!isRun_A)
{
Debug.Log("获取到了按钮");
AddTimeLineSpeed();
}
isRun_A = true;
}
if (isRun_A)
{
runTime_A += Time.deltaTime;
if (runTime_A >= waitTime_A)
{
isRun_A = false;
runTime_A = 0;
}
}
InputDevices.GetDeviceAtXRNode(XRNode.RightHand).TryGetFeatureValue(CommonUsages.secondaryButton, out buttonB);
if (buttonB)
{
if (!isRun_B)
{
Debug.Log("获取到了按钮");
DeductTimeLineSpeed();
}
isRun_B = true;
}
if (isRun_B)
{
runTime_B += Time.deltaTime;
if (runTime_B >= waitTime_B)
{
isRun_B = false;
runTime_B = 0;
}
}
if (Input.GetKeyDown(KeyCode.Q))
{
AddTimeLineSpeed();
}
if (Input.GetKeyDown(KeyCode.R))
{
DeductTimeLineSpeed();
}
}
void AddTimeLineSpeed()
{
speed += 1;
if (speed >= speedMax)
speed = speedMax;
timeLine.playableGraph.GetRootPlayable(0).SetSpeed(speed);
}
void DeductTimeLineSpeed()
{
speed -= 1;
if (speed < 1)
speed = 1;
timeLine.playableGraph.GetRootPlayable(0).SetSpeed(speed);
}
}