Get started with Friends
Set up Friends and learn how to link your Unity project.
阅读时间2 分钟最后更新于 1 个月前
You must link your project with the Unity Dashboard, enable the Friends service, and import the SDK before using the Friends service in your project
Link your project with the Unity Dashboard
You must link your project with the Unity Dashboard to use the Friends service.- From the Unity Editor, select Edit > Project Settings... > Services.
- Link your project.
- If your project doesn't have a Unity project ID:
- Select Create a Unity Project ID > Organizations, then select an organization.
- Select Create project ID.
- If you have an existing Unity project ID to use:
- Select Use an existing Unity project ID.
- Select an organization and a project.
- Select Link project ID.
- If your project doesn't have a Unity project ID:
UnityEditor.CloudProjectSettings.projectIdEnable the Friends service
You can enable the Friends service for your project from the Unity Dashboard.- Sign in to the Unity Dashboard.
- Select your project.
- Navigate to Multiplayer > Friends.
- You can enable Friends from the Overview page or the Setup Guide.
Import the Friends SDK
- Sign in to the Unity Dashboard.
- Select your project.
- Select Project Settings.
- Select Settings > SDK Download.
- Select Friends from the list of available packages. Doing so also selects any package dependencies.
- Select Generate Code Snippet.
- Copy the code snippet that appears on the screen.
- Paste the code snippet in your project’s file in the
Packages/manifest.jsonobject.dependencies - Save the file.
- Install the package through the Package Manager in the Unity Editor. Refer to the Package Manager documentation.
Initialize the Friends service
Once you’ve enabled the Friends service and imported the Friends SDK through the Package Manager in the Unity Editor, initialize the Core SDK usingawait UnityServices.InitializeAsync()// Import required packagesusing Unity.Services.Core;using Unity.Services.Authentication;...private async Task MyMethod(){ // Initialize all of the used services await UnityServices.InitializeAsync(); // Sign in anonymously or using a provider await AuthenticationService.Instance.SignInAnonymouslyAsync(); // Initialize friends service await FriendsService.Instance.InitializeAsync(); // Start using the Friends SDK functionalities. var friends = FriendsService.Instance.Friends;}