Untitled
unknown
plain_text
2 years ago
1.8 kB
12
Indexable
using UnityEngine;
using HutongGames.PlayMaker;
using System.Threading.Tasks;
using TcgEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.ScriptControl)]
[Tooltip("Get coins value from UserData and store it in a Playmaker global float variable.")]
public class GetCoinsValue : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Playmaker global float variable to store the retrieved coins value.")]
public FsmFloat coinsValue;
private bool userDataLoaded = false;
public override async void OnEnter()
{
// Load UserData asynchronously if not already loaded
if (!userDataLoaded)
{
await LoadUserDataAsync();
}
if (Authenticator.Get().UserData != null)
{
// Get the UserData from the Authenticator
UserData userData = Authenticator.Get().UserData;
// Convert coins value to float and store it in the Playmaker global variable
coinsValue.Value = (float)userData.coins;
// Exit the action
Finish();
}
else
{
Debug.LogWarning("UserData not available. Make sure you are logged in.");
// You might want to handle this case based on your project requirements.
Finish();
}
}
private async Task LoadUserDataAsync()
{
// Load UserData asynchronously
await Authenticator.Get().LoadUserData();
// Mark UserData as loaded
userDataLoaded = true;
}
}
}Editor is loading...