LogoLogo
⚠️ Outdated documentationGo to LatestHomeAPI
SDK 0.10
SDK 0.10
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Rooms and Worlds
    • Features and Roadmap
    • Release Notes
    • Known Issues and Troubleshooting
  • Learning coherence
    • First Steps tutorial
      • 1. Basic syncing
        • 1.2. Animation parameters
        • 1.3. Sending commands
      • 2. Physics / Authority transfer
      • 3. Areas of interest
      • 4. Parenting entities
      • 5. Complex hierarchies
      • 6. Persistence
    • How to network...
      • Racing
      • Turn-based
      • First-Person Shooter
      • MMO
      • Fighting
  • Get started
    • Installation
    • Scene Setup
      • Sample UI
    • Prefab Setup: CoherenceSync
    • Local Development
      • Tips and Recommendations
    • coherence Cloud
      • Create a Free Account
      • Deploy a Replication Server
      • Share Builds
  • coherence SDK for Unity
    • Components
      • CoherenceSync
      • CoherenceMonoBridge
      • CoherenceLiveQuery
      • CoherenceTagQuery
      • Order of execution
    • Networking State Changes
      • Messaging with Commands
      • Hierarchies & Child Objects
        • Child GameObjects
        • Child CoherenceSyncs
        • Deep Child CoherenceSyncs
      • Animations
      • CoherenceSync References
      • [Sync] and [Command] Attributes
      • [OnValueSynced] Attribute
      • Supported Types
      • Player Name (Sample UI)
    • Baking (Code Generation)
    • Authority
      • Authority transfer
      • Server-authoritative setup
    • Lifetime
      • Persistence
      • Example – a global counter
    • Optimization
      • Simulation Frequency
      • Areas of Interest
      • Level of Detail (LOD)
    • Interpolation
    • Settings
    • Simulation Frame
    • Replication Server
    • Simulators
      • Scripting: Client vs Simulator
      • Local Development
      • World Simulators
      • Room Simulators
      • Simulator Slugs
      • Multi-Room Simulators
      • Build and Publish
      • Command-line arguments
      • Load Balancing
      • Network Connectivity
    • Client Connections
    • Rollback Networking Support
    • Floating Origin
    • CLI
  • coherence API
    • Worlds
    • Rooms
    • PlayResolver
    • DescriptorProvider
  • Developer Portal
    • Overview
    • Dashboard
    • Worlds
    • Rooms
    • Game Services
      • Account
      • Key-Value Store
      • API
        • Game account
        • Key-value store
  • Schema explained
    • Overview
    • Specification
    • Field settings
    • Archetypes
  • Additional resources
    • Community
    • SDK Upgrade Guide
    • Video Tutorials
    • Quick Samples
    • Continuous Integration
    • Unreal Engine Support
    • WebGL Support
    • Peer-to-Peer Support (P2P)
    • Pricing
    • SLA
    • Glossary
Powered by GitBook
On this page
  • Rooms API
  • Worlds API

Was this helpful?

Export as PDF
  1. coherence API

PlayResolver

The PlayResolver encapsulates all the internals to fetch and join both Rooms and Worlds.

using Coherence.Runtime;

// ensure connection to the play services backend
async Task<bool> PlayResolver.EnsurePlayConnection();

Rooms API

Detailed usage can be found under chapter Rooms.

// Returns true if there is a valid local server running.
// Returns "local" as the region if local server is running.
async Task<(bool, string)> FetchLocalRegions()

// Returns all the regions where rooms are enabled in the portal.
async Task<IReadOnlyList<string>> FetchRegions()

// Fetch a list of rooms currently active in the given region.
// Optionally, filter by tags provided when creating the room.
async Task<IReadOnlyList<RoomData>> FetchRooms(string region, string[] tags = null)

// Create a new room in the region. 
async Task<RoomData> CreateRoom(string region, RoomCreationOptions options = null)

// Convert RoomData to EndpointData, to call IClient.Connect(endpoint) directly.
// The second return value is false if the room data is invalid. 
(EndpointData, bool) GetRoomEndpointData(RoomData room)

Example usage for Rooms API:

using UnityEngine;
using Coherence.Runtime;
using Coherence.Toolkit;

public class CreatorAndJoiner : MonoBehaviour
{
    private CoherenceMonoBridge bridge;

    private async void Start()
    {
        if (!MonoBridgeStore.TryGetBridge(gameObject.scene, out bridge))
        {
            return; 
        }
        
        // XXX: try-catch everything
        var regions = await PlayResolver.FetchRegions();
        var rooms = await PlayResolver.FetchRooms(regions[0]);

        
        if (rooms.Count == 0)
        {
            var room = await PlayResolver.CreateRoom(regions[0]);
            bridge.JoinRoom(room);
        }
        else
        {
            bridge.JoinRoom(rooms[0]);  
        }
    }
}

Worlds API

Detailed usage can be found under chapter Worlds.

// Returns true if a local worlds replication server is running.
async Task<bool> EnsureLocalServer()

// Fetches the connection data for local replication server.
async Task<WorldData> FetchLocalWorld()

// Fetches a list of worlds from the portal.
async Task<IReadOnlyList<WorldData>> FetchWorlds()

// Convert WorldData into EndpointData, to call IClient.Connect(endpoint) directly.
// The second return value is false if the world data is invalid. 
(EndpointData, bool) GetWorldEndpoint(WorldData world)

Example usage for Worlds API:

using UnityEngine;
using Coherence.Runtime;
using Coherence.Toolkit;

public class WorldJoiner : MonoBehaviour
{
    private async void Start()
    {
        if (!MonoBridgeStore.TryGetBridge(gameObject.scene, out var bridge))
        {
            return; 
        }
        
        // XXX: try-catch everything
        var worlds = await PlayResolver.FetchWorlds();
        if (worlds.Count > 0)
        {
            bridge.JoinWorld(worlds[0]);
        }
    }
}

Last updated 2 years ago

Was this helpful?