SampleRoot.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using BestHTTP.Examples.Helpers;
  6. namespace BestHTTP.Examples
  7. {
  8. public class SampleRoot : MonoBehaviour
  9. {
  10. #pragma warning disable 0649, 0169
  11. [Header("Common Properties")]
  12. public string BaseURL = "https://besthttpwebgldemo.azurewebsites.net";
  13. [Header("References")]
  14. [SerializeField]
  15. private Text _pluginVersion;
  16. [SerializeField]
  17. private Dropdown _logLevelDropdown;
  18. [SerializeField]
  19. private Text _proxyLabel;
  20. [SerializeField]
  21. private InputField _proxyInputField;
  22. #pragma warning restore
  23. [SerializeField]
  24. public List<SampleBase> samples = new List<SampleBase>();
  25. [HideInInspector]
  26. public SampleBase selectedExamplePrefab;
  27. private void Start()
  28. {
  29. Application.runInBackground = true;
  30. this._pluginVersion.text = "Version: " + HTTPManager.UserAgent;
  31. int logLevel = PlayerPrefs.GetInt("BestHTTP.HTTPManager.Logger.Level", (int)HTTPManager.Logger.Level);
  32. this._logLevelDropdown.value = logLevel;
  33. HTTPManager.Logger.Level = (BestHTTP.Logger.Loglevels)logLevel;
  34. #if (UNITY_WEBGL && !UNITY_EDITOR) || BESTHTTP_DISABLE_PROXY
  35. this._proxyLabel.gameObject.SetActive(false);
  36. this._proxyInputField.gameObject.SetActive(false);
  37. #else
  38. string proxyURL = PlayerPrefs.GetString("BestHTTP.HTTPManager.Proxy", null);
  39. if (!string.IsNullOrEmpty(proxyURL))
  40. {
  41. try
  42. {
  43. HTTPManager.Proxy = new HTTPProxy(new Uri(proxyURL), null, true);
  44. #if UNITY_2019_1_OR_NEWER
  45. this._proxyInputField.SetTextWithoutNotify(proxyURL);
  46. #else
  47. this._proxyInputField.onEndEdit.RemoveAllListeners();
  48. this._proxyInputField.text = proxyURL;
  49. this._proxyInputField.onEndEdit.AddListener(this.OnProxyEditEnd);
  50. #endif
  51. }
  52. catch
  53. { }
  54. }
  55. else
  56. HTTPManager.Proxy = null;
  57. #endif
  58. #if !BESTHTTP_DISABLE_CACHING
  59. // Remove too old cache entries.
  60. BestHTTP.Caching.HTTPCacheService.BeginMaintainence(new BestHTTP.Caching.HTTPCacheMaintananceParams(TimeSpan.FromDays(30), ulong.MaxValue));
  61. #endif
  62. }
  63. public void OnLogLevelChanged(int idx)
  64. {
  65. HTTPManager.Logger.Level = (BestHTTP.Logger.Loglevels)idx;
  66. PlayerPrefs.SetInt("BestHTTP.HTTPManager.Logger.Level", idx);
  67. }
  68. public void OnProxyEditEnd(string proxyURL)
  69. {
  70. #if (!UNITY_WEBGL || UNITY_EDITOR) && !BESTHTTP_DISABLE_PROXY
  71. try
  72. {
  73. if (string.IsNullOrEmpty(this._proxyInputField.text))
  74. HTTPManager.Proxy = null;
  75. else
  76. HTTPManager.Proxy = new HTTPProxy(new Uri(this._proxyInputField.text), null, true);
  77. PlayerPrefs.SetString("BestHTTP.HTTPManager.Proxy", this._proxyInputField.text);
  78. }
  79. catch
  80. { }
  81. #endif
  82. }
  83. }
  84. }