TrueSync
PhotonTrueSyncCommunicator.cs
1 using System;
2 
3 namespace TrueSync {
4 
9 
10  private LoadBalancingPeer loadBalancingPeer;
11 
12  private static PhotonNetwork.EventCallback lastEventCallback;
13 
19  internal PhotonTrueSyncCommunicator(LoadBalancingPeer loadBalancingPeer) {
20  this.loadBalancingPeer = loadBalancingPeer;
21  }
22 
23  public int RoundTripTime() {
24  return loadBalancingPeer.RoundTripTime;
25  }
26 
27  public void OpRaiseEvent(byte eventCode, object message, bool reliable, int[] toPlayers) {
28  if (loadBalancingPeer.PeerState != ExitGames.Client.Photon.PeerStateValue.Connected) {
29  return;
30  }
31 
32  RaiseEventOptions eventOptions = new RaiseEventOptions();
33  eventOptions.TargetActors = toPlayers;
34 
35  loadBalancingPeer.OpRaiseEvent(eventCode, message, reliable, eventOptions);
36  }
37 
38  public void AddEventListener(OnEventReceived onEventReceived) {
39  if (lastEventCallback != null) {
40  PhotonNetwork.OnEventCall -= lastEventCallback;
41  }
42 
43  lastEventCallback = delegate (byte eventCode, object content, int senderId) { onEventReceived(eventCode, content); };
44  PhotonNetwork.OnEventCall += lastEventCallback;
45  }
46 
47  }
48 
49 }
int RoundTripTime()
Returns the roundtrip time between local player and server.
void AddEventListener(OnEventReceived onEventReceived)
Adds an event listener to handle received custom events.
Truesync's ICommunicator implementation based on PUN.
TrueSync's communicator interface.
Definition: ICommunicator.cs:9
void OpRaiseEvent(byte eventCode, object message, bool reliable, int[] toPlayers)
Raises a custom event to be sent to all other players.