description |
---|
Power up your Unity games with Particle Network SDKs. |
Before using, please review the prerequisites, All unity SDKs are open source, click here to view
- Before using the sdk you have to call init(Required)
ParticleNetwork.Init(ChainInfo.Ethereum);
- Drag prefab to your scene
Drag the ParticleAuthService.prefab to your first scene(Required)
Drag the ParticleUnityRpc.prefab to your first scene(Required), then replace your project id, app id and client key.
ParticleUnityRpc
public async void Login()
{
// authorization is optinal, support login and sign a message
// message in evm should be hex string, in solana should be base58 string.
// message in evm support unique signature.
var authorization = new LoginAuthorization("your message", false)
// login email
var nativeResultData = await ParticleAuthService.Instance.Login(LoginType.PHONE, null, SupportAuthType.ALL, SocialLoginPrompt.SelectAccount, authorization);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public async void Logout()
{
var nativeResultData = await ParticleAuthService.Instance.Logout();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public async void FastLogout()
{
var nativeResultData = await ParticleAuthService.Instance.FastLogout();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
Check is user login locally.
ParticleAuthServiceInteraction.IsLogin();
Check is user login from server, recommended.
var nativeResultData = await ParticleAuthService.Instance.IsLoginAsync();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
ParticleAuthServiceInteraction.GetAddress();
public async void SignMessage()
{
var message = "Hello world";
var nativeResultData =
await ParticleAuthService.Instance.SignMessage(message);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public async void SignTransaction()
{
var transaction = "your transaction";
var nativeResultData =
await ParticleAuthService.Instance.SignTransaction(transaction);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public async void SignAllTransactions()
{
var transaction1 = "transaction1";
var transaction2 ="transaction2";
Debug.Log("transaction1 = " + transaction1);
Debug.Log("transaction2 = " + transaction2);
string[] transactions = new[] { transaction1, transaction2 };
var nativeResultData =
await ParticleAuthService.Instance.SignAllTransactions(transactions);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}cc
public async void SignAndSendTransaction()
{
var transaction = "transaction";
var nativeResultData =
await ParticleAuthService.Instance.SignAndSendTransaction(transaction);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}c
public async void SignTypedData()
{
string typedData = "your typedata";
var nativeResultData =
await ParticleAuthService.Instance.SignTypedData(typedData,
SignTypedDataVersion.V1);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Success:{nativeResultData.data}");
Debug.Log(nativeResultData.data);
}
else
{
ShowToast($"{MethodBase.GetCurrentMethod()?.Name} Failed:{nativeResultData.data}");
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public async void SetChainInfoASync()
{
// call this method to change chain info and auto create public address if that is not existed.
var nativeResultData =
await ParticleAuthService.Instance.SetChainInfoAsync(_chainInfo);
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
Debug.Log(nativeResultData.data);
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}
public void SetChainInfoSync()
{
// call this method to change chain info. You
ParticleNetwork.SetChainInfo(_chainInfo);
}
public void SetiOSModalStyle()
{
// call this method to set embedded safari fullscreen or formsheet,
// default value is formsheet
ParticleAuthServiceInteraction.SetiOSModalPresentStyle(iOSModalPresentStyle.FullScreen);
}
public void SetiOSMediumScreen()
{
// support from iOS 15,
// call this method to set embedded safari medium screen,
// default value is false,
// if you want to use medium screen,
// make sure not call SetiOSModalPresentStyle with FullScreen,
// FullScreen conflicts with medium screen.
ParticleAuthServiceInteraction.SetiOSMediumScreen(true);
}
// set security account config,
// the first parameter is promptSettingWhenSign, default value is 1.
// the second parameter is promptMasterPasswordSettingWhenLogin, default value is 0.
// 0 no prompt
// 1 first time show prompt
// 2 every time show prompt
// 3 force show prompt
ParticleNetwork.SetSecurityAccountConfig(new SecurityAccountConfig(0, 0));
public void HasMasterPassword()
{
var result = ParticleAuthServiceInteraction.HasMasterPassword();
Debug.Log($"HasMasterPassword {result}");
}
public void HasPaymentPassword()
{
var result = ParticleAuthServiceInteraction.HasPaymentPassword();
Debug.Log($"HasPaymentPassword {result}");
}
public void HasSecurityAccount()
{
var result = ParticleAuthServiceInteraction.HasSecurityAccount();
Debug.Log($"HasSecurityAccount {result}");
}
public async void GetSecurityAccount()
{
var nativeResultData = await ParticleAuthService.Instance.GetSecurityAccount();
Debug.Log(nativeResultData.data);
if (nativeResultData.isSuccess)
{
var securityAccount = JsonConvert.DeserializeObject<SecurityAccount>(nativeResultData.data);
var hasSecurityAccount = !string.IsNullOrEmpty(securityAccount.Email) ||
!string.IsNullOrEmpty(securityAccount.Phone);
Debug.Log(securityAccount);
Debug.Log($"HasMasterPassword {securityAccount.HasMasterPassword}, HasPaymentPassword {securityAccount.HasPaymentPassword}, HasSecurityAccount {hasSecurityAccount}");
}
else
{
var errorData = JsonConvert.DeserializeObject<NativeErrorData>(nativeResultData.data);
Debug.Log(errorData);
}
}