This commit is contained in:
2026-04-28 22:35:03 +07:00
parent 645f89b352
commit 29888fadfa
18 changed files with 1122 additions and 5800 deletions

View File

@@ -0,0 +1,10 @@
using UnityEngine;
namespace Hallucinate.UI
{
[CreateAssetMenu(fileName = "FirebaseConfig", menuName = "Configs/FirebaseConfig")]
public class FirebaseConfig : ScriptableObject
{
public string baseUrl;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0551a27408b84c040a2e009ae17debde

View File

@@ -8,8 +8,35 @@ namespace Hallucinate.UI
{
public static class FirebaseService
{
// Thay link database của bạn vào đây
private const string BASE_URL = "https://YOUR_FIREBASE_URL.firebaseio.com/users";
private static string _baseUrl;
private static string BASE_URL
{
get
{
if (string.IsNullOrEmpty(_baseUrl))
{
// Nó sẽ tìm file tên "FirebaseConfig" trong bất kỳ folder "Resources" nào
var config = Resources.Load<FirebaseConfig>("FirebaseConfig");
if (config != null)
{
if (string.IsNullOrEmpty(config.baseUrl))
{
Debug.LogError("<color=red>[FirebaseService]</color> Base URL trong file FirebaseConfig đang trống!");
return null;
}
_baseUrl = config.baseUrl.TrimEnd('/');
}
else
{
Debug.LogError("<color=red>[FirebaseService]</color> Không tìm thấy file 'FirebaseConfig' trong folder Resources! " +
"Hãy đảm bảo bạn đã tạo file tại: Assets/.../Resources/FirebaseConfig");
return null;
}
}
return _baseUrl + "/users";
}
}
public static async Task<bool> IsUsernameTaken(string username)
{

View File

@@ -0,0 +1,44 @@
using UnityEngine;
using Hallucinate.UI;
using System.Threading.Tasks;
namespace Hallucinate.UI
{
public class FirebaseTest : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private string testUsername = "TuanPlayer_01";
async void Start()
{
Debug.Log("<color=cyan>--- Firebase Test Started ---</color>");
// Bước 1: Kiểm tra xem username đã tồn tại chưa
Debug.Log($"[Firebase] Đang kiểm tra username: {testUsername}...");
bool isTaken = await FirebaseService.IsUsernameTaken(testUsername);
if (isTaken)
{
Debug.Log($"<color=yellow>[Firebase] Username '{testUsername}' đã tồn tại trên Database!</color>");
}
else
{
Debug.Log($"<color=green>[Firebase] Username '{testUsername}' còn trống. Tiến hành đăng ký...</color>");
// Bước 2: Thử đăng ký user mới
bool success = await FirebaseService.RegisterUser(testUsername);
if (success)
{
Debug.Log("<color=green>[Firebase] Đăng ký thành công! Hãy kiểm tra trình duyệt (Firebase Console).</color>");
}
else
{
Debug.LogError("[Firebase] Đăng ký thất bại. Kiểm tra link URL hoặc Internet.");
}
}
Debug.Log("<color=cyan>--- Firebase Test Finished ---</color>");
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: db205c30e8f41d84fa79269745feaf84