XritPointerEventHelper.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2024 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if VUPLEX_XR_INTERACTION_TOOLKIT
  15. using UnityEngine;
  16. using UnityEngine.EventSystems;
  17. namespace Vuplex.WebView.Internal {
  18. class XritPointerEventHelper : MonoBehaviour {
  19. public PointerEventData LastPointerEventData { get; private set; }
  20. public static XritPointerEventHelper Instance {
  21. get {
  22. if (_instance == null) {
  23. _instance = new GameObject("WebView XR Pointer Event Helper").AddComponent<XritPointerEventHelper>();
  24. DontDestroyOnLoad(_instance.gameObject);
  25. }
  26. return _instance;
  27. }
  28. }
  29. static XritPointerEventHelper _instance;
  30. void Start() {
  31. var uiInputModule = EventSystem.current.currentInputModule as UnityEngine.XR.Interaction.Toolkit.UI.UIInputModule;
  32. if (uiInputModule == null) {
  33. WebViewLogger.LogWarning("The scene's input module is not an XR Interaction Toolkit UIInputModule, so hovering will not be enabled.");
  34. return;
  35. }
  36. uiInputModule.finalizeRaycastResults += (eventData, _) => LastPointerEventData = eventData;
  37. }
  38. }
  39. }
  40. #endif