It processes PC SDK’s API mostly unsynchronized not to disturb the game engine and game logic.
It loads the result of the API call on the PC SDK’s internal queue. It executes the registered callback when the game calls the RunCallback method to process the result of the API call. Usually, the RunCallback method’s call is input through a coroutine, and you can set the call cycle.
private IEnumerator RunCallback(float intervalSeconds)
{
WaitForSeconds wfs = new WaitForSeconds(intervalSeconds);
while (true)
{
StovePC.RunCallback();
yield return wfs;
}
}
A coroutine is started via the MonoBehaviour.StartCoroutine
method and is usually a PC SDK initialization. It starts with success and stops if PC SDK shutdown succeeds. There is a way to use a member variable to stop the RunCallback coroutine after the successful PC SDK shutdown.
private Coroutine runcallbackCoroutine;
You can operate the runcallbackCoroutine
declared as a member variable in the game project like a timer by using the StartCoroutine
and StopCoroutine
functions as shown in the code below.
public void ToggleRunCallback_ValueChanged(bool isOn)
{
if (isOn)
{
float intervalSeconds = 1f;
runcallbackCoroutine = StartCoroutine(RunCallback(intervalSeconds));
WriteLog("RunCallback Start");
}
else
{
if (runcallbackCoroutine != null)
{
StopCoroutine(runcallbackCoroutine);
runcallbackCoroutine = null;
WriteLog("RunCallback Stop");
}
}
}
To initialize PC SDK, start with filling in the values for the StovePCConfig
and StovePCCallback
structures and call the StovePC.Initialize
method.
Refer to the code below to fill in each field value within the StovePCConfig
structure.
StovePCConfig config = new StovePCConfig
{
Env = "live",
AppKey = "YOUR_APP_KEY",
AppSecret = "YOUR_SECRET_KEY",
GameId = "YOUR_GAME_ID",
LogLevel = StovePCLogLevel.Dubug,
LogPath = ""
};
<aside>
💡 You must change "YOUR_APP_KEY", "YOUR_SECRET_KEY", and "YOUR_GAME_ID" to data with the key-value issued by STOVE Studio
. If you call the StovePC.Initialize
method without logging in to the stove launcher, an error occurs. Run the stove launcher before logging in.
</aside>
Interworking between the game and the PC SDK uses a C# delegate. You must define delegate methods connected to the callbacks of the StovePCCallback
class below for games.
public class StovePCCallback
{
// Callback called when errors occur in StovePCSDK
public StovePCErrorDelegate OnError;
// Callback called when the PC SDK initialization is complete
public StovePCInitializationCompleteDelegate OnInitializationComplete;
// Callback called when the GetToken process is complete
public StovePCTokenDelegate OnToken;
// Callback called when the GetUser process is complete
public StovePCUserDelegate OnUser;
// Callback called when the GetOwnership process is complete
public StovePCOwnershipDelegate OnOwnership;
}
Be careful so that the StovePCCallback
object is maintained until it terminates PC SDK. The PC SDK cannot internally call a callback if you collect the StovePCCallback
object as garbage.
To satisfy this condition, you can define the StovePCCallback
class as a member variable. To satisfy this point, you can solve this by declaring the StovePCCallback
class as a member variable of the game project class to prevent garbage collection.
private StovePCCallback callback;
// StovePCCallback class instance created
this.callback = new StovePCCallback
{
OnError = new StovePCErrorDelegate(this.OnError),
OnInitializationComplete = new StovePCInitializationCompleteDelegate(this.OnInitializationComplete),
OnToken = new StovePCTokenDelegate(this.OnToken),
OnUser = new StovePCUserDelegate(this.OnUser),
OnOwnership = new StovePCOwnershipDelegate(this.OnOwnership)
};