WebGLWebPluginRegistrant.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. using UnityEngine;
  15. namespace Vuplex.WebView.Internal {
  16. /// <summary>
  17. /// Registers the WebGL web plugin.
  18. /// </summary>
  19. /// <remarks>
  20. /// There's a weird Unity bug where a method decorated with `RuntimeInitializeOnLoadMethod`
  21. /// isn't called on if it's nested within a block that's conditionally included
  22. /// using the `UNITY_EDITOR` directive, which the WebGLWebPlugin class uses.
  23. /// This class works around that issue by using the `UNITY_EDITOR` directive *inside*
  24. /// the method instead of outside.
  25. /// </remarks>
  26. class WebGLWebPluginRegistrant {
  27. [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  28. static void _registerPlugin() {
  29. #if UNITY_WEBGL
  30. #if UNITY_EDITOR
  31. // Register the mock in the Editor so that WebPluginFactory knows the package is installed.
  32. var plugin = MockWebPlugin.Instance;
  33. #else
  34. var plugin = WebGLWebPlugin.Instance;
  35. #endif
  36. WebPluginFactory.RegisterWebGLPlugin(plugin);
  37. #endif
  38. }
  39. }
  40. }