Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniWebViewHelper.cs 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // UniWebViewHelper.cs
  3. // Created by Wang Wei(@onevcat) on 2017-04-11.
  4. //
  5. // This file is a part of UniWebView Project (https://uniwebview.com)
  6. // By purchasing the asset, you are allowed to use this code in as many as projects
  7. // you want, only if you publish the final products under the name of the same account
  8. // used for the purchase.
  9. //
  10. // This asset and all corresponding files (such as source code) are provided on an
  11. // “as is” basis, without warranty of any kind, express of implied, including but not
  12. // limited to the warranties of merchantability, fitness for a particular purpose, and
  13. // noninfringement. In no event shall the authors or copyright holders be liable for any
  14. // claim, damages or other liability, whether in action of contract, tort or otherwise,
  15. // arising from, out of or in connection with the software or the use of other dealing in the software.
  16. //
  17. using UnityEngine;
  18. using System.IO;
  19. /// <summary>
  20. /// Provides some helper utility methods for UniWebView.
  21. /// </summary>
  22. public class UniWebViewHelper {
  23. /// <summary>
  24. /// Get the local streaming asset path for a given file path related to the StreamingAssets folder.
  25. ///
  26. /// This method will help you to create a URL string for a file under your StreamingAssets folder for different platforms.
  27. /// <param name="path">The relative path to the Assets/StreamingAssets of your file.
  28. /// For example, if you placed a html file under Assets/StreamingAssets/www/index.html, you should pass `www/index.html` as parameter.
  29. /// </param>
  30. /// <returns>The path you could use as the url for the web view.</returns>
  31. public static string StreamingAssetURLForPath(string path)
  32. {
  33. #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  34. return Path.Combine("file://" + Application.streamingAssetsPath, path);
  35. #elif UNITY_ANDROID && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX
  36. return Path.Combine("file:///android_asset/", path);
  37. #else
  38. UniWebViewLogger.Instance.Critical("The current build target is not supported.");
  39. return string.Empty;
  40. #endif
  41. }
  42. /// <summary>
  43. /// Get the local persistent data path for a given file path related to the data folder of your host app.
  44. ///
  45. /// This method will help you to create a URL string for a file under you stored in the `persistentDataPath`.
  46. /// </summary>
  47. /// <param name="path">
  48. /// The relative path to the persistent data path of your file.
  49. /// </param>
  50. /// <returns>The path you could use as the url for the web view.</returns>
  51. public static string PersistentDataURLForPath(string path)
  52. {
  53. return Path.Combine("file://" + Application.persistentDataPath, path);
  54. }
  55. internal static bool IsEditor {
  56. get {
  57. #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
  58. return true;
  59. #else
  60. return false;
  61. #endif
  62. }
  63. }
  64. }