/// <summary> /// Look if the controller was already loaded. This could happen if the /// GameObject was instantiated at runtime and the model loaded event has already fired. /// </summary> private void CheckModelAlreadyLoaded() { if (!MotionControllerVisualizer.ConfirmInitialized()) { // The motion controller visualizer singleton could not be found. return; } #if UNITY_WSA && UNITY_2017_2_OR_NEWER MotionControllerInfo newController; if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out newController)) { AddControllerTransform(newController); } #endif }
protected virtual void OnEnable() { #if UNITY_WSA && UNITY_2017_2_OR_NEWER if (!MotionControllerVisualizer.ConfirmInitialized()) { // The motion controller visualizer singleton could not be found. return; } if (started) { CheckModelAlreadyLoaded(); } MotionControllerVisualizer.Instance.OnControllerModelLoaded += AddControllerTransform; MotionControllerVisualizer.Instance.OnControllerModelUnloaded += RemoveControllerTransform; #endif }
protected virtual void OnEnable() { #if UNITY_WSA && UNITY_2017_2_OR_NEWER if (!MotionControllerVisualizer.ConfirmInitialized()) { // The motion controller visualizer singleton could not be found. return; } #endif // Look if the controller has loaded. RefreshControllerTransform(); #if UNITY_WSA && UNITY_2017_2_OR_NEWER MotionControllerVisualizer.Instance.OnControllerModelLoaded += AddControllerTransform; MotionControllerVisualizer.Instance.OnControllerModelUnloaded += RemoveControllerTransform; #endif }
/// <summary> /// Looks to see if the controller model already exists and registers it if so. /// </summary> protected virtual void TryAndAddControllerTransform() { #if UNITY_WSA && UNITY_2017_2_OR_NEWER // Look if the controller was already loaded. This could happen if the // GameObject was instantiated at runtime and the model loaded event has already fired. if (!MotionControllerVisualizer.ConfirmInitialized()) { // The motion controller visualizer singleton could not be found. return; } MotionControllerInfo newController; if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out newController)) { AddControllerTransform(newController); } #endif }
/// <summary> /// Iterates through the Transform array to find specifically named GameObjects. /// These GameObjects specify the animation bounds and the GameObject to modify for button, /// thumbstick, and touchpad animation. /// </summary> /// <param name="childTransforms">The transforms of the glTF model.</param> /// <param name="visualizerScript">The script containing references to any objects to spawn.</param> public void LoadInfo(Transform[] childTransforms, MotionControllerVisualizer visualizerScript) { foreach (Transform child in childTransforms) { // Animation bounds are named in two pairs: // pressed/unpressed and min/max. There is also a value // transform, which is the transform to modify to // animate the interactions. We also look for the // touch transform, in order to spawn the touchpadTouched // visualizer. switch (child.name.ToLower()) { case "pressed": switch (child.parent.name.ToLower()) { case "home": homePressed = child; break; case "menu": menuPressed = child; break; case "grasp": graspPressed = child; break; case "select": selectPressed = child; break; case "thumbstick_press": thumbstickPressed = child; break; case "touchpad_press": touchpadPressed = child; break; } break; case "unpressed": switch (child.parent.name.ToLower()) { case "home": homeUnpressed = child; break; case "menu": menuUnpressed = child; break; case "grasp": graspUnpressed = child; break; case "select": selectUnpressed = child; break; case "thumbstick_press": thumbstickUnpressed = child; break; case "touchpad_press": touchpadUnpressed = child; break; } break; case "min": switch (child.parent.name.ToLower()) { case "thumbstick_x": thumbstickXMin = child; break; case "thumbstick_y": thumbstickYMin = child; break; case "touchpad_touch_x": touchpadTouchXMin = child; break; case "touchpad_touch_y": touchpadTouchYMin = child; break; } break; case "max": switch (child.parent.name.ToLower()) { case "thumbstick_x": thumbstickXMax = child; break; case "thumbstick_y": thumbstickYMax = child; break; case "touchpad_touch_x": touchpadTouchXMax = child; break; case "touchpad_touch_y": touchpadTouchYMax = child; break; } break; case "value": switch (child.parent.name.ToLower()) { case "home": home = child.gameObject; break; case "menu": menu = child.gameObject; break; case "grasp": grasp = child.gameObject; break; case "select": select = child.gameObject; break; case "thumbstick_press": thumbstickPress = child.gameObject; break; case "thumbstick_x": thumbstickX = child.gameObject; break; case "thumbstick_y": thumbstickY = child.gameObject; break; case "touchpad_press": touchpadPress = child.gameObject; break; case "touchpad_touch_x": touchpadTouchX = child.gameObject; break; case "touchpad_touch_y": touchpadTouchY = child.gameObject; break; } break; case "touch": touchpadTouchVisualizer = visualizerScript.SpawnTouchpadVisualizer(child); break; } } }