using System.Collections; using System.Collections.Generic; using UnityEngine; using SC.XR.Unity.Module_Tooltip; using SC.XR.Unity.Module_InputSystem; using static API_GSXR_Module_InputSystem_Head; using static API_GSXR_Module_InputSystem_BT3Dof; using static API_GSXR_Module_InputSystem_GGT26Dof; using static API_GSXR_Module_InputSystem_KS; using TMPro; using UnityEngine.EventSystems; public class Module_TooltipMenu : MonoBehaviour { [SerializeField] private GameObject _tooltip; [SerializeField] private GameObject buttons; [SerializeField] private GameObject button_AB; [SerializeField] private GameObject textBoard; [SerializeField] private TextMeshPro text_ButtonA; [SerializeField] private TextMeshPro text_ButtonB; [Header("Exception Objects")] [Tooltip("A list of gameobjects can't be selected when locating the point of tooltip.")] [SerializeField] private GameObject[] exceptionObjects = new GameObject[] { }; [Header("BoxCollider of ButtonA&B")] [Tooltip("Don't change these.")] [SerializeField] private BoxCollider[] boxColliders = new BoxCollider[] { }; [Header("Text of Tooltip")] [Tooltip("The texts of each tooltip.")] [SerializeField] private string[] tooltipText = new string[] { "TooltipTest", "Hello", "OK" }; private GameObject tooltip; private Modules_TooltipLineRenderer tooltipLineRenderer; private InputDevicePartType inputDevicePartType; private bool onLong = false; private bool selectState = false; private bool nextState = false; private void Start() { API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateRegister(EnterDown); API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateRegister(EnterUp); } private void Update() { if(onLong) { OnLong(); } } private void EnterDown(InputKeyCode keyCode, InputDevicePartBase part) { if (selectState&&keyCode == InputKeyCode.Enter && !onLong) { inputDevicePartType = part.PartType; onLong = true; } } private void EnterUp(InputKeyCode keyCode, InputDevicePartBase part) { if (selectState&&keyCode == InputKeyCode.Enter && part.PartType == inputDevicePartType) { onLong = false; } } private void OnLong() { if (selectState) { DefaultCursor cursor; RaycastResult raycastResult; switch (inputDevicePartType) { //忽略GC类型 case InputDevicePartType.Head: cursor = GSXR_Get_HeadCursor; raycastResult = GSXR_HeadHitInfo; break; //case InputDevicePartType.GCOne: // break; //case InputDevicePartType.GCTwo: // break; case InputDevicePartType.KSLeft: cursor = GSXR_Get_KSCursor(GCType.Left); raycastResult = GSXR_KSHitInfo(GCType.Left); break; case InputDevicePartType.KSRight: cursor = GSXR_Get_KSCursor(GCType.Right); raycastResult = GSXR_KSHitInfo(GCType.Right); break; case InputDevicePartType.HandLeft: cursor = GSXR_Get_GGTCursor(GGestureType.Left); raycastResult = GSXR_GGTHitInfo(GGestureType.Left); break; case InputDevicePartType.HandRight: cursor = GSXR_Get_GGTCursor(GGestureType.Right); raycastResult = GSXR_GGTHitInfo(GGestureType.Right); break; default: cursor = null; raycastResult = new RaycastResult(); break; } try { if (raycastResult.gameObject != exceptionObjects[0] && raycastResult.gameObject != exceptionObjects[1]) { //Debug.Log(cursor.transform.position); //Debug.Log(raycastResult.gameObject.name); tooltip.transform.SetParent(raycastResult.gameObject.transform); Vector3 location = cursor.transform.position; tooltipLineRenderer.API_SetTargetPosition(location, true); location.y += 0.1f; tooltipLineRenderer.API_SetLablePosition(location, true); } } catch// (Exception e) { //Debug.Log(e.Message); } } } private void OnDestroy() { if (selectState || nextState) { Destroy(tooltip); } API_GSXR_Module_InputSystem.GSXR_KeyDownDelegateUnRegister(EnterDown); API_GSXR_Module_InputSystem.GSXR_KeyUpDelegateUnRegister(EnterUp); } public void AddTooltip1() { AddTooltip(1); } public void AddTooltip2() { AddTooltip(2); } public void AddTooltip3() { AddTooltip(3); } private void AddTooltip(int number) { Vector3 locate = transform.position; locate.y += 0.2f; Quaternion rotation = transform.rotation; tooltip = Instantiate(_tooltip, locate, rotation); Modules_TooltipUI modules_TooltipUI; modules_TooltipUI = tooltip.GetComponent(); tooltipLineRenderer = tooltip.GetComponent(); modules_TooltipUI.API_SetLableText(tooltipText[number - 1]); buttons.SetActive(false); button_AB.SetActive(true); textBoard.SetActive(true); text_ButtonA.text = "Cancel"; selectState = true; } public void DoCancel() { if (selectState) { Destroy(tooltip); } StartCoroutine(ToDestory()); } public void DoNext() { if (nextState) { tooltip.GetComponent().MoveLableDisable(); nextState = false; StartCoroutine(ToDestory()); } else { text_ButtonB.text = "OK"; textBoard.GetComponentInChildren().text = "Please move the lable to an ideal location."; selectState = false; tooltip.GetComponent().MoveLableEnable(); nextState = true; } } private IEnumerator ToDestory() { boxColliders[0].enabled = false; boxColliders[1].enabled = false; yield return new WaitForSeconds(0.1f); Destroy(gameObject); } }