using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Auth;
using System;
public class FireBaseAuthManager
{
private static FireBaseAuthManager instance = null;
public static FireBaseAuthManager Instance
{
get
{
if (instance == null)
{
instance = new FireBaseAuthManager();
}
return instance;
}
}
private FirebaseAuth auth; // 로그인의 아이디,비번 정보
private FirebaseAuth user; // 로그인한 유저 데이터
public String UserId => user.UserId;
public Action<bool> LoginState;
public void Init()
{
auth = FirebaseAuth.DefaultInstance;
auth.StateChanged += OnChanged;
}
private void Onchanged(object sender, EventArgs e)
{
if(auth.CurrentUser != user)
{
bool signed = (auth.CurrentUser != user && auth.CurrentUser != null);
if(!signed && user != null)
{
Debug.Log("로그아웃");
LoginState?.Invoke(false);
}
user = auth.CurrentUser;
if (signed)
{
Debug.Log("로그인");
LoginState?.Invoke(true);
}
}
}
public void Login(string email, string Password)
{
auth.SignInWithEmailAndPasswordAsync(email, Password).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("로그인 취소");
return;
}
if (task.IsFaulted) // 회원가입 오류 이류: 이메일 오류, 비밀번호 오류 , 이미 가입된 이메일
{
Debug.LogError("로그인 실패");
return;
}
AuthResult authResult = task.Result;
FirebaseUser user = authResult.User;
Debug.LogError("로그인 완료");
} );
}
public void Create(string email,string Password)
{
auth.CreateUserWithEmailAndPasswordAsync(email, Password).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("회원가입취소");
return;
}
if (task.IsFaulted)
{
Debug.LogError("회원가입실패");
return;
}
AuthResult authResult = task.Result;
FirebaseUser user = authResult.User;
Debug.LogError("회원가입완료");
});
}
public void LogOut()
{
auth.SignOut();
Debug.Log("로그아웃");
}
}
When I Loggin InterFace is succeed it is Okay but when I arrangement the code to optimizer the Scripts
It is Crashed to much
So What Can I do
