SCILLPersonalChallenges
public class SCILLPersonalChallenges : SCILLThreadSafety
Overview
This component is derived from the SCILLThreadSafety class. It handles all communication with the SCILL backend to load and update personal challenges in real time. It also implements user interfaces.
This class does three things:
- Load personal challenges with the SCILLClient.GetPersonalChallenges method
- Instantiate the prefab set in categoryPrefab property for each ChallengeCategory object contained in the response and add as child to the transform.
- Listen on server-side changes and update the challenges state in the UI
The categoryPrefab must have a SCILLCategoryItem attached that will create instances of the challengePrefab and add them as childs to category game object instance or if provided to the SCILLCategoryItem transform provided in the challenge category prefab.
In the end, you’ll have this hierarchy:
- Container
- Challenge Category 1
- Header
- Challenge 1
- Challenge 2
- …
- Challenge Category 2
- Header
- Challenges Container
- Challenge 1
- Challenge 2
- ..
- …
- Challenge Category 1
Inspector Properties
categoryPrefab
public SCILLCategoryItem categoryPrefab;
Set this to a prefab having that SCILLCategoryItem component attached. It will be instantiated for each challenge category. If you don’t want to have UI for categories you can just use an empty Game Object as a prefab and attach the SCILLCategoryItem component to it.
challengePrefab
public SCILLChallengeItem challengePrefab;
A prefab with the SCILLChallengeItem attached. It will be instantiated for each challenge in the category and will be added as a child of the category prefab.
Methods
UpdatePersonalChallengesList
This function loads the challenges with the SCILLClient.GetPersonalChallenges method and rebuilds the UI. It updates all child elements for categories and challenges. You can call that function whenever you like.
public async void UpdatePersonalChallengesList();
UnlockPersonalChallenge
Unlocks the personal challenge provided and will update UI elements if required. The default prefabs connect buttons to these functions to trigger unlocking challenges by the user. You can also do that for the user automatically.
public void UnlockPersonalChallenge(Challenge challenge)
Parameters
challenge Challenge
The challenge you want to unlock
ActivatePersonalChallenge
Activates the personal challenge provided and will update UI elements if required. The default prefabs connect buttons to these functions to trigger activating challenges by the user. You can also do that for the user automatically.
public void ActivatePersonalChallenge(Challenge challenge)
Parameters
challenge Challenge
The challenge you want to activate
ClaimPersonalChallengeReward
public void ClaimPersonalChallengeReward(Challenge challenge)
Claims the reward for the personal challenge provided and will update UI elements if required. The default prefabs connect buttons to these functions to trigger claiming the reward by the user. You can also do that for the user automatically.
Calling this function will mark the challenge as claimed and if the challenge is repeatable
it will be available again
for the next round. SCILL Backend will send a realtime notification to inform the client. You can also set a Webhook
in the Admin Panel to get a notification in the backend to unlock the reward there (for example if you need to send
an email).
This function will call the OnPersonalChallengeRewardClaimed function that you can override to unlock the reward.
Parameters
challenge Challenge
The challenge you want to claim
CancelPersonalChallenge
public void CancelPersonalChallenge(Challenge challenge)
Cancels the personal challenge provided and will update UI elements if required. The default prefabs connect buttons to these functions to trigger canceling the challenge by the user.
Calling this function will mark the challenge as cancelled
(type cancelled) and if the challenge is repeatable
it will be available again
for the next round. Otherwise the challenge will not be reported again. SCILL Backend will send a realtime notification to inform the client. You can also set a Webhook
in the Admin Panel to get a notification in the backend to unlock the reward there (for example if you need to send
an email).
Parameters
challenge Challenge
The challenge you want to cancel
Virtual methods
OnPersonalChallengeRewardClaimed
protected virtual void OnPersonalChallengeRewardClaimed(Challenge challenge)
Called whenever the personal challenges has been marked as claimed in SCILL. Override this function to implement your own business logic to unlock the reward set in the challenge provided.