文档

​
​

Development

User Acquisition

Monetization

工业

Multiplayer Services SDK

All Services

Multiplayer Services SDK

此页面不支持所选语言。
Multiplayer
​
​
Multiplayer Services SDK
  • Overview
  • Get started
  • Use multiplayer sessions
  • Manage sessions
    • Lobby events
    • Rate limits
    • Information management in sessions
      • Session data and player data
      • Update session data
      • Update player data
      • Manage properties as a host
      • Manage properties as a client
    • Synchronize player names in a session
    • Access control
    • Session error messages
  • Connect players through a relay
  • Networking
  • Matchmaking
  • Monitor and debug sessions
  • Tutorials
  • Reference
  1. Multiplayer Services SDK

Manage properties as a client

Manage your sessions with the operations available to you as a session client.
阅读时间2 分钟
最后更新于 4 个月前

As a session client, you have access to operations that let you interact with session and player properties.
Note that some client operations differ from those available to the host.

Session property operations

A client can read properties from a session. Unlike a host, a client can't add, update, or delete session properties.
注意
If you are the host and have an
ISession
(client session), you can call
ISession.AsHost()
to get an
IHostSession
(host session) from your
ISession
. After you have an
IHostSession
, you can add, update, or delete session property. Refer to Session operations as a host.

Read APIs

The following APIs allow a client to read session properties:
ISession.IReadOnlyDictionary<string, SessionProperty> Properties { get; }

Read a session property

The following code snippet demonstrates how to read the
colour
property:
if (clientSession.Properties.TryGetValue("colour", out var colour)){ Debug.Log($"The colour session property is {colour.Value}");}

Player property operations

A client can access any player properties set as visible to them. However, a client can only add, update, or remove the player properties they own.

Read APIs

The following APIs allow a client to read player properties:
IPlayer ISession.CurrentPlayer { get; }IReadOnlyList<IReadOnlyPlayer> ISession.Players { get; }
注意
Use
ISession.CurrentPlayer
to read your own properties.

Read a player property

The following code snippet demonstrates how to read the
colour
player property:
if (clientSession.Players.First().Properties.TryGetValue("colour", out var colour)){ Debug.Log($"First player colour property is {colour.Value}");}

Write APIs

The following APIs allow a client to modify its player properties:
IPlayer ISession.CurrentPlayer { get; }Task ISession.SaveCurrentPlayerDataAsync();void IPlayer.SetProperty(string key, PlayerProperty property);void IPlayer.SetProperties(Dictionary<string, PlayerProperty> properties);

Add a player property

To add a property, decide upon the visibility of the property:
  • Public (visible to everyone)
  • Member (visible to members of the Session)
  • Private (visible to the player who owns the property and the host)
The following code snippet demonstrates how to add a
colour
property with the value
red
on a client:
var redColourProperty = new PlayerProperty("red");clientSession.CurrentPlayer.SetProperty("colour", redColourProperty);await clienSession.SaveCurrentPlayerDataAsync();

Update a player property

The following code snippet demonstrates how to set the
colour
property to
null
on a client:
var nullColourProperty = new PlayerProperty(null);clientSession.CurrentPlayer.SetProperty("colour", redColourProperty);await clienSession.SaveCurrentPlayerDataAsync();

Delete a player property

The following code snippet demonstrates how to delete the
colour
property on a client:
clientSession.CurrentPlayer.SetProperty("colour", null);await clienSession.SaveCurrentPlayerDataAsync();

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • Session property operations

      • Read APIs

      • Read a session property

    • Player property operations

      • Read APIs

      • Read a player property

      • Write APIs

      • Add a player property

      • Update a player property

      • Delete a player property


报告此页面的问题