/// <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 }