PUN 2 is in maintenance / LTS mode. Aside from some fixes no further feature updates are planned. Of course, existing PUN 2 projects will continue to run. New projects should consider Fusion or Quantum.
UserIDs and Friends
UserIDs
在Photon中,玩家的身份是用一個唯一的UserID來識別的。
獨特的用戶ID
一般來說,UserIDs不打算被顯示。
與用戶名、顯示名或綽號不同。
用戶ID不一定是人類可讀的,也不一定是非常人性化的。
因此,您可以,例如:使用一個GUID作為UserID。
每個玩家保持一個唯一的UserID的好處是。
- 您可以在不同的遊戲環節和多個設備之間保存您的數據。
您可以重新加入房間,在您停止的地方繼續遊戲。 - 您可以被您遇到的所有玩家所認識,並且容易被大家所識別。
您可以與您的朋友一起玩,向他們發送邀請和挑戰,進行在線聚會,組建團隊和公會,等等。
您可以添加用戶檔案(如經驗、統計、成就、等級等),使遊戲更具挑戰性(也可以使用錦標賽和排行榜)。 - 您可以利用另一個服務將Photon UserID綁定到一個外部的唯一標識。
例如,Photon UserID可以被設置為Facebook ID、Google ID、Steam ID、PlayFab ID等。
設置用戶ID
Once authenticated, a Photon client will keep the same UserID until disconnected.
The UserID for a client can be set in three ways:
- Photon伺服器將為那些沒有使用1或2獲得UserIDs的用戶分配GUIDs作為ID。因此,即使是匿名用戶也會有UserIDs。
朋友
- Friends' UserIDs are case sensitive. Example: "mybestfriend" and "MyBestFriend" are two different UserIDs for two different friends. ::: include condition="Chat PUN Realtime"
- Only friends connected to the same AppID, the same Photon Cloud region and play the same Photon AppVersion can find each other no matter what device or platform they're using. ::: ::: include condition="Server"
- Only friends connected to the same Master Server can find each other no matter what device or platform they're using. :::
- FindFriends works only when connected to the Master Server, it does not work when the client is joined to a room.
C#
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
using Photon.Pun;
public class FindFriendsExample : MonoBehaviourPunCallbacks
{
public bool FindFriends(string[] friendsUserIds)
{
return PhotonNetwork.FindFriends(friendsUserIds);
}
public override void OnFriendListUpdate(List<FriendInfo> friendsInfo)
{
for(int i=0; i < friendsInfo.Count; i++)
{
FriendInfo friend = friendsInfo[i];
Debug.LogFormat("{0}", friend);
}
}
}
Back to top