game: adding signin to supabase

This commit is contained in:
ryan 2025-01-23 14:22:22 +08:00
parent 774ec4831b
commit d69056c9c1
5 changed files with 117 additions and 32 deletions

View file

@ -195,8 +195,8 @@ Light:
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ColorTemperature: 5512
m_UseColorTemperature: 1
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_UseViewFrustumForShadowCasterCull: 1
@ -248,6 +248,22 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1767192439, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
propertyPath: m_BackGroundColor.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1767192439, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
propertyPath: m_BackGroundColor.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1767192439, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
propertyPath: m_BackGroundColor.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1767192439, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
propertyPath: m_BackGroundColor.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1717954561962503725, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3}
propertyPath: m_Name
value: XR Origin (XR Rig)
@ -332,6 +348,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
url: https://fchobpauqasfebohuuam.supabase.co
anonKey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZjaG9icGF1cWFzZmVib2h1dWFtIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzczNTYyNTUsImV4cCI6MjA1MjkzMjI1NX0.LkwCnzjtf8CPLrm6OONkjyjxZW8jE05V_spbOEeAXEM
email: Ryanlin.hr@gmail.com
password: 1234567890
--- !u!4 &545637505
Transform:
m_ObjectHideFlags: 0

View file

@ -1,13 +1,18 @@
using Postgrest;
using Postgrest.Attributes;
using Postgrest.Models;
using UnityEngine;
using Supabase;
using Supabase.Gotrue;
using Client = Supabase.Client;
public class Backend : MonoBehaviour
{
[SerializeField] private string url;
[SerializeField] private string anonKey;
public Client Client;
public string email;
public string password;
public Session Session;
private async void Start()
{
@ -16,34 +21,63 @@ public class Backend : MonoBehaviour
AutoConnectRealtime = true
};
var client = new Supabase.Client(url, anonKey, options);
await client.InitializeAsync();
var test = new Test
Client = new Supabase.Client(url, anonKey, options);
await Client.InitializeAsync().ContinueWith(task =>
{
Name = "John",
Score = 100
};
await client.From<Test>().Insert(test, new QueryOptions { Returning = QueryOptions.ReturnType.Representation })
.ContinueWith(task =>
if (!task.IsCompletedSuccessfully)
{
if (task.IsCompletedSuccessfully)
{
var result = task.Result;
Debug.Log(result.Models[0].Name);
}
else
{
Debug.LogError(task.Exception);
}
});
Debug.LogError(task.Exception);
}
else
{
Debug.Log("Supabase Initialized");
}
});
SignUp(email, password, "Test");
}
}
[Table("test")]
public class Test : BaseModel
{
[Column("name")] public string Name { get; set; }
public async void SendData(string uid, int score, string displayName, int daysPlayed, int customersHelped, int customersHelpedWrongly)
{
var user= new Users
{
uid = uid,
score = score,
displayName = displayName,
daysPlayed = daysPlayed,
customersHelped = customersHelped,
customersHelpedWrongly = customersHelpedWrongly,
};
await Client.From<Users>().Insert(user).ContinueWith(SendTask =>
{
if (!SendTask.IsCompletedSuccessfully)
{
Debug.LogError(SendTask.Exception);
}
else
{
Debug.Log("Data Sent Sucessfully");
}
});
}
[Column("score")] public int Score { get; set; }
public async void SignUp(string email, string password, string displayName)
{
Session = await Client.Auth.SignUp(email, password);
Debug.Log(Session.User.Id);
SendData(Session.User.Id, 0, displayName, 0, 0, 0);
}
public async void SignIn(string email, string password)
{
Session = await Client.Auth.SignIn(email, password);
Debug.Log(Session.User.Id);
}
public async void GetData()
{
}
}

View file

@ -0,0 +1,22 @@
using Postgrest.Attributes;
using Postgrest.Models;
[Table("test")]
public class Test : BaseModel
{
[Column()] public string name { get; set; }
[Column()] public int score { get; set; }
}
[Table("users")]
public class Users : BaseModel
{
[Column()] public string uid { get; set; }
[Column()] public int score { get; set; }
[Column()] public string displayName { get; set; }
[Column()] public int daysPlayed { get; set; }
[Column()] public int customersHelped { get; set; }
[Column()] public int customersHelpedWrongly { get; set; }
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b645c5873f8e2e749b06822b7f32e31f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -12,8 +12,8 @@ PlayerSettings:
targetDevice: 2
useOnDemandResources: 0
accelerometerFrequency: 60
companyName: DefaultCompany
productName: SSLR
companyName: SweetStarryLilRabbits
productName: SolaceOfService
defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0}
m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1}