主场景迁移
This commit is contained in:
1 parent
ba994e715c
commit
ba324aa68d
18 files changed
+94
-13
No files matched your search
@@ -1,93 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d1430f696af1114097da700a5dfe0ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user