API Quick Reference

A quick reference for the CMS API.

M8 CMS SDK - API Quick Reference

Instant Access

C#
using M8CMS;

M8CMSManager cmsManager = M8CMSManager.Instance;

Initialization

MethodReturnsDescription
IsInitialized()boolCheck SDK initialization status
IsGameDataLoaded()boolCheck if game data is loaded
InstanceM8CMSManagerGet singleton instance

Getting Data

MethodReturnsDescription
GetCurrentGameData()GameDataGet complete game data
GetLevelByIndex(int index)LevelGet specific level
GetCollectionByIndex(int index)CollectionItemGet specific collection
GetAllLevels()List<Level>Get all levels
GetAllCollections()List<CollectionItem>Get all collections

Loading Content (Async)

Levels

MethodReturnsDescription
GetLevelImageAsync(int index)Task<Texture2D>Get level image texture
GetLevelSpriteAsync(int index)Task<Sprite>Get level image sprite
GetLevelVideoAsync(int index)Task<byte[]>Get level video bytes

Collections

MethodReturnsDescription
GetCollectionImageAsync(int index)Task<Texture2D>Get collection image texture
GetCollectionSpriteAsync(int index)Task<Sprite>Get collection image sprite
GetCollectionVideoAsync(int index)Task<byte[]>Get collection video bytes

Content Status

MethodReturnsDescription
IsLevelContentReady(int index)boolCheck if level content is ready
IsCollectionContentReady(int index)boolCheck if collection content is ready

Content Consumption

MethodDescription
ConsumeLevelContent(int index)Notify SDK that player reached this level
ConsumeCollectionContent(int index)Notify SDK that player reached this collection

Note: Triggers automatic downloading of upcoming content based on settings.


Cache Management

MethodReturnsDescription
ClearImageCache()voidClear all cached images
ClearVideoCache()voidClear all cached videos
ClearPreloadCache()voidClear preload cache
GetImageCacheStats()(int, long)Get image cache stats (count, size MB)
GetVideoCacheStats()(int, long)Get video cache stats (count, size MB)
GetPreloadCacheStats()PreloadCacheStatsGet preload cache statistics

Version Management

MethodReturnsDescription
GetAllVersionsAsync()Task<List<(...)>>Get all available versions
GetLatestVersionAsync()Task<(string, Version)>Get latest version
GetLiveVersionAsync()Task<Version>Get live version
SetVersionSelectionMode(mode)voidSet version selection mode
SetSelectedVersionName(name)voidSet specific version name
GetVersionSelectionMode()VersionSelectionModeGet current selection mode
GetSelectedVersionName()stringGet selected version name
GetCurrentVersionId()stringGet current version ID
GetAvailableVersions()List<(...)>Get cached versions
LoadGameDataForVersionAsync(id)Task<bool>Load specific version

Events

Static Events (Global)

C#
M8CMSManager.OnInitializationComplete += (bool success) => {};
M8CMSManager.OnGameDataLoaded += (GameData data) => {};
M8CMSManager.OnError += (string error) => {};

Instance Events

C#
cmsManager.OnLevelContentReady += (int index, bool ready) => {};
cmsManager.OnCollectionContentReady += (int index, bool ready) => {};
cmsManager.OnContentLoadError += (int index, string error) => {};
cmsManager.OnNetworkStateChanged += (bool available) => {};

Helper Methods

C#
using M8CMS.Helpers;

// Check content availability without triggering downloads
bool available = M8CMSContentHelper.IsContentAvailableForLevel(index, cmsManager);
bool available = M8CMSContentHelper.IsContentAvailableForCollection(index, cmsManager);

Data Models

Level

C#
public class Level
{
    public int index;
    public string levelType;        // "normal", "boss", "tutorial"
    public string difficulty;        // "normal", "hard"
    public string gridSize;
    public int rewardCoin;
    public string imageUrl;
    public string videoUrl;
    // ...
}

CollectionItem

C#
public class CollectionItem
{
    public int index;
    public string name;
    public string imageUrl;
    public string videoUrl;
    public int startLevel;
    public int endLevel;
    // ...
}

Common Patterns

Pattern 1: Load Level Image

C#
async void LoadLevelImage(int levelIndex)
{
    var sprite = await cmsManager.GetLevelSpriteAsync(levelIndex);
    if (sprite != null) {
        myImage.sprite = sprite;
    }
}

Pattern 2: Track Player Progress

C#
void StartLevel(int levelIndex)
{
    cmsManager.ConsumeLevelContent(levelIndex);
    // SDK auto-downloads upcoming levels
}

Pattern 3: Check Content Status

C#
void UpdateLevelButtons()
{
    foreach (var level in levels) {
        bool ready = cmsManager.IsLevelContentReady(level.index);
        button.interactable = ready;
    }
}

Pattern 4: Handle Events

C#
void OnEnable()
{
    M8CMSManager.OnGameDataLoaded += OnDataLoaded;
    cmsManager.OnLevelContentReady += OnLevelReady;
}

void OnDisable()
{
    M8CMSManager.OnGameDataLoaded -= OnDataLoaded;
    cmsManager.OnLevelContentReady -= OnLevelReady;
}

void OnDataLoaded(GameData data) {
    // Process data
}

void OnLevelReady(int index, bool ready) {
    // Update UI
}

Settings (Inspector)

SettingTypeDefaultDescription
appKeystring""Your game's unique identifier
autoInitializebooltrueAuto-initialize on Start
downloadImagesVideosOnStartint0Items to download immediately
downloadNewLevelsBeforeXLevelint1Levels to pre-download ahead
enableAutoDownloadbooltrueEnable automatic downloads
maxConcurrentDownloadsint1Max simultaneous downloads
maxCacheSizeint40Max cache size (MB)
enableBuiltInContentboolfalseUse offline content
enableDebugLogsbooltrueEnable debug logging

Error Handling

C#
void Start()
{
    M8CMSManager.OnError += (string error) => {
        Debug.LogError($"SDK Error: {error}");
        // Show user-friendly message
    };
    
    cmsManager.OnContentLoadError += (int index, string error) => {
        Debug.LogError($"Failed to load content for {index}: {error}");
        // Retry or show fallback
    };
}

Quick Tips

  1. ✅ Always use await or coroutines with async methods
  2. ✅ Call ConsumeLevelContent() when player reaches a level
  3. ✅ Subscribe to events in OnEnable(), unsubscribe in OnDisable()
  4. ✅ Check IsInitialized() before using SDK
  5. ✅ Use IsLevelContentReady() before displaying content
  6. ✅ Let SDK handle caching - don't duplicate logic
  7. ✅ Set appropriate cache size limits
  8. ✅ Enable debug logs during development

See SDK_DOCUMENTATION.md for complete documentation.