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