Sign in

SCILLBattlePassLevels

public class SCILLBattlePassLevels : SCILLThreadSafety

Overview

This component will instantiate level UI prefabs and will add them as children. Use some sort of auto layout like the vertical, horizontal or grid layout components to build the user interface.

This component will also handle pagination and exposes functions to be connected to buttons click event and properties that you can use to connect buttons that will be hidden and shown depending on the current pagination state.

There are three different types of levels in a battle pass:

  • Locked
  • Unlocked but not complete (current level)
  • Completed

You need to connect prefabs from your Asset browser for each of these states. It’s easier to build three different prefabs rather than having one very complex prefab for these states. Best way is to build a level prefab and then creating prefab variants for the other states.

Please note: The level prefab must have a UnityEngine.UI.Button element somewhere. After instantiating the level prefab it will search for a Button component in the level prefab and will attach a listener to that button. Whenever the level is clicked, the delegate OnSelectedBattlePassLevelChanged will be triggered.

The SCILLRewardPreview will listen on that event and will render a preview of the reward (if available) of the selected level.

Inspector properties

levelPrefab

public SCILLBattlePassLevel levelPrefab;

Connect a SCILLBattlePassLevel prefab that will be used for all completed levels. This prefab will be instantiated for each completed level available in the battle pass and will be added as a child. Make sure that a Button element is available somewhere in the level prefab hierarchy so that the automatic level selection mechanism can do its job.

lockedLevelPrefab

public SCILLBattlePassLevel lockedLevelPrefab;

Connect a SCILLBattlePassLevel prefab that will be used for all locked levels. This prefab will be instantiated for the locked levels in the battle pass and will be added as a child. Make sure that a Button element is available somewhere in the level prefab hierarchy so that the automatic level selection mechanism can do its job.

currentLevelPrefab

public SCILLBattlePassLevel currentLevelPrefab;

Connect a SCILLBattlePassLevel prefab that will be used for the current level. This prefab will be instantiated for the current active level in the battle pass and will be added as a child Make sure that a Button element is available somewhere in the level prefab hierarchy so that the automatic level selection mechanism can do its job.

showLevelInfo

public bool showLevelInfo = true;

Per default, the level number is rendered in each level object. You can set this to false if you don’t want to render the level number for whatever reason.

itemsPerPage

public int itemsPerPage = 5;

Often, the number of levels available in a battle pass cannot be rendered at once on the screen. Use this setting to set the number of levels shown at once. Connect a SCILLPagination object to set the current page.

pagination

public SCILLPagination pagination;

Connect a SCILLPagination object which is part of your hierarchy to allow the user to paginate through your levels. The itemsPerPage in this class determines how many items are rendered for the current page, and the itemsPerPage in the pagination object determin how many levels are skipped for the next level. This allows you to render a couple of more levels than necessary but helps users to understand that there is more if they fade away for example.

Methods

UpdateBattlePassLevelUI

public void UpdateBattlePassLevelUI()

Update the UI if anything changed. This is called automatically whenever required, but you can also trigger a refresh from the outside be calling this function. It will clear the list and rebuild it with all levels available in the SCILLBattlePassManager.

SetCurrentPageIndex

public void SetCurrentPageIndex()

Set the current page index and update the User Interface

OnBattlePassLevelClicked

void OnBattlePassLevelClicked(SCILLBattlePassLevel level)

This script will connect the first Button element found in the level prefabs to this function after they have been instantiated. This function will trigger the OnSelectedBattlePassLevelChanged delegate and will call the Select and Deselect methods of the previous and current levels.

Parameters

level SCILLBattlePassLevel

The SCILLBattlePassLevel component of the level that has been clicked.

OnPrevPage

public void OnPrevPage()

This function will navigate to the previous page by invoking the OnCurrentPageChanged delegate with the new page index. Connect a buttons click function to this to make use of this built in functionality.

OnNextPage

public void OnNextPage()

This function will navigate to the next page by invoking the OnCurrentPageChanged delegate with the new page index. Connect a buttons click function to this to make use of this built in functionality.