修改细节

This commit is contained in:
Caiyanpeng committed 2021-04-25 13:35:07 +08:00
1 parent a96d538dc1
commit 048538a0c8
78 files changed
+15285 -6903

No files matched your search

+5 -12
View File
@@ -31,17 +31,16 @@ public class Toast : MonoBehaviour
public void showToast(string json)
{
JObject JO = (JObject)JsonConvert.DeserializeObject(json);
toast.SetActive(true);
gameObject.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;
gameObject.SetActive(true);
txt.text = text;
txt.enabled = true;
//Fade in
yield return fadeInAndOut(txt, true, 0.5f);
@@ -56,10 +55,7 @@ public class Toast : MonoBehaviour
//Fade out
yield return fadeInAndOut(txt, false, 0.5f);
txt.enabled = false;
toast.SetActive(false);
txt.color = orginalColor;
toast.GetComponent<Image>().color = otoastColor;
gameObject.SetActive(false);
}
IEnumerator fadeInAndOut(Text targetText, bool fadeIn, float duration)
@@ -77,16 +73,13 @@ public class Toast : MonoBehaviour
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);
transform.GetComponent<CanvasGroup>().alpha = alpha;
yield return null;
}
}
+55 -2
View File
@@ -1,5 +1,7 @@
using DG.Tweening;
using Assets.Scripts.UI.Control;
using DG.Tweening;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -76,8 +78,28 @@ namespace Assets.Scripts
}
/*获取ip*/
/*显示简略提示,需要拖Toast的预制件,且保证其他组件名字不是Toast,ToastContainer*/
public static void showToast(GameObject game,string text,int duration = 1)
private static Dictionary<int, string> _toastDict;
private static Dictionary<int, string> toastDict
{
get
{
if (_toastDict == null)
{
_toastDict = new Dictionary<int, string>
{
{0,"Images/home/wrong|#f93086" },{1,"Images/home/right|#41A6FE" }
};
}
return _toastDict;
}
set
{
_toastDict = value;
}
}
public static void showToast(GameObject game,string text,int duration = 1,int type = 0)
{
//type 0错误 1正确
var parent = Utils.FindUpParent(game.transform);
var toast = parent.Find("ToastContainer");
if (toast == null)
@@ -88,6 +110,9 @@ namespace Assets.Scripts
newToast.transform.parent = parent;
toast = newToast.transform;
}
var toastStyle = toastDict[type].Split('|');
toast.Find("Image").GetComponent<Image>().sprite = Resources.Load<Sprite>(toastStyle[0]);
toast.GetComponent<Image>().color = HexToColorHtml(toastStyle[1]);
toast.GetComponent<Toast>().showToast(JsonConvert.SerializeObject(new
{
text,
@@ -130,6 +155,15 @@ namespace Assets.Scripts
else
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
}
static IEnumerator DownloadImageToLocal(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;
}
/*显示网络图片*/
/*获取最顶层对象*/
@@ -218,5 +252,24 @@ namespace Assets.Scripts
}
}
/*打开文件*/
/**/
public static void SetValidate(Dictionary<string, Selectable> dict, JArray errorList)
{
foreach (var error in errorList)
{
var className = dict[error.Value<string>("Field")].GetType().Name;
if (className == "InputField")
{
dict[error.Value<string>("Field")].GetComponent<PFUIInputField>()
.SetValidate(true);
}
else if (className == "Dropdown")
{
dict[error.Value<string>("Field")].GetComponent<PFUIDropdown>()
.SetValidate();
}
//formDict[error.Value<string>("Filed")].error.Value<string>("ErrMsg");
}
}
}
}