Admin Panel

SCILLBattlePassManager

public class SCILLBattlePassManager : SCILLThreadSafety

Overview

This class is designed as a “Singleton” and should be attached to the same GameObject that you have SCILLManager attached. It will completely manage battle passes. It selects the first available active battle pass and selects that battle pass.

This class is derived from the SCILLThreadSafety class.

Add this component to the same GameObject that has the SCILLManager attached. If you want to customize Battle Pass selection, derive a new class from this class and override SelectBattlePass function which receives the array of available battle passes from the backend to return the selected battle pass.

This class handles all data required for displaying and acting on claimed battle pass level rewards. Use the various delegates to connect your own classes to the manager. In this documentation we provide some example code. Our code and all prefabs connect to the manager with these delegates. There is no need to connect prefabs or other things together in Unity - just drop in the prefabs, and they will work automatically as they just listen on the delegates and update their UI whenever data changes and respective delegates are called.

Properties

Instance

public static SCILLBattlePassManager Instance { get; private set; }

As this class is designed as a singleton you can use this getter to get a reference to the instance. It allows you to access the SCILLBattlePassManager from everywhere in your code.

SelectedBattlePass

public BattlePass SelectedBattlePass;

The class stores a reference to the selected battle pass (see SelectBattlePass) that you can access with this property.

BattlePassLevels

public List<BattlePassLevel> BattlePassLevels;

The class stores a reference to the levels loaded for the selected battle pass.

Delegates

SCILLBattlePassManager implements various delegates that get called whenever data changes that the manager handles for you. The basic idea is, that you can just write some scripts, listen to the static delegates provided by the manager to implement your business logic or UI. You don’t need to connect all the various pieces together in Unity, instead you just need to make sure to have SCILLBattlePassManager object in the scene. The rest will be handled by the delegates.

OnBattlePassUpdatedFromServer

Add a listener to this delegate which is called whenever the Battle Pass Manager selection changes. If users can switch between multiple battle passes, the delegate will be called serving the new selected battle pass. SCILLBattlePass adds a listener to automatically update UI once the manager selection changes.

public static event BattlePassUpdatedFromServerAction OnBattlePassUpdatedFromServer;
Definition
public delegate void BattlePassUpdatedFromServerAction(BattlePass battlePass);
Example
Using OnBattlePassLevelsUpdatedFromServer
public class ExampleScript : MonoBehaviour
    private BattlePass battlePass;

    private void OnEnable()
    {
        // Make sure we set an already available battle pass (i.e. if this component got activated later)
        if (SCILLBattlePassManager.Instance)
        {
            battlePass = SCILLBattlePassManager.Instance.SelectedBattlePass;
        }
        
        // Make sure we update we update our local instance of the (selected) battle pass changes on server side
        SCILLBattlePassManager.OnBattlePassUpdatedFromServer += OnBattlePassUpdatedFromServer;
    }
    
    private void OnDestroy()
    {
        // Remove listener once this component is destroyed
        SCILLBattlePassManager.OnBattlePassUpdatedFromServer -= OnBattlePassUpdatedFromServer;
    }

    private void OnBattlePassUpdatedFromServer(BattlePass battlePass)
    {
        // Update local instance and update UI
        this.battlePass = battlePass;
        UpdateUI();
    }
    
    private void UpdateUI()
    {
        // Update user interface
    }
}

OnBattlePassLevelsUpdatedFromServer

Add a listener to this delegate if you want to be informed whenever the battle pass levels change. Whenever a level is unlocked or claimed, this function will be called. SCILLBattlePassLevels listens on those changes to update UI of the levels.

public static event BattlePassLevelsUpdatedFromServerAction OnBattlePassLevelsUpdatedFromServer;
Definition
public delegate void BattlePassLevelsUpdatedFromServerAction(List<BattlePassLevel> battlePassLevels);
Example
Using OnBattlePassLevelsUpdatedFromServer
public class ExampleScript : MonoBehaviour
    private List<BattlePassLevel> _levels;
    
    private void OnEnable()
    {
        // Set levels if levels have already been loaded
        if (SCILLBattlePassManager.Instance)
        {
            _levels = SCILLBattlePassManager.Instance.BattlePassLevels;            
        }
        // Make sure we update the levels once they change on server side
        SCILLBattlePassManager.OnBattlePassLevelsUpdatedFromServer += OnBattlePassLevelsUpdatedFromServer;
        
        UpdateBattlePassLevelUI();        
    }
    
    private void OnDestroy()
    {
        SCILLBattlePassManager.OnBattlePassLevelsUpdatedFromServer -= OnBattlePassLevelsUpdatedFromServer;
    }    

    private void OnBattlePassLevelsUpdatedFromServer(List<BattlePassLevel> battlePassLevels)
    {
        this._levels = battlePassLevels;
        UpdateBattlePassLevelUI();
    }
    
    private UpdateBattlePassLevelUI()
    {
        // Do whatever you have to do to update the UI
    }
}

