p2pInfo
Namespace: SynicSugar.P2P
This is used like p2pinfo.Instance.XXX().
Description
This manages data after p2p connections have established.
This script is Mono's Singleton attached to NetworkManager. To generate NetworkManager, right-click on the Hierarchy and click SynicSugar/NetworkManager
NetworkManager has DontDestroy, so NetworkManager will not be destroyed by scene transitions.
If this is no longer needed, we call CancelCurrentMatchMake, ConnectHub.Instance.CloseSession(CancellationTokenSource) or ConnectHub.Instance.ExitSession(CancellationTokenSource).
Properity
API | description |
---|---|
IsInSession | Whether the user is in p2pSession. |
InConnected | Whether the connection actually is active. |
HostUserId | Host's UserId in this lobby |
LocalUserId | UserID of this local |
CurrentRemoteUserIds | UserIDs of current conenction |
DisconnectedUserIds | Disconnected user ids. (May come back, not exit) |
CurrentConnectedUserIds | Connected user ids include Local UserId |
CurrentAllUserIds | AllUserIds - LeftUsers (not disconnected) |
AllUserIds | AllUserIds in the session |
SessionType | The type of current session |
CurrentSessionStartUTC | Date time when this LOCAL user starts current session |
AcceptHostSynic | If true, host overwrite this local user instnace |
LastDisconnectedUsersReason | The reason of last disconnected user |
LastDisconnectedUsersId | UserID of last Disconnected user |
LastConnectedUsersId | UserID of last Connected user |
HasReceivedAllSyncSynic | Return True only once after local user receives all SyncSynics |
SyncedSynicPhase | The SyncSynic phase of last received |
LastSyncedUserId | The UserID of last synced SyncSynic |
LastRPCPayload | The last byte array sent with RPC that record data |
LastRPCch | The last ch sent with RPC that record data |
LastTargetRPCPayload | The last byte array sent with TargetRPC that record data |
LastTargetRPCch | The last ch sent with TargetRPC that record data |
LastTargetRPCUserId | The last UserId sent with TargetRPC that record data |
IsReconnecter | Return true until reconencter gets self Synic data. |
Event
API | description |
---|---|
ConnectionNotifier | Notifers when a user connects or disconnects |
SyncSnyicNotifier | Notifers when a user get SynicVariables |
Function
API | description |
---|---|
IsLoaclUser | If target is LocalUser, return true |
IsHost | If local or target user is host, return true |
GetSessionTimestamp | Sec since start current session |
GetSessionTimestampInMs | Micro Sec since start current session |
GetUserIndex | Get the user unique index in AllUserIds |
ConnectionIsValid | Whether the connection is valid or not |
GetActiveReceiverType | Gets the currently valid packet receiver type |
QueryNATType | Update local user's NATType to the latest |
GetNATType | Get last-queried NAT-type |
GetPing | Get a ping with a peer from cache |
RefreshPing | Refresh ping with other all peers |
using SynicSugar.P2P;
using UnityEngine;
[NetworkPlayer]
public partial class p2pSample : MonoBehaviour {
void Start(){
if(!isLoacl){
return;
}
p2pInfo.Instance.ConnectionNotifier.Disconnected += OnDisconect;
if(p2pInfo.Instance.IsHost()){
p2pInfo.Instance.ConnectionNotifier.Connected += () => Debug.Log($"{p2pConfig.Instance.LastConnectedUsersId} Join");
}
}
void OnDisconect(){
Debug.Log($"{p2pInfo.Instance.LastDisconnectedUsersId} is Disconnected / {p2pInfo.Instance.ClosedReason}");
}
}