MacWebView.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2022 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 (UNITY_STANDALONE_OSX && !UNITY_EDITOR) || UNITY_EDITOR_OSX
  15. using System;
  16. using System.Runtime.InteropServices;
  17. using UnityEngine;
  18. using Vuplex.WebView.Internal;
  19. namespace Vuplex.WebView {
  20. /// <summary>
  21. /// The macOS IWebView implementation.
  22. /// </summary>
  23. public class MacWebView : StandaloneWebView, IWebView {
  24. public WebPluginType PluginType { get; } = WebPluginType.Mac;
  25. public static MacWebView Instantiate() => new GameObject().AddComponent<MacWebView>();
  26. public static bool ValidateGraphicsApi() {
  27. var isValid = SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal;
  28. if (!isValid) {
  29. var message = "Unsupported graphics API: 3D WebView for macOS requires Metal.";
  30. if (Application.isEditor) {
  31. message += " Please go to Player Settings and enable \"Metal Editor Support\".";
  32. }
  33. WebViewLogger.LogError(message);
  34. }
  35. return isValid;
  36. }
  37. protected override StandaloneWebView _instantiate() => Instantiate();
  38. }
  39. }
  40. #endif