OnBattlePassChallengeUpdate

Whenever a challenge in the battle pass changes, i.e. the type changes indicating that a challenge got activated due to the level being unlocked or if the progress changes, this delegate will be called.

public static event BattlePassChallengeUpdateAction OnBattlePassChallengeUpdate;
Definition
public delegate void BattlePassChallengeUpdateAction(BattlePassChallengeChangedPayload challengeChangedPayload);
Example
Using OnBattlePassChallengeUpdate
public class ExampleScript : MonoBehaviour
    public BattlePassLevelChallenge challenge;
    
    public Slider challengeProgressSlider;
    
    // Start is called before the first frame update
    void Start()
    {
        UpdateUI();
    }
    
    private void OnEnable()
    {
        SCILLBattlePassManager.OnBattlePassChallengeUpdate += OnBattlePassChallengeUpdate;
    }
    
    private void OnDestroy()
    {
        SCILLBattlePassManager.OnBattlePassChallengeUpdate -= OnBattlePassChallengeUpdate;
    }

    private void OnBattlePassChallengeUpdate(BattlePassChallengeChangedPayload challengeChangedPayload)
    {
        // Update local challenge object if it has the same id
        if (challengeChangedPayload.new_battle_pass_challenge.challenge_id == challenge.challenge_id)
        {
            challenge.type = challengeChangedPayload.new_battle_pass_challenge.type;
            challenge.user_challenge_current_score =
                challengeChangedPayload.new_battle_pass_challenge.user_challenge_current_score;
            UpdateUI();   
        }
    }

    public void UpdateUI()
    {
        // Update local challenge UI
        if (challengeProgressSlider)
        {
            if (challenge.challenge_goal > 0 && challenge.user_challenge_current_score > 0)
            {
                if (challenge.challenge_goal_condition == 0)
                {
                    // If the challenge_goal_condition is 0 then counter must be greater than the goal, so progress is the
                    // relation between the counter and the goal
                    
                    challengeProgressSlider.value = (float) ((float) challenge.user_challenge_current_score /
                                                             (float) challenge.challenge_goal);
                }
                else if (challenge.challenge_goal_condition == 1)
                {
                    // If the challenge_goal_condition is 1 then counter must be smaller than the goal, so progress is the
                    // inverted relation between the counter and the goal
                    
                    challengeProgressSlider.value = (float) 1.0f / ((float) challenge.user_challenge_current_score /
                                                             (float) challenge.challenge_goal);
                }
            }
            else
            {
                challengeProgressSlider.value = 0;
            }
        }
    }
}

OnBattlePassLevelRewardClaimed

This delegate is called whenever a levels reward is claimed. If you want to unlock rewards within your client you just need to listen to this delegate (see example below) to unlock that reward. Use Webhooks if you want to unlock rewards in your backend.

public static event BattlePassLevelRewardClaimedAction OnBattlePassLevelRewardClaimed;
Definition
public delegate void BattlePassLevelRewardClaimedAction(BattlePassLevel level);
Example
Using OnBattlePassLevelRewardClaimed
public class ExampleScript : MonoBehaviour
    
    private void OnEnable()
    {
        SCILLBattlePassManager.OnBattlePassLevelRewardClaimed += OnBattlePassLevelRewardClaimed;
    }

    private void OnDisable()
    {
        SCILLBattlePassManager.OnBattlePassLevelRewardClaimed -= OnBattlePassLevelRewardClaimed;
    }
    
    private void OnBattlePassLevelRewardClaimed(BattlePassLevel level)
    {
        // Use level.level_reward_type and level.reward_amount to find our what to unlock for the user
    }
}

Methods

SelectBattlePass

protected virtual BattlePass SelectBattlePass(List<BattlePass> battlePasses)

This function receives a List of BattlePass objects and returns one BattlePass object that should be used within the game. You can override this function to adjust behavior of this class.

Parameters

battlePasses List<BattlePass>

A list of available batte passes loaded from the SCILL Backend with the SCILLClient.GetBattlePasses function.

Returns

Returns the access token as a string which is stored and reused for all further requests to the SCILL backend.

UpdateBattlePassLevelsFromServer

public async void UpdateBattlePassLevelsFromServer()

Use this function to reload the battle pass levels from the SCILL server and to trigger the OnBattlePassLevelsUpdatedFromServer event.

Returns

Returns the User ID which is then used in a call to GenerateAccessToken to generate the access token.

ClaimBattlePassLevelReward

public async void ClaimBattlePassLevelReward(BattlePassLevel level)

Call this function to claim the reward attached to the battle pass level. It will call the SCILLClient.ClaimBattlePassReward function and will trigger the OnBattlePassLevelRewardClaimed event.