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 

    APIdescription
    IsInSessionWhether the user is in p2pSession.
    InConnectedWhether the connection actually is active.
    HostUserIdHost's UserId in this lobby
    LocalUserIdUserID of this local
    CurrentRemoteUserIdsUserIDs of current conenction
    DisconnectedUserIdsDisconnected user ids. (May come back, not exit)
    CurrentConnectedUserIdsConnected user ids include Local UserId
    CurrentAllUserIdsAllUserIds - LeftUsers (not disconnected)
    AllUserIdsAllUserIds in the session
    SessionTypeThe type of current session
    CurrentSessionStartUTCDate time when this LOCAL user starts current session
    AcceptHostSynicIf true, host overwrite this local user instnace
    LastDisconnectedUsersReasonThe reason of last disconnected user
    LastDisconnectedUsersIdUserID of last Disconnected user
    LastConnectedUsersIdUserID of last Connected user
    HasReceivedAllSyncSynicReturn True only once after local user receives all SyncSynics
    SyncedSynicPhaseThe SyncSynic phase of last received
    LastSyncedUserIdThe UserID of last synced SyncSynic
    LastRPCPayloadThe last byte array sent with RPC that record data
    LastRPCchThe last ch sent with RPC that record data
    LastTargetRPCPayloadThe last byte array sent with TargetRPC that record data
    LastTargetRPCchThe last ch sent with TargetRPC that record data
    LastTargetRPCUserIdThe last UserId sent with TargetRPC that record data
    IsReconnecterReturn true until reconencter gets self Synic data.

    Event 

    APIdescription
    ConnectionNotifierNotifers when a user connects or disconnects
    SyncSnyicNotifierNotifers when a user get SynicVariables

    Function 

    APIdescription
    IsLoaclUserIf target is LocalUser, return true
    IsHostIf local or target user is host, return true
    GetSessionTimestampSec since start current session
    GetSessionTimestampInMsMicro Sec since start current session
    GetUserIndexGet the user unique index in AllUserIds
    ConnectionIsValidWhether the connection is valid or not
    GetActiveReceiverTypeGets the currently valid packet receiver type
    QueryNATTypeUpdate local user's NATType to the latest
    GetNATTypeGet last-queried NAT-type
    GetPingGet a ping with a peer from cache
    RefreshPingRefresh 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}");
        }
    }