Game Economics Module

Coda SDK Game Economics Module's main purpose is to speed up development time of studios by providing them easy to use UI and In-Game Economics solutions.

Enable Game Economics Module

Game Economics Module is disabled by default, in order to start using, please go to CodaSDK -> Externals -> Economics and check the tick box.

Enable Game EconomicsEnable Game Economics

Enable Game Economics

Game Economics Settings

The Economics Canvas Order is set to 30000 by default. You can make changes on it if you need to. This number is the game economic's canvas order, and needs to be in front of your own ui order.
If Development Mode is on Rewarded Ad buttons work without showing the actual ad for testing purposes. Once you make changes please press Save Settings.
You can access the drag and use prefabs such as Navigate To Drag And Use Prefabs Folder. Their usages will be explained later.
The Selected Style selects the prefab style to be used in game. There are 2 different styles which are; Hyper Casual and Realistic.

Prefab StylesPrefab Styles

Prefab Styles

Realistic Style Level Failed ExampleRealistic Style Level Failed Example

Realistic Style Level Failed Example

Hyper Casual Style Level Failed ExampleHyper Casual Style Level Failed Example

Hyper Casual Style Level Failed Example

The Navigate To Drag And Use Prefabs Folder button can be used to directly navigate to the drag and use prefabs folder. In that folder you can select drag and use prefabs such as Currency UI prefab and Shop Button prefab, which can be used in your games by simply dragging them into your canvas.

Navigate To Drag And Use Prefabs FolderNavigate To Drag And Use Prefabs Folder

Navigate To Drag And Use Prefabs Folder

The Item Selection Style determines to allow players to be able to select an item for each categories seperate or select one item for all categories. Multiple item selection example: Each item category can be like -> Hair Style, Dress, Shoes. Player can select an item from each category. Single item selection example: Each item category can be like -> Low tier cars, Medium tier cars, High tier cars. Player can select 1 item and that item will be selected for overall categories. Meaning if you select a car from low tier and then select a car from high tier, your low tier selection will be unticked and your last selection will be ticked. The default mode is single item selection, this is the case for the most of the games.

Item Selection StyleItem Selection Style

Item Selection Style

Clear Shop Prefs

Shop prefs are different than player prefs and saved in persistant data path. If you would like to reset your unlocked items you need to clear them from here. If you see any errors about shop at runtime, try clearing shop prefs.

Creating Shop Item

After placing an Item Icon, Item Name, In Game Prefab and specifying Item Category, you can Create Shop Item. Optionally you can enable 3D Preview and place a 3D prefab which will be seen in the shop screen.

Shop Screen 3D PreviewShop Screen 3D Preview

Shop Screen 3D Preview

Editing Current Shop Items

Created shop items can easly be edited through editor window. After changing item's properties click Edit Item button to edit.

Editing ItemEditing Item

Editing Item

Removing Shop Item

You can remove an existing shop item through editor window by clicking Remove Item button..

Remove ItemRemove Item

Remove Item

Adjusting 3D Preview Prefab

You need to adjust your 3d preview prefab that you would like to show in shop because it's transform properties like rotation and position can not be automatically handled in order it to be able to shown properly in the shop. Go to play mode and drag your preview item under the ShopPreviewCamera and play with it's properties to make sure it is visible, then copy those properties and apply them to the preview prefab.

📘

Note that the position of the preview prefab will be set to 0,0,50. So please consider making your preview prefab to a child with an empty gameobject and adjust your child object's properties.

3D Preview Prefab Location in scene3D Preview Prefab Location in scene

3D Preview Prefab Location in scene

Bad positioned preview item, needs to be adjusted.Bad positioned preview item, needs to be adjusted.

Bad positioned preview item, needs to be adjusted.

Currency Usage

CurrencyCurrency

Currency

Currency Prefab IndicatorCurrency Prefab Indicator

Currency Prefab Indicator

You can drag and drop CurrencyUI by clicking the indicator from editor window above into your canvas or reference it in your script and instantiate it as your wish.

You can subscribe to OnTotalCoinsChanged event as shown to act upon that.

CurrencyUI automatically updates itself when currency is changed.

private void Start()
{
  StartCoroutine(WaitForGameEconomicsController());
}

private IEnumerator WaitForGameEconomicsController()
{
  yield return new WaitUntil(() => GameEconomicsController.Instance != null);
  SubscribeToCoinsChanged();
}

private void SubscribeToCoinsChanged() 
{
  GameEconomicsController.Instance.OnTotalCoinsChanged += OnTotalCoinsChanged;
}

