From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../UniWebView/Script/Helper/UniWebViewHelper.cs | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs (limited to 'Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs') diff --git a/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs new file mode 100644 index 00000000..17e810b1 --- /dev/null +++ b/Client/Assets/Scripts/UniWebView/Script/Helper/UniWebViewHelper.cs @@ -0,0 +1,91 @@ +using UnityEngine; + +/// +/// Supply some helper utility method for UniWebView +/// +public class UniWebViewHelper{ + /// + /// Get the height of the screen. + /// + /// + /// The height of screen. + /// + /// + /// In iOS devices, it will always return the screen height in "point", + /// instead of "pixel". It would be useful to use this value to calculate webview size. + /// On other platforms, it will just return Unity's Screen.height. + /// For example, a portrait iPhone 5 will return 568 and a landscape one 320. You should + /// always use this value to do screen-size-based insets calculation. + /// + public static int screenHeight { + get { +#if UNITY_IOS && !UNITY_EDITOR + return UniWebViewPlugin.ScreenHeight(); +#else + return Screen.height; +#endif + } + } + + /// + /// Get the height of the screen. + /// + /// + /// The height of screen. + /// + /// + /// In iOS devices, it will always return the screen width in "point", + /// instead of "pixel". It would be useful to use this value to calculate webview size. + /// On other platforms, it will just return Unity's Screen.height. + /// For example, a portrait iPhone 5 will return 320 and a landscape one 568. You should + /// always use this value to do screen-size-based insets calculation. + /// + public static int screenWidth { + get { +#if UNITY_IOS && !UNITY_EDITOR + return UniWebViewPlugin.ScreenWidth(); +#else + return Screen.width; +#endif + } + } + + /// + /// Get the screen scale. In iOS or OS X Editor, it could be 1, 2 or 3 now, depending on the type of your screen. + /// + /// The screen scale. + public static int screenScale { + get { +#if UNITY_IOS || UNITY_EDITOR + return UniWebViewPlugin.ScreenScale(); +#else + return 1; +#endif + } + } + + /// + /// Get the local streaming asset path for a given file path related to the StreamingAssets folder. + /// + /// + /// This method will help you to concat a URL string for a file under your StreamingAssets folder for different platforms. + /// + /// The relative path to the Assets/StreamingAssets of your file. + /// For example, if you placed a html file under Assets/StreamingAssets/www/index.html, you should pass `www/demo.html` as parameter. + /// + /// The path you could use as the url for the web view. + public static string streamingAssetURLForPath(string path) + { +#if UNITY_EDITOR + return Application.streamingAssetsPath + "/" + path; +#elif UNITY_IOS + return Application.streamingAssetsPath + "/" + path; +#elif UNITY_ANDROID + return "file:///android_asset/" + path; +#elif UNITY_WP8 + return "Data/StreamingAssets/" + path; +#else + return string.Empty; +#endif + } +} -- cgit v1.1-26-g67d0