暂存
This commit is contained in:
1 parent
558fb16160
commit
f92b623349
14 files changed
+696
-597
No files matched your search
@@ -29,19 +29,18 @@ namespace Assets.Scripts.Apis
|
||||
}
|
||||
//protected static EasyHttp.Http.HttpClient http;
|
||||
private static System.Net.Http.HttpClient httpClient;
|
||||
private static HttpClientHandler httpClientHandler;
|
||||
private static PfHttpClientHandler httpClientHandler;
|
||||
static ApiBase()
|
||||
{
|
||||
//http = new EasyHttp.Http.HttpClient();
|
||||
//http.Request.PersistCookies = true;
|
||||
|
||||
httpClientHandler = new HttpClientHandler();
|
||||
httpClientHandler = new PfHttpClientHandler();
|
||||
httpClientHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
httpClientHandler.Proxy = WebRequest.GetSystemWebProxy();
|
||||
httpClientHandler.CookieContainer = _cookieCollection;
|
||||
httpClientHandler.UseCookies = true;
|
||||
//httpClientHandler.CookieContainer.Add(new Uri(ConfigHelper.Host), new Cookie("PowerFun.AUTH", "E1F130A03C0C2F01DF465A17AAA4740E9C44FC5F7C5077AF5A09B5ED29F0CF4FABE44329111C0BDBC6D97A28E7C7C188250265B37D2E6A849D7F0CAC606490648F17DC7FB9C8778BE7217991EBB6304BD543CFEE55084E54CCD634B49F26A751","/"));
|
||||
|
||||
httpClient = new System.Net.Http.HttpClient(httpClientHandler);
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
HandleHeaders(httpClient.DefaultRequestHeaders);
|
||||
@@ -172,8 +171,13 @@ namespace Assets.Scripts.Apis
|
||||
{
|
||||
AddLanguage();
|
||||
var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
|
||||
|
||||
return await response.Content.ReadAsStreamAsync();
|
||||
}
|
||||
// protected override Task<HttpResponseMessage> SendAsync(
|
||||
// HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
|
||||
//}
|
||||
|
||||
private async Task<T> ParseJsonAsync<T>(HttpResponseMessage response)
|
||||
{
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Assets.Scripts.Apis
|
||||
public class JsonResult
|
||||
{
|
||||
public bool result { get; set; }
|
||||
public int? code { get; set; }
|
||||
//public dynamic data { get; set; }
|
||||
public string errMsg { get; set; }
|
||||
public JArray errFieldMsg { get; set; }
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Apis
|
||||
{
|
||||
public class PfHttpClientHandler: HttpClientHandler
|
||||
{
|
||||
protected async override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
//{"result":false,"errMsg":"已在其他设备登录","code":401}
|
||||
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
if (request.RequestUri.ToString().Contains(App.Host) && result.Contains(@"{""result"":false,"))
|
||||
{
|
||||
var json = ParseJson<JsonResult<object>>(result);
|
||||
if (json.code == 401)
|
||||
{
|
||||
App.is401 = json.errMsg;
|
||||
UIManager.Instance.StartCoroutine(LoadLogin(json.errMsg));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App.is401 = null;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
private T ParseJson<T>(string result)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result, new JsonSerializerSettings
|
||||
{
|
||||
DateTimeZoneHandling = DateTimeZoneHandling.Local
|
||||
});
|
||||
}
|
||||
IEnumerator LoadLogin(string msg)
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be40636e05636c34690e1a893df3c22a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+27
-3
@@ -11,10 +11,11 @@ using Assets.Scripts.Devices;
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
|
||||
public static class App
|
||||
{
|
||||
public static string Host = "http://192.168.0.101:5084/";
|
||||
public static string Host = "http://192.168.0.101:5085/";
|
||||
|
||||
public static string AppVersion = Application.version;
|
||||
|
||||
@@ -31,7 +32,7 @@ public static class App
|
||||
|
||||
public static double latitude { get; internal set; }
|
||||
public static double longitude { get; internal set; }
|
||||
|
||||
public static string is401 { get; set; }
|
||||
public static bool FromLogin => false;
|
||||
public static bool? _IsRowerMode = null;
|
||||
public static bool? IsRowerMode
|
||||
@@ -118,7 +119,30 @@ public static class App
|
||||
App._IsRowerMode = bool.Parse(isRower);
|
||||
}
|
||||
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
|
||||
System.Timers.Timer timer = new System.Timers.Timer();
|
||||
timer.Interval = 1000;
|
||||
timer.AutoReset = true;
|
||||
timer.Elapsed += new ElapsedEventHandler((o, e) =>
|
||||
{
|
||||
var reply = ping.Send("47.97.84.8");
|
||||
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
App.delayTime = new System.Random().Next(300);
|
||||
#else
|
||||
App.delayTime = reply.RoundtripTime;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
App.delayTime = -1;
|
||||
}
|
||||
});
|
||||
timer.Start();
|
||||
});
|
||||
Debug.Log(SystemInfo.deviceUniqueIdentifier);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,13 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
private BleCharacteristicInfo tacxFecWriteCharacteristic;
|
||||
|
||||
private TacxFecWrite tacxFecWrite;
|
||||
|
||||
private List<Guid> otherGuids = new List<Guid>()
|
||||
{
|
||||
new Guid("0000fff0-0000-1000-8000-00805f9b34fb"),
|
||||
new Guid("0000180a-0000-1000-8000-00805f9b34fb"),
|
||||
new Guid("00001826-0000-1000-8000-00805f9b34fb"),
|
||||
new Guid("c1fe406e-a3b5-93f3-e0a9-e50e24dcca9e"),
|
||||
};
|
||||
/// <summary>
|
||||
/// 当前坡度,当切换到其他模式的时候,需要把坡度设置为0
|
||||
/// </summary>
|
||||
@@ -35,7 +41,6 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
{
|
||||
tacxFecNotify = new TacxFecNotify();
|
||||
base.Characteristics.Add(tacxFecNotify);
|
||||
|
||||
tacxFecWrite = new TacxFecWrite();
|
||||
base.Characteristics.Add(tacxFecWrite);
|
||||
|
||||
@@ -80,7 +85,7 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
{
|
||||
foreach (var item in base.Characteristics)
|
||||
{
|
||||
if (characteristic.MatchGuid(item.Uuid))
|
||||
if (characteristic.MatchGuid(item.Uuid) || otherGuids.Contains(item.Uuid))
|
||||
{
|
||||
//Debug.Log(string.Join(",", response.Data));
|
||||
item.HandleAttributeReceived(response.Data);
|
||||
|
||||
@@ -128,6 +128,11 @@ public class LoginController : BaseScene
|
||||
#elif UNITY_IOS
|
||||
Input.location.Start();
|
||||
#endif
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
if (!string.IsNullOrEmpty(App.is401))
|
||||
{
|
||||
Utils.showToast(null, App.is401);
|
||||
}
|
||||
Init();
|
||||
if (loginScrollView != null)
|
||||
{
|
||||
@@ -501,36 +506,14 @@ public class LoginController : BaseScene
|
||||
transform.Find("Panel").Find("Version").GetComponent<Text>().text = $"V{App.AppVersion}";
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Test(string key)
|
||||
{
|
||||
Debug.Log(key);
|
||||
}
|
||||
async void Init()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
|
||||
System.Timers.Timer timer = new System.Timers.Timer();
|
||||
timer.Interval = 1000;
|
||||
timer.AutoReset = true;
|
||||
timer.Elapsed += new ElapsedEventHandler((o, e) =>
|
||||
{
|
||||
var reply = ping.Send("47.97.84.8");
|
||||
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
App.delayTime = new System.Random().Next(300);
|
||||
#else
|
||||
App.delayTime = reply.RoundtripTime;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
App.delayTime = -1;
|
||||
}
|
||||
});
|
||||
timer.Start();
|
||||
});
|
||||
|
||||
Debug.Log(535);
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
userInfos = UIManager.Instance.userInfos;
|
||||
|
||||
@@ -514,11 +514,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//显示设备连接
|
||||
public void ShowDevicePanel(BaseEventData baseEventData)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
UIManager.ShowDevicePanel();
|
||||
#else
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, uipanel.GetComponent<PFUIPanel>());
|
||||
#endif
|
||||
mainController.ShowDevice(null);
|
||||
}
|
||||
//显示设置
|
||||
public void ShowSettingPanel(BaseEventData baseEventData)
|
||||
|
||||
@@ -497,10 +497,12 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
{
|
||||
singleUIManager.StartRide();
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = true;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = false;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = false;
|
||||
Utils.showToast(null, "Please connect the device!", duration: int.MaxValue, isLowest: true
|
||||
, stopFunc: () => !(!CheckAnt() && !isWatch)
|
||||
, endCallback: () =>
|
||||
@@ -508,6 +510,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
UIManager.Instance.DevicePanel.Close();
|
||||
singleUIManager.StartRide();
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/StartOrPauseButton").GetComponent<Button>().enabled = true;
|
||||
transform.Find("UI/Panel(Clone)/ToolBarPanel/SettingButton").GetComponent<Button>().enabled = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -646,7 +649,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
UIManager.ShowDevicePanel();
|
||||
#else
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, pFUIPanel);
|
||||
UIManager.Show(UIManager.Instance.DevicePanel,null,true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ public class RaceScript : PFUIPanel
|
||||
}
|
||||
protected void StartTime()
|
||||
{
|
||||
if (_timer == null)
|
||||
{
|
||||
_timer = Timer();
|
||||
}
|
||||
timerFlag = true;
|
||||
StartCoroutine(_timer);
|
||||
}
|
||||
@@ -136,7 +140,10 @@ public class RaceScript : PFUIPanel
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_timer = Timer();
|
||||
if (_timer == null)
|
||||
{
|
||||
_timer = Timer();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
@@ -148,6 +148,11 @@ public class UIManager : MonoBehaviour
|
||||
return this.GetPanelInstance("EditUserPanel", ref this.mEditUserController);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetModalPanel(PFUIPanel p)
|
||||
{
|
||||
UIManager.Instance.ModalsPanel = p;
|
||||
}
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
private ResultListPanelController mResultListController;
|
||||
public ResultListPanelController ResultListPanel
|
||||
|
||||
@@ -143,11 +143,21 @@ namespace Assets.Scripts
|
||||
_deviceDict = value;
|
||||
}
|
||||
}
|
||||
public static void showToast(GameObject game, string text, int duration = 2, int type = 0, Func<bool> stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null)
|
||||
public static void showToast(GameObject p, string text, int duration = 2, int type = 0, Func<bool> stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null,PFUIPanel _parent = null)
|
||||
{
|
||||
//type 0错误 1正确
|
||||
var parent = UIManager.Instance.ModalsPanel;
|
||||
if (parent == null) return;
|
||||
if (parent == null)
|
||||
{
|
||||
if (_parent)
|
||||
{
|
||||
parent = _parent;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!parent.gameObject.activeInHierarchy) parent.gameObject.SetActive(true);
|
||||
var toast = parent.transform.Find("ToastContainer");
|
||||
if (toast != null)
|
||||
|
||||
Reference in new issue
Block a user