Files
PrinceOfGlory/Assets/Scripts/Help/SetHandRay.cs
2026-03-02 17:56:21 +08:00

80 lines
2.7 KiB
C#

using UnityEngine;
using UnityEngine.Rendering;
using BigSpace.Logic;
using BigSpace.XRCore.Event;
public class SetHandRay : MonoBehaviour
{
public GameObject LeftRya;
public GameObject RigthRay;
UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor xRRayInteractor_Left;
LineRenderer lineRenderer_Left;
UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals.XRInteractorLineVisual xRInteractorLineVisual_Left;
SortingGroup sortingGroup_Left;
UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor xRRayInteractor_Right;
LineRenderer lineRenderer_Right;
UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals.XRInteractorLineVisual xRInteractorLineVisual_Right;
SortingGroup sortingGroup_Right;
// Start is called before the first frame update
void Start()
{
xRRayInteractor_Left = LeftRya.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor>();
lineRenderer_Left = LeftRya.GetComponent<LineRenderer>();
xRInteractorLineVisual_Left = LeftRya.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals.XRInteractorLineVisual>();
sortingGroup_Left = LeftRya.GetComponent<SortingGroup>();
xRRayInteractor_Right = RigthRay.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.XRRayInteractor>();
lineRenderer_Right = RigthRay.GetComponent<LineRenderer>();
xRInteractorLineVisual_Right = RigthRay.GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals.XRInteractorLineVisual>();
sortingGroup_Right = RigthRay.GetComponent<SortingGroup>();
GlobalEventMgr.Listen<bool>(GameEvent.EventSetHandRay, GameDataManage_EventSetHandRay);
}
void GameDataManage_EventSetHandRay(bool isShow)
{
if (isShow)
{
ShowHandRay();
}
else
{
HideHandRay();
}
}
void HideHandRay()
{
xRRayInteractor_Left.enabled = false;
lineRenderer_Left.enabled = false;
xRInteractorLineVisual_Left.enabled = false;
sortingGroup_Left.enabled = false;
xRRayInteractor_Right.enabled = false;
lineRenderer_Right.enabled = false;
xRInteractorLineVisual_Right.enabled = false;
sortingGroup_Right.enabled = false;
}
void ShowHandRay()
{
xRRayInteractor_Left.enabled = true;
lineRenderer_Left.enabled = true;
xRInteractorLineVisual_Left.enabled = true;
sortingGroup_Left.enabled = true;
xRRayInteractor_Right.enabled = true;
lineRenderer_Right.enabled = true;
xRInteractorLineVisual_Right.enabled = true;
sortingGroup_Right.enabled = true;
}
}