@oasiz/sdk 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -402,7 +402,9 @@ import {
|
|
|
402
402
|
import type {
|
|
403
403
|
GameState,
|
|
404
404
|
HapticType,
|
|
405
|
+
LogOverlayEntry,
|
|
405
406
|
LogOverlayHandle,
|
|
407
|
+
LogOverlayLevel,
|
|
406
408
|
LogOverlayOptions,
|
|
407
409
|
ShareRoomCodeOptions,
|
|
408
410
|
Unsubscribe,
|
|
@@ -421,6 +423,59 @@ C# API and **WebGL-only** `OasizBridge.jslib` live in this repository at **`pack
|
|
|
421
423
|
2. Ensure the **WebGL** platform is selected for release builds; the `.jslib` under `Runtime/Plugins/WebGL/` is included automatically for WebGL.
|
|
422
424
|
3. Add an **`OasizSDK`** component to a persistent GameObject early (for example a bootstrap scene), **or** rely on `OasizSDK.Instance` which creates a `DontDestroyOnLoad` object. The component registers listeners for `oasiz:pause`, `oasiz:resume`, `oasiz:back`, and `oasiz:leave` via `SendMessage`.
|
|
423
425
|
|
|
426
|
+
### Quick start
|
|
427
|
+
|
|
428
|
+
```csharp
|
|
429
|
+
using Oasiz;
|
|
430
|
+
using UnityEngine;
|
|
431
|
+
|
|
432
|
+
public class GameManager : MonoBehaviour
|
|
433
|
+
{
|
|
434
|
+
void Start()
|
|
435
|
+
{
|
|
436
|
+
// Ensure the singleton is initialized early
|
|
437
|
+
_ = OasizSDK.Instance;
|
|
438
|
+
|
|
439
|
+
// Subscribe to lifecycle events
|
|
440
|
+
OasizSDK.OnPause += OnPause;
|
|
441
|
+
OasizSDK.OnResume += OnResume;
|
|
442
|
+
|
|
443
|
+
// Offset UI for the host's top safe area
|
|
444
|
+
float safeTop = OasizSDK.SafeAreaTop;
|
|
445
|
+
Debug.Log($"Safe area top: {safeTop}px");
|
|
446
|
+
|
|
447
|
+
// Emit score normalization anchors
|
|
448
|
+
OasizSDK.EmitScoreConfig(new ScoreConfig(
|
|
449
|
+
new ScoreAnchor(10, 100),
|
|
450
|
+
new ScoreAnchor(30, 300),
|
|
451
|
+
new ScoreAnchor(75, 600),
|
|
452
|
+
new ScoreAnchor(200, 950)
|
|
453
|
+
));
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
void OnGameOver(int finalScore)
|
|
457
|
+
{
|
|
458
|
+
OasizSDK.SubmitScore(finalScore);
|
|
459
|
+
OasizSDK.FlushGameState();
|
|
460
|
+
OasizSDK.SetLeaderboardVisible(true);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
void OnGameplayStart()
|
|
464
|
+
{
|
|
465
|
+
OasizSDK.SetLeaderboardVisible(false);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
void OnPause() => Time.timeScale = 0f;
|
|
469
|
+
void OnResume() => Time.timeScale = 1f;
|
|
470
|
+
|
|
471
|
+
void OnDestroy()
|
|
472
|
+
{
|
|
473
|
+
OasizSDK.OnPause -= OnPause;
|
|
474
|
+
OasizSDK.OnResume -= OnResume;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
424
479
|
### API parity (TypeScript → C#)
|
|
425
480
|
|
|
426
481
|
| HTML5 (`@oasiz/sdk`) | Unity (`Oasiz` namespace) |
|
|
@@ -438,21 +493,71 @@ C# API and **WebGL-only** `OasizBridge.jslib` live in this repository at **`pack
|
|
|
438
493
|
| `oasiz.leaveGame()` | `OasizSDK.LeaveGame()` |
|
|
439
494
|
| `oasiz.shareRoomCode` | `OasizSDK.ShareRoomCode(string, ShareRoomCodeOptions)` |
|
|
440
495
|
| `oasiz.openInviteModal()` | `OasizSDK.OpenInviteModal()` |
|
|
441
|
-
| `oasiz.gameId` / `roomCode` /
|
|
442
|
-
|
|
|
496
|
+
| `oasiz.gameId` / `roomCode` / ... | `OasizSDK.GameId` / `RoomCode` / `PlayerName` / `PlayerAvatar` |
|
|
497
|
+
| -- | `OasizSDK.EmitScoreConfig(ScoreConfig)` → `window.emitScoreConfig` (Unity-only helper for normalized score UI) |
|
|
443
498
|
| `oasiz.enableLogOverlay` | `OasizSDK.EnableLogOverlay(LogOverlayOptions)` (see note below) |
|
|
499
|
+
| -- | `OasizSDK.AppendLogOverlay(level, message, stackTrace)` (see note below) |
|
|
500
|
+
|
|
501
|
+
### Types
|
|
502
|
+
|
|
503
|
+
```csharp
|
|
504
|
+
// Haptic feedback intensity
|
|
505
|
+
public enum HapticType { Light, Medium, Heavy, Success, Error }
|
|
506
|
+
|
|
507
|
+
// Score normalization (exactly 4 anchors required)
|
|
508
|
+
public struct ScoreAnchor { public int raw; public int normalized; }
|
|
509
|
+
public struct ScoreConfig { public ScoreAnchor[] anchors; }
|
|
510
|
+
|
|
511
|
+
// Multiplayer invite options
|
|
512
|
+
public class ShareRoomCodeOptions { public bool InviteOverride { get; set; } }
|
|
513
|
+
|
|
514
|
+
// Log overlay configuration
|
|
515
|
+
public class LogOverlayOptions
|
|
516
|
+
{
|
|
517
|
+
public bool Enabled { get; set; } = true;
|
|
518
|
+
public bool Collapsed { get; set; } = false;
|
|
519
|
+
public int MaxEntries { get; set; } = 200;
|
|
520
|
+
public string Title { get; set; } = "SDK Logs";
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Log overlay lifecycle handle
|
|
524
|
+
public class LogOverlayHandle
|
|
525
|
+
{
|
|
526
|
+
public void Clear();
|
|
527
|
+
public void Hide();
|
|
528
|
+
public void Show();
|
|
529
|
+
public bool IsVisible();
|
|
530
|
+
public void Destroy();
|
|
531
|
+
}
|
|
532
|
+
```
|
|
444
533
|
|
|
445
534
|
### Back button and errors
|
|
446
535
|
|
|
447
536
|
Matching the HTML5 SDK: if any **`OnBackButton`** handler throws, **`OasizSDK.LeaveGame()`** is invoked and the **original exception is rethrown** (`throw;` preserves the stack trace). Use **`SubscribeBackButton`** when you want an unsubscribe delegate; you can also use `OnBackButton +=` / `-=` directly.
|
|
448
537
|
|
|
538
|
+
```csharp
|
|
539
|
+
// Subscribe with automatic unsubscribe support
|
|
540
|
+
var offBack = OasizSDK.SubscribeBackButton(() =>
|
|
541
|
+
{
|
|
542
|
+
if (isPaused)
|
|
543
|
+
Resume();
|
|
544
|
+
else
|
|
545
|
+
Pause();
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// Unsubscribe when no longer needed
|
|
549
|
+
offBack();
|
|
550
|
+
```
|
|
551
|
+
|
|
449
552
|
### Editor vs WebGL builds
|
|
450
553
|
|
|
451
554
|
In the **Unity Editor**, bridge calls are mostly **logged** and return safe defaults (for example safe area `0`, `null` platform IDs). Real host integration applies to **WebGL player** builds running inside Oasiz.
|
|
452
555
|
|
|
453
556
|
### Log overlay (Unity)
|
|
454
557
|
|
|
455
|
-
The C# API for the log overlay exists for API compatibility, but the **default `OasizBridge.jslib` in this repo does not inject DOM UI** — `EnableLogOverlay` / `AppendLogOverlay` are no-ops at the JavaScript layer. Use Unity
|
|
558
|
+
The C# API for the log overlay exists for API compatibility, but the **default `OasizBridge.jslib` in this repo does not inject DOM UI** — `EnableLogOverlay` / `AppendLogOverlay` are no-ops at the JavaScript layer. Use Unity's console and device logs for debugging unless you replace or extend the `.jslib` on your side.
|
|
559
|
+
|
|
560
|
+
`AppendLogOverlay(level, message, stackTrace)` lets you pipe `Debug.Log` output into the overlay manually, since many embedded WebViews do not route Unity player logs through `console.log`. Valid levels: `"debug"`, `"log"`, `"info"`, `"warn"`, `"error"`.
|
|
456
561
|
|
|
457
562
|
---
|
|
458
563
|
|