มาเริ่มกันเลยดีกว่า
1. ให้ทำการสร้าง Project และ Import Firebase Auth package เข้ามาครับ
2. ทำการ switch platform เป็น Android or iOS ครับ
3. และให้ทำการ download file "google-service" ลงมาด้วยครับ
4. จากนั้นไปที่ Firebase Console และทำการเพิ่ม Enable Email
using Firebase.Auth;
using UnityEngine;
using UnityEngine.UI;
public class EmailLoginController : MonoBehaviour
{
public Text log;
public InputField email;
public InputField password;
private FirebaseAuth auth;
void Start()
{
auth = FirebaseAuth.DefaultInstance;
}
// public void Login(){}
// public void Register(){}
}
public void Register()
{
auth.CreateUserWithEmailAndPasswordAsync(email.text, password.text).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("CreateUserWithEmailAndPasswordAsync error: " + task.Exception);
// ตรวจสอบ InnerExceptions
if (task.Exception.InnerExceptions.Count > 0)
Debug.LogError(task.Exception.InnerExceptions[0].Message);
return;
}
FirebaseUser newUser = task.Result;
log.text = string.Format("Firebase user created successfully: {0} ({1})", newUser.DisplayName, newUser.UserId);
// Load Scene
});
}
public void Login()
{
auth.SignInWithEmailAndPasswordAsync(email.text, password.text).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithEmailAndPasswordAsync error: " + task.Exception);
// ตรวจสอบ InnerExceptions
if (task.Exception.InnerExceptions.Count > 0)
Debug.LogError(task.Exception.InnerExceptions[0].Message);
return;
}
FirebaseUser newUser = task.Result;
log.text = string.Format("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId);
// Load Scene
});
}
เท่านี้ก็สามารถนำไปประยุกต์ใช้งานได้ละครับ
NO GAME NO DREAM !!!!