using SC.XR.Unity; using SC.XR.Unity.Module_InputSystem; using SC.XR.Unity.Module_InputSystem.InputDeviceGC; using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS; using TMPro; using UnityEngine; using UnityEngine.UI; using static API_GSXR_Module_InputSystem_KS; using static API_GSXR_Slam; public class ControllerManager : MonoBehaviour { string L_controllerType; string R_controllerType; public Transform leftController; public Transform rightController; public GameObject leftImg; public GameObject rightImg; protected bool reset_state; Transform R_Controller; Transform L_Controller; // Start is called before the first frame update void Start() { InputDeviceGCPartEventBase.eventDelegate += ControllerEvent; reset_state = true; } // Update is called once per frame void Update() { } void ControllerEvent(GCEventType aEvent, InputDeviceGCPart GCPart) { if (GCPart.PartType == InputDevicePartType.KSLeft) { if (aEvent == GCEventType.Connect) { L_controllerType = GCPart.inputDataGC.GCName; if (L_controllerType == "Nolo") { InitControllerPanel("NoloController",0); } else if (L_controllerType == "K102") { InitControllerPanel("K102Controller", 0); } else if (L_controllerType == "Luci") { InitControllerPanel("K102Controller", 0); } } else if (aEvent == GCEventType.DisConnect) { L_controllerType = "null"; foreach (Transform child in leftController) { Destroy(child.gameObject); } leftImg.SetActive(false); } } if (GCPart.PartType == InputDevicePartType.KSRight) { if (aEvent == GCEventType.Connect) { R_controllerType = GCPart.inputDataGC.GCName; if (R_controllerType == "Nolo") { InitControllerPanel("NoloController", 1); } else if (R_controllerType == "K102") { InitControllerPanel("K102Controller", 1); } else if (R_controllerType == "Luci") { InitControllerPanel("K102Controller", 1); } } else if (aEvent == GCEventType.DisConnect) { R_controllerType = "null"; foreach (Transform child in rightController) { Destroy(child.gameObject); } rightImg.SetActive(false); } } } protected void InitControllerPanel(string prefabName,int index) { if (index==1) { if (rightController.GetComponentsInChildren().Length >=1) { return; } R_Controller = Instantiate(Resources.Load("prefabs/"+ prefabName)).transform; R_Controller.transform.parent = rightController; R_Controller.transform.localPosition = Vector3.zero; R_Controller.transform.localEulerAngles = Vector3.zero; R_Controller.transform.localScale = Vector3.one; rightImg.SetActive(true); R_Controller.GetComponent().is_Left = false; } else if (index == 0) { if (leftController.GetComponentsInChildren().Length >= 1) { return; } L_Controller = Instantiate(Resources.Load("prefabs/" + prefabName)).transform; L_Controller.parent = leftController; L_Controller.localPosition = Vector3.zero; L_Controller.localEulerAngles = Vector3.zero; L_Controller.localScale = Vector3.one; leftImg.SetActive(true); L_Controller.GetComponent().is_Left = true; } } private void OnDestroy() { InputDeviceGCPartEventBase.eventDelegate -= ControllerEvent; } }