using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using VRTK;
using ChivaXR.Op;
using QFramework;
public enum HandType { right,left }
public enum ClickType
{
连击,
单击
}
public class ExamHandleManager : MonoBehaviour
{
#region 提示模块
[BoxGroup("提示信息绑定", CenterLabel = true)]
[LabelText("手柄")]
public HandType promptHandType = HandType.right;
[BoxGroup("提示信息绑定", CenterLabel = true)]
[LabelText("手柄按键")]
public SDK_BaseController.ButtonTypes promptButtonType = SDK_BaseController.ButtonTypes.ButtonTwo;
[BoxGroup("提示信息绑定", CenterLabel = true)]
[LabelText("手柄按键触发类型")]
public SDK_BaseController.ButtonPressTypes promptButtonPressType = SDK_BaseController.ButtonPressTypes.PressDown;
[BoxGroup("提示信息绑定", CenterLabel = true)]
[LabelText("点击类型")]
public ClickType clickType;
[ShowIf("clickType",Value = ClickType.连击)]
[BoxGroup("提示信息绑定", CenterLabel = true)]
[LabelText("点击次数")]
public int needClickCount = 1;
private int promptClikCount;
///
/// 提示
///
private void PromptContronl()
{
VRTK_ControllerReference handReference = null;
switch (promptHandType)
{
case HandType.right:
handReference = VRTK_DeviceFinder.GetControllerReferenceRightHand();
break;
case HandType.left:
handReference = VRTK_DeviceFinder.GetControllerReferenceLeftHand();
break;
default:
break;
}
if (VRTK_SDK_Bridge.GetControllerButtonState(promptButtonType, promptButtonPressType, handReference))
{
switch (clickType)
{
case ClickType.连击:
if (promptClikCount == 0) StartCoroutine(StartPromptCount());
promptClikCount++;
if (promptClikCount == needClickCount)
{
StopCoroutine(StartPromptCount());
promptClikCount = 0;
ExamManagerForVR.instance.OpenPrompt();
}
break;
case ClickType.单击:
ExamManagerForVR.instance.OpenPrompt();
break;
default:
break;
}
}
}
private IEnumerator StartPromptCount(float time = 0.5f)
{
yield return new WaitForSeconds(time);
promptClikCount = 0;
}
#endregion
#region 打开结束考试UI
[BoxGroup("结束考试UI绑定", CenterLabel = true)]
[LabelText("手柄")]
public HandType endExamHandType = HandType.right;
[BoxGroup("结束考试UI绑定", CenterLabel = true)]
[LabelText("手柄按键")]
public SDK_BaseController.ButtonTypes endExamButtonType = SDK_BaseController.ButtonTypes.Trigger;
[BoxGroup("结束考试UI绑定", CenterLabel = true)]
[LabelText("手柄按键触发类型")]
public SDK_BaseController.ButtonPressTypes endExamButtonPressType = SDK_BaseController.ButtonPressTypes.PressDown;
[BoxGroup("结束考试UI绑定", CenterLabel = true)]
[LabelText("点击类型")]
public ClickType endExamClickType;
[ShowIf("endExamClickType", Value = ClickType.连击)]
[BoxGroup("结束考试UI绑定", CenterLabel = true)]
[LabelText("点击次数")]
public int endExamNeedClickCount = 1;
private int endExamClikCount = 0;
private void EndExamContronl()
{
VRTK_ControllerReference handReference = null;
switch (endExamHandType)
{
case HandType.right:
handReference = VRTK_DeviceFinder.GetControllerReferenceRightHand();
break;
case HandType.left:
handReference = VRTK_DeviceFinder.GetControllerReferenceLeftHand();
break;
default:
break;
}
if (VRTK_SDK_Bridge.GetControllerButtonState(endExamButtonType, endExamButtonPressType, handReference))
{
switch (endExamClickType)
{
case ClickType.连击:
if (endExamClikCount == 0) StartCoroutine(StartEndExamCount());
endExamClikCount++;
if (endExamClikCount == endExamNeedClickCount)
{
StopCoroutine(StartEndExamCount());
endExamClikCount = 0;
OpenExamResultPanel();
}
break;
case ClickType.单击:
OpenExamResultPanel();
break;
default:
break;
}
}
}
private IEnumerator StartEndExamCount(float time = 0.8f)
{
yield return new WaitForSeconds(time);
endExamClikCount = 0;
}
private void OpenExamResultPanel()
{
ExamResultPanel examResultPanel = FindObjectOfType();
if (examResultPanel != null)
{
if (!examResultPanel.gameObject.activeSelf)
{
examResultPanel.gameObject.SetActive(true);
}
return;
}
EndExamPanel endExamPanel = FindObjectOfType();
if (endExamPanel == null)
{
ResMgr.Init();
var resLoader = ResLoader.Allocate();
GameObject uiPrefab = resLoader.LoadSync("EndExamCanvas");
if (uiPrefab != null)
{
Instantiate(uiPrefab).transform.SetAsLastSibling();
}
}
else
{
endExamPanel.SetSelfPositionAndDisableCameraMove();
}
}
#endregion
private void Update()
{
PromptContronl();
EndExamContronl();
}
}