/// <summary> /// The IsValidInteractableController method is used to check to see if a controller is allowed to perform an interaction with this object as sometimes controllers are prohibited from grabbing or using an object depedning on the use case. /// </summary> /// <param name="actualController">The game object of the controller that is being checked.</param> /// <param name="controllerCheck">The value of which controller is allowed to interact with this object.</param> /// <returns>Is true if the interacting controller is allowed to grab the object.</returns> public virtual bool IsValidInteractableController(GameObject actualController, AllowedController controllerCheck) { if (controllerCheck == AllowedController.Both) { return(true); } SDK_BaseController.ControllerHand controllerHand = VRTK_DeviceFinder.GetControllerHandType(controllerCheck.ToString().Replace("Only", "")); return(VRTK_DeviceFinder.IsControllerOfHand(actualController, controllerHand)); }
/// <summary> /// IsValidInteractableController方法由于检测一个手柄游戏对象是否被允许与当前物体交互,因为有的情况下(根据使用需求)手柄是禁止与物体交互的 /// </summary> /// <param name="actualController">接受检测的手柄游戏对象</param> /// <param name="controllerCheck">哪个手柄被允许与当前物体交互</param> /// <returns></returns> public bool IsValidInteractableController(GameObject actualController, AllowedController controllerCheck) { if (controllerCheck == AllowedController.Both) { // 如果物体被允许与任何手柄交互,那么始终返回真 return(true); } // controllerCheck.ToString().Replace("_Only", "")这句代码是把Left_Only和Right_Only里面的_Only去掉,留下Left或者Right // 然后用VRTK_DeviceFinder去找到对应的手柄 var controllerHand = VRTK_DeviceFinder.GetControllerHandType(controllerCheck.ToString().Replace("_Only", "")); // 对比,里面要依赖SteamVR_ControllerManager return(VRTK_DeviceFinder.IsControllerOfHand(actualController, controllerHand)); }