Skip to content

Conditions

Conditional logic can be applied to any document. Currently, we use it to run GameEvents. Any condition starts with one of 2 logical operators And / Or. Then you can add any other types of conditions. The conditions can be as complex and nested as you want.

  • Dates Range, Day Of The Week, and Time Of The Day are conditions based on a specific time.
  • ABTest Condition checks if the user was assigned to a specific A/B Test and Variant.
  • Active Event triggers only if the specified GameEvent is active right now.
  • Segment Condition checks if the user belongs to a specific Segment.
  • Revenue checks if the user has generated a specific amount of in-app/ads revenue(count) during certain days.
  • Was Item Purchased checks if a StoreItem was purchased.
  • Primitive allows you to use any custom User Properties.

Screenshot

  • Country checks if the user is from the specified country.

Note: Please use this Country condition under the System category instead of getting the custom Country User Property from Primitive condition.

Screenshot

Section for programmers

GameEvent documents take care of the conditional logic. However, if you want to add conditions to your documents, here are the steps you need to take:

  • Let's say you have a Document, named MyDocument with a conditional parameter Condition.
  • Use interface for your class IConditionsListener which will be responsible for the logic. Usually, it's some Manager.
  • Call the following method LiveOps.General.ConditionSubscribe(MyDocument.Condition, MyDocument, this, PassType.False);.
  • The default condition value (PassType.True or PassType.False) is the last parameter in the method above. Whenever the condition state changes, one of the following methods from the interface IConditionsListener is called on your Manager:

    • public void ConditionPassed(object data);
    • public void ConditionFailed(object data);
  • The data parameter in the methods above is the second parameter you send to the LiveOps.General.ConditionSubscribe - it's MyDocument in our example.

  • At any time you can check Condition state by calling LiveOps.General.CanPassCondition(MyDocument.Condition);
public class Manager : IConditionsListener
{
    private void Start()
    {
        foreach (var ev in DataManager.GameEvents)
            LiveOps.General.ConditionSubscribe(ev.Condition, ev, this, IsGameEventActive(ev));
    }

    public void ConditionPassed(object data)
    {
        if (data is GameEvent gameEvent)
            StartEvent(gameEvent);
    }

    public void ConditionFailed(object data)
    {
        if (data is GameEvent gameEvent)
            StopEvent(gameEvent);
    }

    ....
    ....
    ....
}

Custom conditions

  1. Create a new Template inherited from CustomCondition to add your condition. For example TestCondition.
  2. Mark it with Partial flag to be able to add methods.
  3. After the code is generated, add a new class inside of the Balancy folder (due to the amsdef file) but outside of the AutoGeneratedCode folder (to avoid data loss after the following code generation). For example, you can make a new folder Assets/Balancy/Custom and put all your custom scripts there.
public partial class TestCondition : SmartObjects.Conditions.Custom
{
    public override bool CanPass(IUserConditionEnvironment environment)
    {
        //TODO return true or false  
    }

    protected override void SubscribeForPrivateInfo(IUserConditionEnvironment environment)
    {
        //TODO subscribe for all the required events and call OnUpdate() method to force conditions to recalculate
    }

    protected override void UnsubscribeFromPrivateInfo(IUserConditionEnvironment environment)
    {
        //TODO clean up all subscriptions
    }
}