M8 CMS SDK - API Quick Reference
Instant Access
C#using M8CMS; M8CMSManager cmsManager = M8CMSManager.Instance;
Initialization
| Method | Returns | Description |
|---|---|---|
IsInitialized() | bool | Check SDK initialization status |
IsGameDataLoaded() | bool | Check if game data is loaded |
Instance | M8CMSManager | Get singleton instance |
Getting Data
| Method | Returns | Description |
|---|---|---|
GetCurrentGameData() | GameData | Get complete game data |
GetLevelByIndex(int index) | Level | Get specific level |
GetCollectionByIndex(int index) | CollectionItem | Get specific collection |
GetAllLevels() | List<Level> | Get all levels |
GetAllCollections() | List<CollectionItem> | Get all collections |
Loading Content (Async)
Levels
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
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
| Method | Returns | Description |
|---|---|---|
IsLevelContentReady(int index) | bool | Check if level content is ready |
IsCollectionContentReady(int index) | bool | Check if collection content is ready |
Content Consumption
| Method | Description |
|---|---|
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
| Method | Returns | Description |
|---|---|---|
ClearImageCache() | void | Clear all cached images |
ClearVideoCache() | void | Clear all cached videos |
ClearPreloadCache() | void | Clear preload cache |
GetImageCacheStats() | (int, long) | Get image cache stats (count, size MB) |
GetVideoCacheStats() | (int, long) | Get video cache stats (count, size MB) |
GetPreloadCacheStats() | PreloadCacheStats | Get preload cache statistics |
Version Management
| Method | Returns | Description |
|---|---|---|
GetAllVersionsAsync() | Task<List<(...)>> | Get all available versions |
GetLatestVersionAsync() | Task<(string, Version)> | Get latest version |
GetLiveVersionAsync() | Task<Version> | Get live version |
SetVersionSelectionMode(mode) | void | Set version selection mode |
SetSelectedVersionName(name) | void | Set specific version name |
GetVersionSelectionMode() | VersionSelectionMode | Get current selection mode |
GetSelectedVersionName() | string | Get selected version name |
GetCurrentVersionId() | string | Get 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)
| Setting | Type | Default | Description |
|---|---|---|---|
appKey | string | "" | Your game's unique identifier |
autoInitialize | bool | true | Auto-initialize on Start |
downloadImagesVideosOnStart | int | 0 | Items to download immediately |
downloadNewLevelsBeforeXLevel | int | 1 | Levels to pre-download ahead |
enableAutoDownload | bool | true | Enable automatic downloads |
maxConcurrentDownloads | int | 1 | Max simultaneous downloads |
maxCacheSize | int | 40 | Max cache size (MB) |
enableBuiltInContent | bool | false | Use offline content |
enableDebugLogs | bool | true | Enable 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
- ✅ Always use
awaitor coroutines with async methods - ✅ Call
ConsumeLevelContent()when player reaches a level - ✅ Subscribe to events in
OnEnable(), unsubscribe inOnDisable() - ✅ Check
IsInitialized()before using SDK - ✅ Use
IsLevelContentReady()before displaying content - ✅ Let SDK handle caching - don't duplicate logic
- ✅ Set appropriate cache size limits
- ✅ Enable debug logs during development
See SDK_DOCUMENTATION.md for complete documentation.