Awesome
EpicOnlineTransport for Mirror
Hi! This is our Epic Online Services (EOS) transport for Mirror. We developed it for our game Nimoyd, it is still under development, but already working without any problems.
Dependencies
- Mirror (Documentation)
- Epic Online Services C# SDK (Documentation)
Setting Up Epic Online Services and Obtaining API Keys
- Login to the Epic Games Dev Portal with an Epic Games Account
- Create a new Product
- Go to Product Settings -> Clients and add a new Client Policy
- Name your Client Policy and set the Client Policy Type to Peer2Peer, then Save & Exit
- Add a new Client
- Name your Client and set the Client Policy to the Client Policy you just created, then Save & Exit
- Go to Epic Account Services -> Configure Application
- Set Application Name to what you want your users to see when signing in with the Account Portal, then Save Draft
- Go to Permissions and set all permissions to Required, then Save
- Go to Clients and set the Client to the Client you just created, then Save
- Go back, then click Back to Organization
- Go to SDK -> SDK Credentials -> Get Credentials
- Copy and paste all of your credentials into the EOS API Key Asset once your project is set up
Installation
- Visit the Mirror Asset Store Page and add Mirror to My Assets
- Import Mirror with Package Manager (Window -> Package Manager -> Packages: My Assets -> Mirror -> Download)
- Download the latest master branch, unpack it and copy the Plugin and the Mirror folder into your project (merge with already existing folders).
- Attach an EOSSDKComponent to a GameObject in your Scene
- Right click in the Project View and create an EOS API Key Asset (Create -> EOS -> API Key)
- Fill out all the SDK keys on the EOS API Key Asset, you can find them in the Epic Online Services Dev Portal (SDK -> SDK Credentials -> Get Credentials)
- Move the EOS API Key Asset into the 'Api Keys' slot on the EOSSDKComponent
- Attach a NetworkManager to a GameObject in your Scene
- Attach an EosTransport component to the same GameObject as the NetworkManager
- Move the EosTransport component into the 'Transport' slot on the NetworkManager
- (Optional) Add an EOSLobbyUI component, a NetworkManagerHUD component, or a NetworkDiscoveryHUD component to test that the transport is working properly
- Change the Auth Interface Credential Type and Connect Interface Credential Types on the EOSSDKComponent to suit the needs of your project
Building for Android
- Install the Android Module through Unity Hub
- Switch platform to Android in Build Settings
- In Unity -> Edit -> Project Settings... -> Player -> Android -> Other Settings -> Identification set Minimum API Level to Android 6.0 'Marshmallow' (API Level 23) as required by the EOS Android SDK
- (Optional) Install Android Logcat through Package Manager to see logs when running on Android device over USB (Window -> Package Manager -> Packages: Unity Registry -> Android Logcat -> Install) then open with Alt+6 or Window -> Analysis -> Android Logcat
Testing multiplayer on one device
Running multiple instances of your game on one device for testing requires you to have multiple epic accounts. Even if your game doesn't use epic accounts you will need them for testing.
- Add all epic accounts you want to test with to your organization in the dev portal
- On the EOSSDKComponent under User Login set Auth Interface Login to true
- Choose 'Developer' as Auth Interface Credential Type
- Choose 'Epic' as Connect Interface Credential Type
- Open the epic transport folder with a file explorer and go into the DevAuthTool folder
- Create a folder that ends with ~ e.g. Tool~, this makes unity ignore this folder
- Unzip the dev auth tool for your OS (Mac/Win) into the folder you created in step 5.
- Run the dev auth tool
- Enter a port in the dev auth tool
- Login to your epic account and give the credential a name
- Repeat step 9 for as many accounts you want to use
- On the EOSSDKComponent set the port to the one you used in the dev auth tool
- On the EOSSDKCOmponent set Dev Auth Tool Credential Name to the named you chose in the tool
Note: In the editor after logging in with the dev auth tool you cant change the credential name as the sdk stays initialized even after finish playing. You either have to restart unity or the dev auth tool. For builds it is useful to set delayed initialization on the EOSSDKComponent to true and then provide a user input field to set the dev tool credential name and then calling EOSSDKComponent.Initialize().
Connecting to other users
You need the epic online product id to connect to another user, you can get it by calling:
EOSSDKComponent.LocalUserProductId
or
EOSSDKComponent.LocalUserProductIdString
The string variant can be sent to other users to connect.
Lobbies
You can quickly add lobbies to your game using the pre-built EOSLobbyUI script. The EOSLobbyUI extends the EOSLobby script which has methods for handling lobby creation, joining, finding, and leaving and has many events that you can subscribe to. To make the EOSLobbyUI work, create a GameObject, and add the script. If you don't have an EOSSDKComponent present in the scene, make sure to add it to the GameObject. If you prefer to create your own UI for lobbies, you can reference the EOSLobbyUI script.
NOTE: The EOSLobby script creates lobbies with the host address predefined. You can get the host address from the JoinLobbySucceeded
event so you can establish a connection using Mirror.
EOSLobbyUI Features
The EOSLobbyUI allows for a fast implementation of lobbies in your project and it is also an example of what you can do. Here are the features:
- Creating a lobby with a name
- Lobby list that displays the name and player count
- Joining
- Leaving (If the owner of the lobby leaves, then the lobby will be destroyed)
Credits
Big thanks to erikas-taroza aka TypicalEgg for his help in improving and extending this transport!