private void OnTotalCoinsChanged(int oldAmount, int newAmount)
{
  //oldAmound -> amount before coin changed
  //newAmount -> current amount after coin changed
  //do stuff
}

Level Failed Screen Usage

Level Failed ScreenLevel Failed Screen

Level Failed Screen

You can create level failed screen as shown below. When "Revive" or "No, Thanks" is clicked, it will automatically notify its listeners and disable itself. Reward type can be changed while you are creating this screen(Revive or Skip Level).

You can subscribe to "OnRetryScreenResulted" delegate to receive callbacks when buttons are clicked.

private void ShowRetryScreen(int currentLevel, CodaRetryScreen.RewardedType rewardType)
{
  GameEconomicsController.Instance.ShowRetryScreen(currentLevel, rewardType);
}

private void SubscribeRetryScreenResult()
{
  GameEconomicsController.Instance.CodaRetryScreen.RetryScreenResulted += OnRetryScreenResulted;
}

private void OnRetryScreenResulted(bool rewardedvideowatched, CodaRetryScreen.RewardType rewardtype)
{
  //do stuff
}

private void SubscribeToRetryScreenOpened()
{
  GameEconomicsController.Instance.CodaRetryScreen.OnScreenOpened += OnScreenOpened;
}

private void SubscribeToRetryScreenClosed()
{
  GameEconomicsController.Instance.CodaRetryScreen.OnScreenClosed += OnScreenClosed;
}

private void OnScreenOpened()
{
  //do stuff when retry screen opened
}

private void OnScreenClosed()
{
  //do stuff when retry screen closed
}

Level Completed Screen Usage

Level Completed ScreenLevel Completed Screen

Level Completed Screen

You can create level complete screen as shown below. When "Get x3" or "No, Thanks" is clicked, it will automatically disable itself. This screen has the currency inside of it's prefab already.

How Does The Reward Amount Set
Rewarded amount is set automatically based on the level number you pass when you create this screen as shown below. It is being calculated according to the best practices being used in hyper-casual games. After level 200, the reward amount is always the same.

Level Completed Screen sends Coda Game Events when buttons are clicked. When rewarded is accepted it dispatches "OnRewardMultiplyAccepted" and when rewarded is rejected it dispatches "OnRewardMultiplyRejected". These two events are being sent with empty parameters. If you would like to get details when buttons are clicked, you need to subscribe to "OnLevelPassed".
"OnLevelPassed" parameters are;

  • currentLevel
  • playerCoins

❗️

Don't Dispatch Level Complete Event

If you are using level complete screen, do not send level completed event described in Set Up Game Events

private void ShowResultScreen(bool success, int currentLevel)
{
  GameEconomicsController.Instance.ShowResultScreen(success, currentLevel);
  CodaGameManager.Instance.GameEventManager.SubscribeGameEvent(GameEventType.OnRewardMultiplyAccepted, OnRewardedAccepted);
  CodaGameManager.Instance.GameEventManager.SubscribeGameEvent(GameEventType.OnRewardMultiplyRejected, OnRewardedRejected);
  CodaGameManager.Instance.GameEventManager.SubscribeGameEvent(GameEventType.OnLevelPassed, OnLevelPassed);
}

private void OnRewardedAccepted(string[] eventData)
{
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyAccepted, OnRewardedAccepted);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyRejected, OnRewardedRejected);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnLevelPassed, OnLevelPassed);
  //do stuff
}
        
private void OnRewardedRejected(string[] eventData)
{
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyAccepted, OnRewardedAccepted);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyRejected, OnRewardedRejected);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnLevelPassed, OnLevelPassed);
  //do stuff          
}

private void OnLevelPassed(string[] eventData)
{
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyAccepted, OnRewardedAccepted);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnRewardMultiplyRejected, OnRewardedRejected);
  CodaGameManager.Instance.GameEventManager.UnsubscribeGameEvent(GameEventType.OnLevelPassed, OnLevelPassed);
  
  var currentLevel = int.Parse(eventData[0]);
  var totalCoins = int.Parse(eventData[1]);
  
  //do stuff
}

private void SubscribeToResultScreenOpened()
{
  GameEconomicsController.Instance.CodaResultScreen.OnScreenOpened += OnScreenOpened;
}

private void SubscribeToResultScreenClosed()
{
  GameEconomicsController.Instance.CodaResultScreen.OnScreenClosed += OnScreenClosed;
}

private void OnScreenOpened()
{
  //do stuff when result screen opened
}

