Introduction & How To Use |
Local Multiplayer for iOS/tvOS/macOS enables you to implement local hassle-free multiplayer to your game with just a few lines of code. Connection between devices is done automatically using whatever connectivity options are available — Bluetooth, WiFi, Peer-to-Peer WiFi, Ethernet, all without any setup! It integrates seamlessly with Unity's built-in networking system, which means you can easily reuse your networking code with minimal changes, or use any of existing tutorials about Unity built-in networking.
Highlights:
Runs on the whole spectrum of Apple devices based on iOS (iPhone, iPad, iPod), tvOS (Apple TV), and macOS.
True peer-to-peer connection - no need to have all devices connected to the same network..
Fully compatible with Unity's built-in UNet multiplayer component. No need to write special networking code!
Documented demo examples and components to get you started immediately.
Powerful API to cover even advanced use cases.
Comprehensive online documentation.
Supports iOS 7.0 or newer, tvOS 10.0 or newer, macOS 10.10 or newer.
macOS Unity editor is supported as well - no need to build on multiple devices when developing.
Local Multiplayer for iOS/tvOS/macOS is built on top of Apple's Multipeer Connectivity framework. The main benefit of Multipeer Connectivity is that it doesn't require nearby devices to connect to same access point or an access point at all. For iOS, the framework uses infrastructure Wi-Fi networks (like a hotspot), peer-to-peer Wi-Fi (like WiFi Direct), and Bluetooth personal area networks for the underlying transport. For macOS and tvOS, it uses infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Ethernet.
If devices are unable to connect directly, framework will attempt to use other devices as relays. For example, let's assume we have three devices — A, B, and C. Device A only has WiFi enabled, device B has both WiFi and Bluetooth enabled, and device C only has Bluetooth enabled. Device A creates a game, device B joins it over WiFi, everything works fine as it is. After that, device C tries to join the same session, but since WiFi is disabled, it can't do it directly. What will happen is that traffic from C will first travel to B via Bluetooth, and then B will then retransmit the data to A. This means that for optimal performance, all devices have to use the same connection method. Keep this in mind for fast-paced games.
Local Multiplayer for iOS/tvOS/macOS works by creating UDP tunnels that correspond to Multipeer Connectivity framework connections. This makes it completely transparent to Unity's UNet networking system, resulting in a system that just works.
If the app moves into the background, the framework stops advertising and browsing and disconnects any open sessions. Upon returning to the foreground, the framework automatically resumes advertising and browsing, but you must reestablish the session.
Class | Description |
---|---|
Provides access to the local multiplayer session, setting the peer name, service type, getting other peers that are connected to the session. | |
Provides access to the native built-in peer discovery UI that allows you to quickly invite other peers to the session. Very easy to use and setup, but limited to a single interaction model. | |
Provides access to the native built-in service advertiser. Whenever another peer sends an invitation, present a dialog that allows declining or accepting the invitation. Very easy to use and setup, but limited to a single interaction model. | |
Provides full programmatic access to the peer discovery API. Allows implementing complex custom behaviours (like auto-joining the session or implementing a in-game peer discovery interface). | |
Provides full programmatic access to the service advertiser API. Allows implementing complex custom behaviours (like auto-joining the session or implementing a in-game invitation accept/decline interface). | |
Provides access to device's connectivity options like Bluetooth. | |
Provides access to log system interface, contains functions that are useful for debugging. | |
Uniquely represents a peer in a local multiplayer session. |
The plugin comes with a set of scripts designed for making the integration into your project as easy as possible.
AppleLocalMultiplayerNetworkManagerHelper is the class you'll use the most. It is very similar in its usage to Unity's Networking.NetworkManager, main difference being that AppleLocalMultiplayerNetworkManagerHelper automatically synchronizes Unity's UNet networking system with the local multiplayer session, manages the peer browser UI and the invitation handling UI.
AppleLocalMultiplayerNetworkManager and AppleLocalMultiplayerNetworkLobbyManager are variants of Networking.NetworkManager and Networking.NetworkLobbyManager respectively. The difference is that they also stop the local multiplayer session connection when connection to the host is lost.
AppleLocalMultiplayerNetworkManagerHUD is a simplified version of Networking.NetworkManagerHUD designed specifically for Local Multiplayer. It has no features that are incompatible or meaningless for local gaming, making it less confusing.
Issues? Questions? Suggestions? Feel free to contact:
Forum thread: https://forum.unity3d.com/threads/released-local-multiplayer-for-ios-tvos-macos.474432/
E-mail: contact@lostpolygon.com
Skype: serhii.yolkin