下载速度,修改文案
This commit is contained in:
1 parent
abf913b467
commit
5c96b10385
12 files changed
+203
-380
No files matched your search
@@ -9,7 +9,7 @@ namespace Assets.Scripts.UI.Prefab.MapList
|
||||
{
|
||||
public class MapFilterOptions
|
||||
{
|
||||
public static List<Dropdown.OptionData> distances = new string[] {"全部",
|
||||
public static List<Dropdown.OptionData> distances = new string[] {"All",
|
||||
"0-5KM",
|
||||
"5-10KM",
|
||||
"10-20KM",
|
||||
@@ -17,10 +17,10 @@ namespace Assets.Scripts.UI.Prefab.MapList
|
||||
"30-50KM",
|
||||
"50-100KM",
|
||||
"100-200KM",
|
||||
"200-无限制", }.Select(x=>new Dropdown.OptionData(x)).ToList();
|
||||
"Over 200KM", }.Select(x=>new Dropdown.OptionData(x)).ToList();
|
||||
public static Dictionary<string, string> distanceDict = new Dictionary<string, string>()
|
||||
{
|
||||
{"全部","" },
|
||||
{"All","" },
|
||||
{"0-5KM","0-5" },
|
||||
{"5-10KM","5-10" },
|
||||
{"10-20KM","10-20" },
|
||||
@@ -28,7 +28,7 @@ namespace Assets.Scripts.UI.Prefab.MapList
|
||||
{"30-50KM","30-50" },
|
||||
{"50-100KM","50-100" },
|
||||
{"100-200KM","100-200" },
|
||||
{"200-无限制","200-99999" },
|
||||
{"Over 200KM","200-99999" },
|
||||
};
|
||||
public static Dictionary<string,string> diffDict = new Dictionary<string, string>()
|
||||
{
|
||||
|
||||
@@ -62,8 +62,11 @@ public class HomeController : PFUIPanel
|
||||
//Application.OpenURL("https://powerfun.oss-cn-shanghai.aliyuncs.com/Releases/PowerFunWorkouts.exe");
|
||||
return;
|
||||
}
|
||||
Utils.ExecFile(path);
|
||||
Application.Quit();
|
||||
UIManager.ShowConfirm("Confirm", "Switch to PowerFun Workouts?\nWe will close the Powerfun and start PowerFun Workouts.", () =>
|
||||
{
|
||||
Utils.ExecFile(path);
|
||||
Application.Quit();
|
||||
});
|
||||
});
|
||||
UIManager.AddEvent(BtnTraining.gameObject, EventTriggerType.PointerEnter, OnHover);
|
||||
UIManager.AddEvent(BtnTraining.gameObject, EventTriggerType.PointerExit, OnExit);
|
||||
|
||||
@@ -398,8 +398,6 @@ public class MapListController : PFUIPanel
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
var cg = this.GetComponent<CanvasGroup>();
|
||||
cg.alpha = 0;
|
||||
base.Show();
|
||||
if (App.TextureCache.ContainsKey("rotateImage"))
|
||||
{
|
||||
@@ -409,6 +407,8 @@ public class MapListController : PFUIPanel
|
||||
{
|
||||
transform.Find("RawImage").GetComponent<RawImage>().texture = App.DefaultRotateTexture;
|
||||
}
|
||||
var cg = this.GetComponent<CanvasGroup>();
|
||||
cg.alpha = 0;
|
||||
cg.DOFade(1f, .3f);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class RaceItemScript : MonoBehaviour, IPointerExitHandler, IPointerEnterH
|
||||
Utils.DisplayImage(transform.GetComponent<RawImage>(), mapCompetition.RouteCover, true);
|
||||
Utils.DisplayImage(transform.Find("AltitudeCurve").GetComponent<RawImage>(), mapCompetition.AltitudeGraph, true);
|
||||
transform.Find("InfoContainer/Text").GetComponent<Text>().SetTextWithEllipsis(mapCompetition.Title);
|
||||
transform.Find("GetReadyContainer").gameObject.SetActive(mapCompetition.Status != 3);
|
||||
transform.Find("GetReadyContainer").gameObject.SetActive(true);
|
||||
transform.Find("GetReadyContainer-2").gameObject.SetActive(mapCompetition.Status == 1);
|
||||
//transform.Find("Text").GetComponent<Text>().text = mapCompetition.Title;
|
||||
//props.Find("DistanceText").GetComponent<Text>().text = $"{myMap.Distance.ToString(myMap.Distance > 1000 ? "#0" : "#0.00")}KM";
|
||||
|
||||
@@ -12,7 +12,9 @@ public class RaceScript : PFUIPanel
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
transform.GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
||||
var cg = this.GetComponent<CanvasGroup>();
|
||||
cg.alpha = 0;
|
||||
cg.DOFade(1f, .5f);
|
||||
}
|
||||
protected void StartTime()
|
||||
{
|
||||
@@ -93,12 +95,18 @@ public class RaceScript : PFUIPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (map.Status == 4)
|
||||
else if (map.Status == 3)
|
||||
{
|
||||
currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text = "Start Time";
|
||||
currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text =
|
||||
map.StartTime.ToString("yyyy-MM-dd HH:mm");
|
||||
}
|
||||
else if (map.Status == 4)
|
||||
{
|
||||
currentItem.Find("GetReadyContainer/Title").GetComponent<Text>().text = "End Time";
|
||||
currentItem.Find("GetReadyContainer/Value").GetComponent<Text>().text =
|
||||
map.FirstEndTime.HasValue?
|
||||
map.FirstEndTime.Value.ToString("yyyy-MM-dd HH:mm"):map.EndTime.ToString("yyyy-MM-dd HH:mm");
|
||||
map.FirstEndTime.HasValue ?
|
||||
map.FirstEndTime.Value.ToString("yyyy-MM-dd HH:mm") : map.EndTime.ToString("yyyy-MM-dd HH:mm");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DownloadController : PFUIPanel
|
||||
SetType(1);
|
||||
//Button.GetComponent<Button>().enabled = false;
|
||||
//Button.GetComponent<Button>().interactable = false;
|
||||
path = Application.persistentDataPath + "/PowerFun.exe";
|
||||
path = Application.temporaryCachePath + "/PowerFun.exe";
|
||||
UIManager.AddEvent(Btn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
Application.Quit();
|
||||
@@ -41,10 +41,10 @@ public class DownloadController : PFUIPanel
|
||||
{
|
||||
BtnStart.GetComponent<Button>().enabled = false;
|
||||
BtnStart.GetComponent<Button>().interactable = false;
|
||||
StartCoroutine(DownLoadExe(App.UpdateObject.Url, path, (a, b, isComplete) =>
|
||||
StartCoroutine(DownLoadExe(App.UpdateObject.Url, path, (p, isComplete) =>
|
||||
{
|
||||
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {a.ToString("#0")}M / {b.ToString("#0")}M";// string.Format(, a, b);
|
||||
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)(a / b);
|
||||
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {Math.Round(p * 100, 0)}%";// string.Format(, a, b);
|
||||
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)p;
|
||||
if (isComplete)
|
||||
{
|
||||
SetType(3);
|
||||
@@ -73,7 +73,7 @@ public class DownloadController : PFUIPanel
|
||||
}
|
||||
}
|
||||
/*下载文件*/
|
||||
IEnumerator DownLoadExe(string url, string desFileName, Action<double, double, bool> OnDownloadProgressEvent)
|
||||
IEnumerator DownLoadExe(string url, string desFileName, Action<double, bool> OnDownloadProgressEvent)
|
||||
{
|
||||
string version = null;
|
||||
if (App.UpdateObject != null)
|
||||
@@ -108,33 +108,75 @@ public class DownloadController : PFUIPanel
|
||||
File.Delete(desFileName + ".pfdownload");
|
||||
}
|
||||
SetType(2);
|
||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
request.Timeout = 5000;
|
||||
WebResponse response = request.GetResponse();
|
||||
//UnityWebRequest request = UnityWebRequest.Get(url);
|
||||
//yield return request.SendWebRequest();
|
||||
int packLength = 1024 * 20;
|
||||
int nReadSize = 0;
|
||||
byte[] nbytes = new byte[packLength];
|
||||
double dDownloadedLength = 0, dTotalLength = 0;
|
||||
long countLength = response.ContentLength;
|
||||
using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
|
||||
using (Stream netStream = response.GetResponseStream())
|
||||
//HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
//request.Timeout = 5000;
|
||||
//WebResponse response = request.GetResponse();
|
||||
////UnityWebRequest request = UnityWebRequest.Get(url);
|
||||
////yield return request.SendWebRequest();
|
||||
//int packLength = 1024 * 20;
|
||||
//int nReadSize = 0;
|
||||
//byte[] nbytes = new byte[packLength];
|
||||
//double dDownloadedLength = 0, dTotalLength = 0;
|
||||
//long countLength = response.ContentLength;
|
||||
//using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
|
||||
//using (Stream netStream = response.GetResponseStream())
|
||||
//{
|
||||
// nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
// while (nReadSize > 0)
|
||||
// {
|
||||
// fs.Write(nbytes, 0, nReadSize);
|
||||
// nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
// dDownloadedLength = fs.Length * 1.0 / (1024 * 1024);
|
||||
// dTotalLength = countLength * 1.0 / (1024 * 1024);
|
||||
// OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, false);
|
||||
// //string ss = string.Format("已下载 {0:F}M / {1:F}M", dDownloadedLength, dTotalLength);
|
||||
// //Debug.Log(ss);
|
||||
// yield return null;
|
||||
// }
|
||||
//}
|
||||
//OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, true);
|
||||
using (var uwr = UnityWebRequest.Get(url))
|
||||
{
|
||||
nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
while (nReadSize > 0)
|
||||
var operation = uwr.SendWebRequest();
|
||||
|
||||
while (!operation.isDone)
|
||||
{
|
||||
fs.Write(nbytes, 0, nReadSize);
|
||||
nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
dDownloadedLength = fs.Length * 1.0 / (1024 * 1024);
|
||||
dTotalLength = countLength * 1.0 / (1024 * 1024);
|
||||
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, false);
|
||||
//string ss = string.Format("已下载 {0:F}M / {1:F}M", dDownloadedLength, dTotalLength);
|
||||
//Debug.Log(ss);
|
||||
/*
|
||||
* as BugFinder metnioned in the comments
|
||||
* what you want to track is uwr.downloadProgress
|
||||
*/
|
||||
var downloadDataProgress = uwr.downloadProgress * 100;
|
||||
|
||||
/*
|
||||
* use a float division here
|
||||
* I don't know what type downloadDataProgress is
|
||||
* but if it is an int than you will always get
|
||||
* an int division <somethingSmallerThan100>/100 = 0
|
||||
*/
|
||||
//progressBar.fillAmount = downloadDataProgress / 100.0f;
|
||||
OnDownloadProgressEvent.Invoke(uwr.downloadProgress, false);
|
||||
Debug.Log("Download: " + downloadDataProgress);
|
||||
yield return null;
|
||||
}
|
||||
ByteArrayToFile(path + ".pfdownload", uwr.downloadHandler.data);
|
||||
OnDownloadProgressEvent.Invoke(1, true);
|
||||
}
|
||||
}
|
||||
public bool ByteArrayToFile(string fileName, byte[] byteArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
fs.Write(byteArray, 0, byteArray.Length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError(ex);
|
||||
return false;
|
||||
}
|
||||
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, true);
|
||||
}
|
||||
void SetType(int a)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
Btn = transform.Find("Panel/BtnConfirm");
|
||||
BtnStart = transform.Find("Panel/BtnStart");
|
||||
Loading = transform.Find("Panel/LoadingContainer");
|
||||
scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
|
||||
//scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
|
||||
Exit = transform.Find("Panel/Exit");
|
||||
BtnStart.GetComponent<Button>().enabled = true;
|
||||
BtnStart.GetComponent<Button>().interactable = true;
|
||||
@@ -35,7 +35,7 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
Btn = transform.Find("Panel/BtnConfirm");
|
||||
BtnStart = transform.Find("Panel/BtnStart");
|
||||
Loading = transform.Find("Panel/LoadingContainer");
|
||||
scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
|
||||
//scroll = transform.Find("Panel/Scroll View").GetComponent<ScrollRect>();
|
||||
Exit = transform.Find("Panel/Exit");
|
||||
SetType(1);
|
||||
UIManager.AddEvent(Exit.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
|
||||
@@ -59,14 +59,15 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
|
||||
//Button.GetComponent<Button>().enabled = false;
|
||||
//Button.GetComponent<Button>().interactable = false;
|
||||
path = Application.persistentDataPath + "/PowerFunWorkouts.exe";
|
||||
path = Application.temporaryCachePath + "/PowerFunWorkouts.exe";
|
||||
Debug.Log(path);
|
||||
UIManager.AddEvent(Btn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
//Application.Quit();
|
||||
UIManager.ShowConfirm("Confirm", @"Switch to PowerFun Workouts? We will close the Powerfun and start PowerFun Workouts", () =>
|
||||
UIManager.ShowConfirm("Confirm", "Switch to PowerFun Workouts?\nWe will close the Powerfun and start PowerFun Workouts.", () =>
|
||||
{
|
||||
Utils.ExecFile(path);
|
||||
UIManager.CloseConfirm();
|
||||
Application.Quit();
|
||||
});
|
||||
});
|
||||
UIManager.AddEvent(BtnStart.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick,async (_base) =>
|
||||
@@ -80,11 +81,11 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
BtnStart.GetComponent<Button>().enabled = false;
|
||||
BtnStart.GetComponent<Button>().interactable = false;
|
||||
Debug.Log(path);
|
||||
StartCoroutine(DownLoadExe(wpf.Url, path, (a, b, isComplete) =>
|
||||
StartCoroutine(DownLoadExe(wpf.Url, path, (p, isComplete) =>
|
||||
{
|
||||
Debug.Log($"{a} {b} {isComplete}");
|
||||
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {a.ToString("#0")}M / {b.ToString("#0")}M";// string.Format(, a, b);
|
||||
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)(a / b);
|
||||
//Debug.Log($"{a} {b} {isComplete}");
|
||||
transform.Find("Panel/LoadingContainer/Text").GetComponent<Text>().text = $"Downloaded {Math.Round(p * 100,0)}%";// string.Format(, a, b);
|
||||
transform.Find("Panel/LoadingContainer/Loading").GetComponent<Image>().fillAmount = (float)p;
|
||||
if (isComplete)
|
||||
{
|
||||
SetType(3);
|
||||
@@ -132,7 +133,7 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
HttpWebRequest request;
|
||||
Stream _fs, _netStream;
|
||||
/*下载文件*/
|
||||
IEnumerator DownLoadExe(string url, string desFileName, Action<double, double, bool> OnDownloadProgressEvent)
|
||||
IEnumerator DownLoadExe(string url, string desFileName, Action<double, bool> OnDownloadProgressEvent)
|
||||
{
|
||||
string version = null;
|
||||
if (wpf != null)
|
||||
@@ -151,7 +152,12 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
if (version == PlayerPrefs.GetString("exeVersion_w"))
|
||||
{
|
||||
//Application.Quit();
|
||||
Utils.ExecFile(desFileName);
|
||||
UIManager.ShowConfirm("Confirm", "Switch to PowerFun Workouts?\nWe will close the Powerfun and start PowerFun Workouts.", () =>
|
||||
{
|
||||
Utils.ExecFile(desFileName);
|
||||
Application.Quit();
|
||||
});
|
||||
|
||||
yield break;
|
||||
}
|
||||
else
|
||||
@@ -167,36 +173,81 @@ public class DownloadWorkoutsController : PFUIPanel
|
||||
File.Delete(desFileName + ".pfdownload");
|
||||
}
|
||||
SetType(2);
|
||||
request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
request.Timeout = 5000;
|
||||
//request = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||
//request.Timeout = 5000;
|
||||
|
||||
WebResponse response = request.GetResponse();
|
||||
//UnityWebRequest request = UnityWebRequest.Get(url);
|
||||
//yield return request.SendWebRequest();
|
||||
int packLength = 1024 * 20;
|
||||
int nReadSize = 0;
|
||||
byte[] nbytes = new byte[packLength];
|
||||
double dDownloadedLength = 0, dTotalLength = 0;
|
||||
long countLength = response.ContentLength;
|
||||
using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
|
||||
using (Stream netStream = response.GetResponseStream())
|
||||
//WebResponse response = request.GetResponse();
|
||||
////UnityWebRequest request = UnityWebRequest.Get(url);
|
||||
////yield return request.SendWebRequest();
|
||||
//int packLength = 1024 * 20;
|
||||
//int nReadSize = 0;
|
||||
//byte[] nbytes = new byte[packLength];
|
||||
//double dDownloadedLength = 0, dTotalLength = 0;
|
||||
//long countLength = response.ContentLength;
|
||||
//using (FileStream fs = new FileStream(desFileName + ".pfdownload", FileMode.Create))
|
||||
//using (Stream netStream = response.GetResponseStream())
|
||||
//{
|
||||
// _fs = fs;
|
||||
// _netStream = netStream;
|
||||
// nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
// while (nReadSize > 0)
|
||||
// {
|
||||
// fs.Write(nbytes, 0, nReadSize);
|
||||
// nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
// dDownloadedLength = fs.Length * 1.0 / (1024 * 1024);
|
||||
// dTotalLength = countLength * 1.0 / (1024 * 1024);
|
||||
// OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, false);
|
||||
// //string ss = string.Format("已下载 {0:F}M / {1:F}M", dDownloadedLength, dTotalLength);
|
||||
// //Debug.Log(ss);
|
||||
// yield return null;
|
||||
// }
|
||||
//}
|
||||
//OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, true);
|
||||
|
||||
using (var uwr = UnityWebRequest.Get(url))
|
||||
{
|
||||
_fs = fs;
|
||||
_netStream = netStream;
|
||||
nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
while (nReadSize > 0)
|
||||
var operation = uwr.SendWebRequest();
|
||||
|
||||
while (!operation.isDone)
|
||||
{
|
||||
fs.Write(nbytes, 0, nReadSize);
|
||||
nReadSize = netStream.Read(nbytes, 0, packLength);
|
||||
dDownloadedLength = fs.Length * 1.0 / (1024 * 1024);
|
||||
dTotalLength = countLength * 1.0 / (1024 * 1024);
|
||||
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, false);
|
||||
//string ss = string.Format("已下载 {0:F}M / {1:F}M", dDownloadedLength, dTotalLength);
|
||||
//Debug.Log(ss);
|
||||
/*
|
||||
* as BugFinder metnioned in the comments
|
||||
* what you want to track is uwr.downloadProgress
|
||||
*/
|
||||
var downloadDataProgress = uwr.downloadProgress * 100;
|
||||
|
||||
/*
|
||||
* use a float division here
|
||||
* I don't know what type downloadDataProgress is
|
||||
* but if it is an int than you will always get
|
||||
* an int division <somethingSmallerThan100>/100 = 0
|
||||
*/
|
||||
//progressBar.fillAmount = downloadDataProgress / 100.0f;
|
||||
OnDownloadProgressEvent.Invoke(uwr.downloadProgress,false);
|
||||
Debug.Log("Download: " + downloadDataProgress);
|
||||
yield return null;
|
||||
}
|
||||
ByteArrayToFile(path+".pfdownload", uwr.downloadHandler.data);
|
||||
OnDownloadProgressEvent.Invoke(1, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public bool ByteArrayToFile(string fileName, byte[] byteArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
fs.Write(byteArray, 0, byteArray.Length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError(ex);
|
||||
return false;
|
||||
}
|
||||
OnDownloadProgressEvent.Invoke(dDownloadedLength, dTotalLength, true);
|
||||
}
|
||||
void SetType(int a)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user