WWebViewSystem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace ICODES.STUDIO.WWebView
  5. {
  6. public sealed class WWebViewSystem : MonoBehaviour
  7. {
  8. public void Initialize()
  9. {
  10. this.InitializeWinPlayer();
  11. }
  12. private void InitializeWinPlayer()
  13. {
  14. WWebViewWin32.ModifyStyle(WWebViewWin32.FindUnityPlayerWindow(), 0L, 33554432L, 0U);
  15. WWebViewWin32.SubclassWindow();
  16. base.StartCoroutine("DispatchMessage");
  17. }
  18. private IEnumerator DispatchMessage()
  19. {
  20. for (;;)
  21. {
  22. yield return new WaitForFixedUpdate();
  23. WWebViewWin32.DispatchMessage();
  24. }
  25. yield break;
  26. }
  27. public bool HoloLensVR
  28. {
  29. get
  30. {
  31. return false;
  32. }
  33. }
  34. private void OnDestroy()
  35. {
  36. WWebViewSystem.instance = null;
  37. }
  38. private void OnApplicationQuit()
  39. {
  40. WWebViewPlugin.Release();
  41. }
  42. public static string EscapeJsonText(string data)
  43. {
  44. return data.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("/", "\\/");
  45. }
  46. public static WWebViewSystem Instance
  47. {
  48. get
  49. {
  50. if (WWebViewSystem.instance == null)
  51. {
  52. WWebViewSystem.instance = (UnityEngine.Object.FindObjectOfType(typeof(WWebViewSystem)) as WWebViewSystem);
  53. if (WWebViewSystem.instance == null)
  54. {
  55. GameObject gameObject = new GameObject("WWebViewSystem");
  56. UnityEngine.Object.DontDestroyOnLoad(gameObject);
  57. WWebViewSystem.instance = gameObject.AddComponent<WWebViewSystem>();
  58. }
  59. }
  60. return WWebViewSystem.instance;
  61. }
  62. }
  63. private static WWebViewSystem instance;
  64. }
  65. }