private void OnScreenClosed()
{
  //do stuff when result screen closed
}

Shop Screen Usage

Shop ScreenShop Screen

Shop Screen

You can create shop screen as shown below with code sample. You can also drag and use the ShopButton prefab into your scene directly and it will automatically open shop when clicked. Shop Button also automatically plays badge animation when there is enough money to buy an item.

Shop Button Indicator. It will indicate the prefab's location when clicked.Shop Button Indicator. It will indicate the prefab's location when clicked.

Shop Button Indicator. It will indicate the prefab's location when clicked.

Shop ButtonShop Button

Shop Button

  • Players could spend currency to unlock a random shop item.
  • Players can earn a set amount of currency after watching rewarded video in the shop.
Categories and their item pricesCategories and their item prices

Categories and their item prices

private void ShowShopScreen()
{
    GameEconomicsController.Instance.ShowShopScreen();
}

private void SubscribeToNewItemUnlocked()
{
  GameEconomicsController.Instance.CodaShopScreen.NewItemUnlocked += OnNewItemUnlocked;
}

private void SubscribeToSelectedItemChanged()
{
  GameEconomicsController.Instance.CodaShopScreen.SelectedItemChanged += OnSelectedItemChanged;
}

private void SubscribeToShopOpened()
{
  GameEconomicsController.Instance.CodaShopScreen.OnScreenOpened += OnScreenOpened;
}

private void SubscribeToShoClosed()
{
  GameEconomicsController.Instance.CodaShopScreen.OnScreenClosed += OnScreenClosed;
}

private void OnScreenOpened()
{
  //do stuff when shop opened
}

private void OnScreenClosed()
{
  //do stuff when shop closed
}

private void OnNewItemUnlocked(ShopItemData unlockedItem)
{
  //do stuff
}

private void OnSelectedItemChanged(ShopItemData unlockedItem)
{
  //do stuff
}

Rate Us Popup Usage

GEM rate us popupGEM rate us popup

GEM rate us popup

Game Economics Module also has rate us popup included and works automatically if activated from firebase remote config.

Rate Us Popup Remote Config Parameters

CodaRateUsActive : bool, default is false . If you want to use rate us popup automatically you need to activate this from firebase remote config.
CodaRateUsLevel : int, default is 2. If CodaRateUsActive is set to true then rate us popup will show up after completing level 2. Make sure you sending level events correctly.

These parameters can be modified from firebase remote config.

Manual Usage

GameEconomicsController.Instance.ShowRateUsPopup();

You need to call this method when you want to show up rate us popup manually.

Public APIs

  • GameEconomicsController.Instance.GetSelectedItem();
    Returns the item that is being used
  • GameEconomicsController.Instance.GetItemById(itemId, itemRarity);
    Returns an item data by it's id
  • GameEconomicsController.Instance.GetAllItems();
    Returns all items
  • GameEconomicsController.Instance.UseItemById(itemId, itemRarity);
    Selects and use an item by it's id
  • GameEconomicsController.Instance.UnlockItemById(itemId, itemRarity);
    Unlocks an item by it's id
  • GameEconomicsController.Instance.UnlockRandomItem();
    Unlocks a random item
  • GameEconomicsController.Instance.GetLockedItems();
    Returns all locked items
  • GameEconomicsController.Instance.GetUnlockedItems();
    Returns all unlocked items
  • GameEconomicsController.Instance.GetItemByName(itemName, itemRarity);
    Returns an item data by it's name
  • GameEconomicsController.Instance.UnlockItemByName(itemName, itemRarity);
    Unlocks an item by it's name
  • GameEconomicsController.Instance.GetLevelCoins(levelNo);
    Returns the rewarded coin amount that the game economics will give based on level
  • GameEconomicsController.Instance.AddCoins(coinAmount);
    Adds coins to the account
  • GameEconomicsController.Instance.RemoveCoins(coinAmount);
    Removes coins from account
    * GameEconomicsController.Instance.GetTotalCoins();
    Returns total coins in the account
  • GameEconomicsController.Instance.CloseActiveScreen();
    Closes the active screen
  • GameEconomicsController.Instance.ShowShopScreen();
    Opens shop screen
  • GameEconomicsController.Instance.ShowRetryScreen(levelNo, rewardType);
    Opens retry screen
  • GameEconomicsController.Instance.ShowResultScreen(success, currentLevel);
    Opens result/level complete screen
  • GameEconomicsController.Instance.MinMoneyRequiredToBuyItem();
    Returns the minimum amount that player needs in order to unlock an item

Did this page help you?