iOSWebPlugin.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_IOS && !UNITY_EDITOR
  17. using System;
  18. using UnityEngine;
  19. namespace Vuplex.WebView {
  20. class iOSWebPlugin : IWebPlugin, IPluginWithTouchScreenKeyboard {
  21. public static iOSWebPlugin Instance {
  22. get {
  23. if (_instance == null) {
  24. _instance = new iOSWebPlugin();
  25. }
  26. return _instance;
  27. }
  28. }
  29. public WebPluginType Type {
  30. get {
  31. return WebPluginType.iOS;
  32. }
  33. }
  34. public void ClearAllData() {
  35. iOSWebView.ClearAllData();
  36. }
  37. public void CreateTexture(float width, float height, Action<Texture2D> callback) {
  38. iOSWebView.CreateTexture(width, height, callback);
  39. }
  40. public void CreateMaterial(Action<Material> callback) {
  41. CreateTexture(1, 1, texture => {
  42. Material material = null;
  43. Shader shader = ResourceMgr.Instance.FindShader("Vuplex/Viewport Shader", "Assets/Shaders/WebView/Common/ViewportShader");
  44. if (shader)
  45. {
  46. material = new Material(shader);
  47. material.mainTexture = texture;
  48. material.renderQueue = 3000;
  49. }
  50. callback(material);
  51. });
  52. }
  53. public void CreateVideoMaterial(Action<Material> callback) {
  54. CreateTexture(1, 1, texture => {
  55. Material material = null;
  56. Shader shader = ResourceMgr.Instance.FindShader("Vuplex/Viewport Shader", "Assets/Shaders/WebView/Common/ViewportShader");
  57. if (shader)
  58. {
  59. material = new Material(shader);
  60. material.mainTexture = texture;
  61. material.EnableKeyword("FLIP_Y");
  62. material.SetFloat("_FlipY", 1);
  63. material.renderQueue = 2999;
  64. }
  65. callback(material);
  66. });
  67. }
  68. public virtual IWebView CreateWebView() {
  69. return iOSWebView.Instantiate();
  70. }
  71. public void EnableRemoteDebugging() {
  72. WebViewLogger.Log("Remote debugging is enabled for iOS. For instructions, please see https://support.vuplex.com/articles/how-to-debug-web-content#ios.");
  73. }
  74. public void SetIgnoreCertificateErrors(bool ignore) {
  75. iOSWebView.SetIgnoreCertificateErrors(ignore);
  76. }
  77. public void SetStorageEnabled(bool enabled) {
  78. iOSWebView.SetStorageEnabled(enabled);
  79. }
  80. /// <see cref="IPluginWithTouchScreenKeyboard"/>
  81. public void SetTouchScreenKeyboardEnabled(bool enabled) {
  82. iOSWebView.SetTouchScreenKeyboardEnabled(enabled);
  83. }
  84. public void SetUserAgent(bool mobile) {
  85. iOSWebView.GloballySetUserAgent(mobile);
  86. }
  87. public void SetUserAgent(string userAgent) {
  88. iOSWebView.GloballySetUserAgent(userAgent);
  89. }
  90. static iOSWebPlugin _instance;
  91. }
  92. }
  93. #endif