69 lines
1.5 KiB
C#
69 lines
1.5 KiB
C#
using Assets.Scripts;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class MailReceiver : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
private static MailReceiver _instance = null;
|
|
|
|
public static bool Exists()
|
|
{
|
|
return _instance != null;
|
|
}
|
|
|
|
public static MailReceiver Instance()
|
|
{
|
|
if (!Exists())
|
|
{
|
|
throw new Exception("UnityMainThreadDispatcher could not find the UnityMainThreadDispatcher object. Please ensure you have added the MainThreadExecutor Prefab to your scene.");
|
|
}
|
|
return _instance;
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
if (_instance == null)
|
|
{
|
|
_instance = this;
|
|
}
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
float timer = 10f;
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
if (timer < 0)
|
|
{
|
|
if (!SceneManager.GetActiveScene().name.Contains("Login"))
|
|
{
|
|
GetMessage();
|
|
}
|
|
timer += 10;
|
|
}
|
|
}
|
|
|
|
public async Task GetMessage()
|
|
{
|
|
var res = await ConfigHelper.mailApi.GetList(0, 100, 0);
|
|
if (res.result)
|
|
{
|
|
App.CurrentUserMails = res.data;
|
|
App.hasNotRead = res.data.Count(x => !x.IsRead) > 0;
|
|
}
|
|
}
|
|
}
|