Migrating from v3 to v4

This guide will help you migrate your existing BitLabs Unity SDK integration from v3 to v4.

Breaking Changes

1. Callback Architecture

v3 used GameObject-based callbacks with UnitySendMessage. v4 uses inline lambda callbacks.

v3 (Old):

// v3 required GameObject.name for callbacks
BitLabs.CheckSurveys(gameObject.name);

// Then you had a callback method in your MonoBehaviour:
void OnSurveysAvailable(string hasSurveys) {
    if (hasSurveys == "true") {
        Debug.Log("Surveys available!");
    }
}

v4 (New):

// v4 uses inline callbacks
BitLabs.CheckSurveys(
    onSuccess: (hasSurveys) => {
        if (hasSurveys) {
            Debug.Log("Surveys available!");
        }
    },
    onError: (error) => {
        Debug.LogError($"Error: {error}");
    }
);

2. Method Signature Changes

All methods now use callback parameters instead of GameObject names:

Featurev3v4
InitInit(token, userId)Init(token, userId, onSuccess, onError)
CheckSurveysCheckSurveys(gameObjectName)CheckSurveys(onSuccess, onError)
GetSurveysGetSurveys(gameObjectName)GetSurveys(onSuccess, onError)
SetTagsSetTags(tags)No callbacks (kept same signature)
SetRewardCallbackSetOnRewardListener(gameObjectName)SetRewardCallback(onReward)

3. Installation Method

v4 prioritizes UPM (Unity Package Manager) installation over .unitypackage.

v3: Primarily distributed as .unitypackage v4: Recommended installation via UPM (git URL), .unitypackage still available

Migration Steps

1. Update Package

  • If using UPM: Update version in Packages/manifest.json to #v4.0.0(or #upm if you want the latest)
  • If using .unitypackage: Download and import latest from Releases

2. Update Init Call (optional callbacks)

Init now supports optional callbacks for success/error handling:

// v3 (still works in v4):
BitLabs.Init("token", "userId");

// v4 with optional callbacks:
BitLabs.Init("token", "userId",
    onSuccess: () => { /* handle success */ },
    onError: (error) => { /* handle error */ }
);

3. Update Callback Methods

  • Remove GameObject callback methods (e.g., CheckSurveysCallback, GetSurveysCallback, etc...)
  • Replace with inline lambda callbacks in each method call

Example:

// v3:
BitLabs.GetSurveys(gameObject.name);
void GetSurveysCallback(string surveysJson) {
    // Parse and handle surveys
}

// v4:
BitLabs.GetSurveys(
    onSuccess: (surveysJson) => {
        // Parse and handle surveys
    },
    onError: (error) => {
        Debug.LogError($"Error: {error}");
    }
);

4. Update Reward Callback

// Replace this:
BitLabs.SetOnRewardListener(gameObject.name);
// (with RewardCallback method in your script)

// With this:
BitLabs.SetRewardCallback(onReward: (payout) => {
    Debug.Log($"Reward: {payout}");
});

Why This Change?

The new callback-based architecture provides:

  • Better encapsulation: No need to expose GameObject in hierarchy
  • Type safety: Compile-time checking of callback signatures
  • Flexibility: Callbacks can be defined inline or as separate methods
  • Modern C# patterns: Uses delegates/lambdas standard in Unity development