Files
PrinceOfGlory/Assets/Scripts/Help/SetHandRay.cs
kridoo 6e91a0c7f0 111
2025-09-15 17:32:08 +08:00

80 lines
2.3 KiB
C#

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.XR.Interaction.Toolkit;
using BigSpace.Logic;
using BigSpace.XRCore.Event;
public class SetHandRay : MonoBehaviour
{
public GameObject LeftRya;
public GameObject RigthRay;
XRRayInteractor xRRayInteractor_Left;
LineRenderer lineRenderer_Left;
XRInteractorLineVisual xRInteractorLineVisual_Left;
SortingGroup sortingGroup_Left;
XRRayInteractor xRRayInteractor_Right;
LineRenderer lineRenderer_Right;
XRInteractorLineVisual xRInteractorLineVisual_Right;
SortingGroup sortingGroup_Right;
// Start is called before the first frame update
void Start()
{
xRRayInteractor_Left = LeftRya.GetComponent<XRRayInteractor>();
lineRenderer_Left = LeftRya.GetComponent<LineRenderer>();
xRInteractorLineVisual_Left = LeftRya.GetComponent<XRInteractorLineVisual>();
sortingGroup_Left = LeftRya.GetComponent<SortingGroup>();
xRRayInteractor_Right = RigthRay.GetComponent<XRRayInteractor>();
lineRenderer_Right = RigthRay.GetComponent<LineRenderer>();
xRInteractorLineVisual_Right = RigthRay.GetComponent<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;
}
}