public abstract class AttributesSync : CommunicationBridgeUID// By inheriting from AttributesSync, we get access to attributes and methods for controlling synchronization
// of methods and fields between clients in a room.
public class MyAttributesSyncClass : AttributesSync
{
// By using the SynchronizableField attribute, the field will be synchronized between other clients
// in the same room automatically.
[SynchronizableField]
public string MyString;
}public class MessageAll : AttributesSync
{
private int _messageMethodID;
private void Start()
{
// Get the method's ID once.
_messageMethodID = GetMethodAttributeId(nameof(Message));
}
public void SendMessage()
{
// Invoke method by id.
BroadcastRemoteMethod(_messageMethodID, "Hello, world!");
// Alternatively, you can invoke using the SynchronizableMethod's name. This method of calling the
// SynchronizableMethod is less performant as it has to look through all SynchronizableMethod's rather
// than calling it directly using the ID.
// BroadcastRemoteMethod(nameof(Message), "Hello, world!");
}
// The SynchronizableMethod attribute marks the method as available for invocation from
// AttributesSync behavior.
[SynchronizableMethod]
private void Message(string msg)
{
// The message will now be printed to all the clients' log in the room.
Debug.Log(msg);
}
}public class PlayAudioSync : AttributesSync
{
// Reference to AudioSource.
public AudioSource AudioSource;
// The public method that we call in an event or from external scripts.
public void Play()
{
// When no argument is provided, ID defaults to 0.
// Calls the method on all clients, including the sending client.
BroadcastRemoteMethod();
}
// We define our synced method here.
// As we only define one in this script, we know this one have index 0.
[SynchronizableMethod]
private void PlayRemote()
{
AudioSource.Play();
}
}public class Message : AttributesSync
{
public void SendMessageToUser(ushort userID, string message)
{
// Calls the function on a different client.
// As there is only one SynchronizableMethod in this script, the method ID will always be 0.
// So we will just use id 0 here instead of using the nameof method.
InvokeRemoteMethod(0, userID, message);
}
public void SendMessageToUsers(ushort[] userIDs, string message)
{
// Calls method by index.
InvokeRemoteMethod(0, userIDs, message);
}
// Because this is the first method defined, we know its index is 0. The next one would have index of 1.
[SynchronizableMethod]
private void Message(string msg)
{
// This message will not be printed on the client(s) that has matching id(s).
Debug.Log(msg);
}
}| BroadcastRemoteMethod(Int32, Object) | Calls method with the SynchronizableMethod attribute on every client including sender with given parameters. |
| BroadcastRemoteMethod(String, Object) | Calls method with the SynchronizableMethod attribute on every client including sender with given parameters. with given parameters. |
| Commit | Send all changes to all users. |
| ForceSync | Force all fields to be synced as if they were changed. |
| GetMethodAttributeId | Get index of method with the SynchronizableMethod attribute by name. |
| GetMethodAttributeName | Get name of method with the SynchronizableMethod attribute by index. |
| InvokeRemoteMethod(Int32, UserId, Object) | Invoke a method with the SynchronizableMethod attribute on target user with given parameters. |
| InvokeRemoteMethod(Int32, ListUInt16, Object) | Invoke a method with the SynchronizableMethod attribute on target users with given parameters. |
| InvokeRemoteMethod(Int32, UInt16, Object) | Invoke a method with the SynchronizableMethod attribute on target user with given parameters. |
| InvokeRemoteMethod(String, UserId, Object) | Invoke a method with the SynchronizableMethod attribute on target user with given parameters. |
| InvokeRemoteMethod(String, ListUInt16, Object) | Invoke a method with the SynchronizableMethod attribute on target users with given parameters. |
| InvokeRemoteMethod(String, UInt16, Object) | Invoke a method with the SynchronizableMethod attribute on target user with given parameters. |
| LateUpdate | Handle changed fields. |
| Register | (Overrides CommunicationBridgeUIDRegister) |
| Serialize | Write changes to a ITransportStreamWriter processor. (Overrides CommunicationBridgeUIDSerialize(ITransportStreamWriter, SerializeInfo)) |
| UncommittedFields | Check if there is any uncommitted changes to any fields. |
| Unserialize | Read changes from a ITransportStreamReader processor. (Overrides CommunicationBridgeUIDUnserialize(ITransportStreamReader, UnserializeInfo)) |
| ForceSyncFields | |
| ForceSyncMethods | |
| LocalMethodBehavior | Chose how local methods behave when sending. |
| Reliability | Chose how to send data. Reliable or Unreliable. |