MacWebView.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright (c) 2021 Vuplex Inc. All rights reserved.
  3. *
  4. * Licensed under the Vuplex Commercial Software Library License, you may
  5. * not use this file except in compliance with the License. You may obtain
  6. * a copy of the License at
  7. *
  8. * https://vuplex.com/commercial-library-license
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #if (UNITY_STANDALONE_OSX && !UNITY_EDITOR) || UNITY_EDITOR_OSX
  17. using System;
  18. using System.Runtime.InteropServices;
  19. using UnityEngine;
  20. namespace Vuplex.WebView {
  21. /// <summary>
  22. /// The macOS `IWebView` implementation.
  23. /// </summary>
  24. public class MacWebView : StandaloneWebView, IWebView {
  25. public WebPluginType PluginType {
  26. get {
  27. return WebPluginType.Mac;
  28. }
  29. }
  30. public static MacWebView Instantiate() {
  31. return (MacWebView) new GameObject().AddComponent<MacWebView>();
  32. }
  33. public static bool ValidateGraphicsApi() {
  34. var isValid = SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal;
  35. if (!isValid) {
  36. var message = "Unsupported graphics API: 3D WebView for macOS requires Metal.";
  37. if (Application.isEditor) {
  38. message += " Please go to Player Settings and enable \"Metal Editor Support\".";
  39. }
  40. WebViewLogger.LogError(message);
  41. }
  42. return isValid;
  43. }
  44. protected override StandaloneWebView _instantiate() {
  45. return Instantiate();
  46. }
  47. [DllImport (_dllName)]
  48. static extern void WebView_executeJavaScript(IntPtr webViewPtr, string javaScript, string resultCallbackId);
  49. }
  50. }
  51. #endif