主场景迁移
This commit is contained in:
1 parent
ba994e715c
commit
ba324aa68d
18 files changed
+94
-13
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -11,5 +13,9 @@ namespace Assets.Scripts
|
||||
public static string Host = App.Host;
|
||||
|
||||
public static string AppVersion = App.AppVersion;
|
||||
public static UserResultModel CurrentUser { get; set; }
|
||||
public static UserApi userApi = new UserApi();
|
||||
public static MapApi mapApi = new MapApi();
|
||||
public static MapInterruptRecordApi mapInterruptRecordApi = new MapInterruptRecordApi();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UserInfo : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Text Ftp;
|
||||
[SerializeField] RawImage Avatar;
|
||||
[SerializeField] Text Weight;
|
||||
[SerializeField] Text WKG;
|
||||
[SerializeField] Text Calories;
|
||||
[SerializeField] Text KM;
|
||||
[SerializeField] Text Climb;
|
||||
[SerializeField] Text NickName;
|
||||
[SerializeField] Button More;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var parent = Utils.FindUpParent(gameObject.transform);
|
||||
if (parent.Find("ToastContainer") == null)
|
||||
{
|
||||
var toast = Instantiate(Resources.Load<GameObject>("ToastContainer"));
|
||||
toast.name = "ToastContainer";
|
||||
toast.GetComponent<RectTransform>().position = new Vector3(Screen.width / 2, Screen.height / 2, 0);
|
||||
toast.transform.parent = parent;
|
||||
}
|
||||
if (ConfigHelper.CurrentUser != null)
|
||||
{
|
||||
SetCurrentUser();
|
||||
GetSummary();
|
||||
}
|
||||
if (More != null)
|
||||
{
|
||||
More.onClick.AddListener(MoreFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void MoreFunc()
|
||||
{
|
||||
Utils.showToast(gameObject, "更多信息", 1);
|
||||
}
|
||||
|
||||
void SetCurrentUser()
|
||||
{
|
||||
var user = ConfigHelper.CurrentUser;
|
||||
Ftp.text = user.FTP.ToString();
|
||||
Weight.text = user.Weight.ToString();
|
||||
WKG.text = $"{user.Weight}KG/{user.BicycleWeight}KG";
|
||||
NickName.text = user.Nickname;
|
||||
Utils.DisplayImage(StartCoroutine, Avatar, user.WxHeadImg);
|
||||
}
|
||||
void GetSummary()
|
||||
{
|
||||
var res = ConfigHelper.userApi.GetSummary();
|
||||
if (res.result)
|
||||
{
|
||||
KM.text = $"{res.data.TotalDistance.ToString("#0.00")}KM";
|
||||
Climb.text = $"{res.data.TotalClimb.ToString()}M";
|
||||
Calories.text = $"{res.data.Kcal.ToString()}KCAL";
|
||||
//Calories.text = res.data.
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.showToast(gameObject, res.errMsg);
|
||||
}
|
||||
//var res = await NoAuthApi.GetCurrentUser();
|
||||
//if (res.result)
|
||||
//{
|
||||
// Global.CurrentUser = res.data;
|
||||
// SetCurrentUser();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Utils.showToast(gameObject, res.errMsg);
|
||||
//}
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32d45078acd8c0341bc9d900a607ebcd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,93 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class Toast : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (toast!=null)
|
||||
{
|
||||
//toast.SetActive(false);
|
||||
//txt = toast.transform.Find("Toast").GetComponent<Text>();
|
||||
}
|
||||
//if (txt != null)
|
||||
//{
|
||||
// txt.enabled = false;
|
||||
//}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
[SerializeField] GameObject toast;
|
||||
[SerializeField] Text txt;
|
||||
|
||||
public void showToast(string json)
|
||||
{
|
||||
JObject JO = (JObject)JsonConvert.DeserializeObject(json);
|
||||
toast.SetActive(true);
|
||||
StartCoroutine(showToastCOR(JO.Value<string>("text"), JO.Value<int>("duration")));
|
||||
}
|
||||
|
||||
private IEnumerator showToastCOR(string text,
|
||||
int duration)
|
||||
{
|
||||
Color orginalColor = txt.color;
|
||||
Color otoastColor = toast.GetComponent<Image>().color;
|
||||
txt.text = text;
|
||||
txt.enabled = true;
|
||||
//Fade in
|
||||
yield return fadeInAndOut(txt, true, 0.5f);
|
||||
|
||||
//Wait for the duration
|
||||
float counter = 0;
|
||||
while (counter < duration)
|
||||
{
|
||||
counter += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
//Fade out
|
||||
yield return fadeInAndOut(txt, false, 0.5f);
|
||||
|
||||
txt.enabled = false;
|
||||
toast.SetActive(false);
|
||||
txt.color = orginalColor;
|
||||
toast.GetComponent<Image>().color = otoastColor;
|
||||
}
|
||||
|
||||
IEnumerator fadeInAndOut(Text targetText, bool fadeIn, float duration)
|
||||
{
|
||||
//Set Values depending on if fadeIn or fadeOut
|
||||
float a, b;
|
||||
if (fadeIn)
|
||||
{
|
||||
a = 0f;
|
||||
b = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = 1f;
|
||||
b = 0f;
|
||||
}
|
||||
|
||||
Color currentColor = txt.color;
|
||||
Color toastColor = toast.GetComponent<Image>().color;
|
||||
float counter = 0f;
|
||||
|
||||
while (counter < duration)
|
||||
{
|
||||
counter += Time.deltaTime;
|
||||
float alpha = Mathf.Lerp(a, b, counter / duration);
|
||||
toast.GetComponent<Image>().color = new Color(toastColor.r, toastColor.g, toastColor.b, alpha);
|
||||
targetText.color = new Color(currentColor.r, currentColor.g, currentColor.b, alpha);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d1430f696af1114097da700a5dfe0ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
/*显示简略提示,需要拖Toast的预制件,且保证其他组件名字不是Toast,ToastContainer*/
|
||||
public static void showToast(GameObject game,string text,int duration = 1)
|
||||
{
|
||||
var toast = Utils.FindUpParent(game.transform).Find("ToastContainer");
|
||||
if (toast!=null)
|
||||
{
|
||||
toast.GetComponent<Toast>().showToast(JsonConvert.SerializeObject(new
|
||||
{
|
||||
text,
|
||||
duration
|
||||
}));
|
||||
//toast.SendMessage("showToast", );
|
||||
}
|
||||
}
|
||||
/*显示简略提示,需要拖Toast的预制件,且保证其他组件名字不是Toast,ToastContainer*/
|
||||
|
||||
/*显示网络图片*/
|
||||
public delegate Coroutine StartCoroutine(IEnumerator routine);
|
||||
public static void DisplayImage(StartCoroutine startCoroutine,RawImage img, string url)
|
||||
{
|
||||
startCoroutine(DownloadImage(img, url));
|
||||
}
|
||||
static IEnumerator DownloadImage(RawImage img,string MediaUrl)
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.isNetworkError || request.isHttpError)
|
||||
Debug.Log(request.error);
|
||||
else
|
||||
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
}
|
||||
/*显示网络图片*/
|
||||
|
||||
/*获取最顶层对象*/
|
||||
public static Transform FindUpParent(Transform zi)
|
||||
{
|
||||
if (zi.parent == null)
|
||||
return zi;
|
||||
else
|
||||
return FindUpParent(zi.parent);
|
||||
}
|
||||
/*获取最顶层对象*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 860b65f14906bba44b260c0fec18bca6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user