2022-03-02 17:03:29 +08:00
using Assets.Scripts ;
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Linq ;
using System.Threading.Tasks ;
using UnityEngine ;
2022-06-09 14:51:03 +08:00
using UnityEngine.SceneManagement ;
2022-03-02 17:03:29 +08:00
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 )
{
2022-06-09 14:51:03 +08:00
if ( ! SceneManager . GetActiveScene ( ) . name . Contains ( "Login" ) )
{
GetMessage ( ) ;
}
2022-03-02 17:03:29 +08:00
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 ;
}
}
}