/// <summary> /// Creates a GameObject that represents the left or right device controllers. /// These are the "VR hands". /// </summary> /// <param name="role">The controller device role (left or right).</param> /// <returns>The GameObject for the "VR hand".</returns> protected GameObject CreateManipulator(ETrackedControllerRole role) { // create new GameObject GameObject manipulator = new GameObject("KVR_Manipulator"); DontDestroyOnLoad(manipulator); // define the Manipulator component Manipulator manipulatorComponent = manipulator.AddComponent <Manipulator>(); manipulatorComponent.SetRole(role); return(manipulator); }
/// <summary> /// Creates a GameObject that represents the left or right device controllers. /// These are the "VR hands". /// </summary> /// <param name="role">The controller device role (left or right).</param> /// <returns>The GameObject for the "VR hand".</returns> protected GameObject CreateManipulator(ETrackedControllerRole role) { // create new GameObject GameObject manipulator = new GameObject("KVR_Manipulator_" + role.ToString()); DontDestroyOnLoad(manipulator); // define the Manipulator component Manipulator manipulatorComponent = manipulator.AddComponent <Manipulator>(); manipulatorComponent.role = role; #if DEBUG GameObject manipulatorGizmo = Utils.CreateGizmo(); manipulatorGizmo.transform.SetParent(manipulator.transform); manipulatorGizmo.transform.localPosition = Vector3.zero; manipulatorGizmo.transform.localRotation = Quaternion.identity; manipulatorGizmo.transform.localScale = Vector3.one * 0.5f; #endif return(manipulator); }
private GameObject CreateManipulator(ETrackedControllerRole role) { // create new GameObject GameObject manipulator = GameObject.CreatePrimitive(PrimitiveType.Sphere); manipulator.name = "VR_Manipulator_" + role.ToString(); DontDestroyOnLoad(manipulator); // define the render model manipulator.transform.localScale = Vector3.one * ((role == ETrackedControllerRole.RightHand) ? 0.02f : 0.08f); Color manipulatorColor = (role == ETrackedControllerRole.RightHand) ? Color.green : Color.red; MeshRenderer manipulatorRenderer = manipulator.GetComponent <MeshRenderer>(); manipulatorRenderer.material.color = manipulatorColor; // define the collider Rigidbody manipulatorRigidbody = manipulator.AddComponent <Rigidbody>(); manipulatorRigidbody.isKinematic = true; SphereCollider manipulatorCollider = manipulator.GetComponent <SphereCollider>(); manipulatorCollider.isTrigger = true; // define the Manipulator component Manipulator manipulatorComponent = manipulator.AddComponent <Manipulator>(); manipulatorComponent.role = role; manipulatorComponent.originalColor = manipulatorColor; manipulatorComponent.activeColor = Color.yellow; #if DEBUG manipulatorRenderer.enabled = true; #else manipulatorRenderer.enabled = false; #endif return(manipulator); }
/// <summary> /// Checks whether the given Manipulator component is the right Manipulator. /// </summary> /// <param name="obj">The Manipulator component to check.</param> /// <returns>True if this is the right Manipulator, false otherwise.</returns> public static bool IsManipulatorRight(Manipulator obj) { return(Instance.ManipulatorRight != null && obj == Instance.ManipulatorRight); }
/// <summary> /// Creates a GameObject that represents the left or right device controllers. /// These are the "VR hands". /// </summary> /// <param name="role">The controller device role (left or right).</param> /// <returns>The GameObject for the "VR hand".</returns> protected GameObject CreateManipulator(ETrackedControllerRole role) { // create new GameObject GameObject manipulator = new GameObject("KVR_Manipulator_" + role.ToString()); DontDestroyOnLoad(manipulator); // define the render model GameObject glovePrefab = AssetLoader.Instance.GetGameObject("GlovePrefab"); if (glovePrefab == null) { Utils.LogError("GameObject \"GlovePrefab\" was not found!"); return(manipulator); } GameObject gloveObject = Instantiate(glovePrefab); gloveObject.transform.SetParent(manipulator.transform); Vector3 gloveObjectScale = Vector3.one * ManipulatorSize; if (role == ETrackedControllerRole.RightHand) { gloveObjectScale.y *= -1f; } gloveObject.transform.localPosition = GLOVE_POSITION; gloveObject.transform.localRotation = Quaternion.Euler(GLOVE_ROTATION); gloveObject.transform.localScale = gloveObjectScale; Utils.SetLayer(gloveObject, 20); // define the colliders Transform colliderObject = gloveObject.transform.Find("HandDummy/Arm Bone L/Wrist Bone L/Finger Index Bone L1/Finger Index Bone L2/Finger Index Bone L3/Finger Index Bone L4"); if (colliderObject == null) { Utils.LogWarning("Manipulator is missing fingertip collider child object"); return(manipulator); } SphereCollider fingertipCollider = colliderObject.GetComponent <SphereCollider>(); colliderObject = gloveObject.transform.Find("HandDummy/Arm Bone L/Wrist Bone L"); if (colliderObject == null) { Utils.LogWarning("Manipulator is missing grip collider child object"); return(manipulator); } CapsuleCollider gripCollider = colliderObject.GetComponent <CapsuleCollider>(); // retrieve the animator Animator manipulatorAnimator = gloveObject.GetComponent <Animator>(); // define the Manipulator component Manipulator manipulatorComponent = manipulator.AddComponent <Manipulator>(); manipulatorComponent.role = role; manipulatorComponent.fingertipCollider = fingertipCollider; manipulatorComponent.gripCollider = gripCollider; manipulatorComponent.manipulatorAnimator = manipulatorAnimator; #if DEBUG GameObject manipulatorGizmo = Utils.CreateGizmo(); manipulatorGizmo.transform.SetParent(manipulator.transform); manipulatorGizmo.transform.localPosition = Vector3.zero; manipulatorGizmo.transform.localRotation = Quaternion.identity; manipulatorGizmo.transform.localScale = Vector3.one * 0.5f; #endif return(manipulator); }