IWithNative2DMode.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 System.Threading.Tasks;
  15. using UnityEngine;
  16. namespace Vuplex.WebView {
  17. /// <summary>
  18. /// An interface implemented by a webview if it supports Native 2D Mode, which makes it
  19. /// so that 3D WebView positions a native 2D webview in front of the Unity game view instead
  20. /// of displaying web content as a texture in the Unity scene.
  21. /// For more info, please see [this article](https://support.vuplex.com/articles/native-2d-mode).
  22. /// </summary>
  23. /// <seealso cref="CanvasWebViewPrefab.Native2DModeEnabled"/>
  24. public interface IWithNative2DMode {
  25. /// <summary>
  26. /// Gets a value indicating whether the webview is running in Native 2D Mode.
  27. /// </summary>
  28. /// <seealso cref="CanvasWebViewPrefab.Native2DModeEnabled"/>
  29. /// <example>
  30. /// <code>
  31. /// await canvasWebViewPrefab.WaitUntilInitialized();
  32. /// var native2DWebView = canvasWebViewPrefab.WebView as IWithNative2DMode;
  33. /// Debug.Log("Native 2D Mode enabled: " + native2DWebView?.Native2DModeEnabled);
  34. /// </code>
  35. /// </example>
  36. bool Native2DModeEnabled { get; }
  37. /// <summary>
  38. /// Gets the native 2D webview's rect on the screen, in pixels.
  39. /// </summary>
  40. /// <seealso cref="IWithNative2DMode.SetRect"/>
  41. Rect Rect { get; }
  42. /// <summary>
  43. /// Gets a value indicating whether the native 2D webview is visible.
  44. /// The default is `true`.
  45. /// </summary>
  46. /// <seealso cref="CanvasWebViewPrefab.Visible"/>
  47. /// <seealso cref="IWithNative2DMode.SetVisible"/>
  48. bool Visible { get; }
  49. /// <summary>
  50. /// Brings the native webview to the front of the view hierarchy.
  51. /// A webview is automatically placed in the front when it's created,
  52. /// but this method can be used to control which webview is in front
  53. /// if your scene contains multiple 2D webviews.
  54. /// </summary>
  55. /// <remarks>
  56. /// This method is currently not supported on UWP.
  57. /// </remarks>
  58. /// <example>
  59. /// <code>
  60. /// await canvasWebViewPrefab.WaitUntilInitialized();
  61. /// var native2DWebView = canvasWebViewPrefab.WebView as IWithNative2DMode;
  62. /// native2DWebView?.BringToFront();
  63. /// </code>
  64. /// </example>
  65. void BringToFront();
  66. /// <summary>
  67. /// Initializes the webview in Native 2D Mode. This method is to be used instead
  68. /// of IWebView.Init() for initialization.
  69. /// </summary>
  70. Task InitInNative2DMode(Rect rect);
  71. /// <summary>
  72. /// Sets whether the native 2D webview's pinch-to-zoom behavior
  73. /// is enabled. The default is `true`.
  74. /// </summary>
  75. /// <example>
  76. /// <code>
  77. /// await canvasWebViewPrefab.WaitUntilInitialized();
  78. /// var native2DWebView = canvasWebViewPrefab.WebView as IWithNative2DMode;
  79. /// native2DWebView?.SetNativeZoomEnabled(false);
  80. /// </code>
  81. /// </example>
  82. void SetNativeZoomEnabled(bool enabled);
  83. /// <summary>
  84. /// Sets the native 2D webview's rect on the screen, in pixels.
  85. /// </summary>
  86. /// <seealso cref="IWithNative2DMode.Rect"/>
  87. void SetRect(Rect rect);
  88. /// <summary>
  89. /// Sets whether the native 2D webview is visible.
  90. /// </summary>
  91. /// <seealso cref="CanvasWebViewPrefab.Visible"/>
  92. /// <seealso cref="IWithNative2DMode.Visible"/>
  93. void SetVisible(bool visible);
  94. }
  95. }