Synchronizable Class

Class Synchronizable defines a base containing data to be synchronized with other clients in the Room. Synchronizable also support attributes, but unlike AttributesSync, it does not auto commit changes in fields marked with the SynchronizableField attribute.

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4
C#
public abstract class Synchronizable : CommunicationBridgeUID
Inheritance
Object    Object    Component    Behaviour    MonoBehaviour    CommunicationBridge    CommunicationBridgeUID    Synchronizable
Derived

Example

Synchronizables are automatically assigned a unique global identifier (UniqueID) when they are first created. This ensures that all application instances can always identify the correct object to synchronize and prevent collisions. You can inspect the assigned UniqueID in the inspector window for all objects that have Synchronizable components attached to them. Alteruna Multiplayer supports synchronization of virtually any data type or user-defined class as long as they can be serialized as a stream of bytes. Alteruna Multiplayer provides a framework for reading and writing the most common primitive data types in C#. It does support sending a series of bytes which open up for more complex data types to be synchronized as well. Here is a detailed example of a Synchronizable.
C#
public class ExampleSynchronizable : Synchronizable
   {
       // Data to be synchronized with other players in our playroom.
       public float SynchronizedFloat = 3.0f;

       // Used to store the previous version of our data so that we know when it has changed.
       private float _oldSynchronizedFloat;

       public override void DisassembleData(Reader reader, byte LOD)
       {
           // Set our data to the updated value we have recieved from another player.
           SynchronizedFloat = reader.ReadFloat();

           // Save the new data as our old data, otherwise we will immediatly think it changed again.
           _oldSynchronizedFloat = SynchronizedFloat;
       }

       public override void AssembleData(Writer writer, byte LOD)
       {
           // Write our data so that it can be sent to the other players in our playroom.
           writer.Write(SynchronizedFloat);
       }

       private void Update()
       {
           // If the value of our float has changed, sync it with the other players in our playroom.
           if (SynchronizedFloat != _oldSynchronizedFloat)
           {
               // Store the updated value
               _oldSynchronizedFloat = SynchronizedFloat;

               // Tell Alteruna Multiplayer that we want to commit our data.
               Commit();
           }

           // Update the Synchronizable
           base.SyncUpdate();
       }
    }

Methods

AssembleData Called by the SynchronizableManager after Commit() to collect the data to be synced before sending it.
BroadcastRemoteMethod(Int32, Object) Commits method with the SynchronizableMethod attribute on evey client including sender with given parameters.
BroadcastRemoteMethod(String, Object) Commits method with the SynchronizableMethod attribute on evey client including sender with given parameters. with given parameters.
Commit This method informs the SynchronizableManager that this synchronizable has new data that needs to be synced.
DisassembleData Called by the SynchronizableManager after recieving new data to be synced with this Synchronizable.
GetMethodAttributeId Get id of method with the SynchronizableMethod attribute by name.
GetMethodAttributeName Get name of method with the SynchronizableMethod attribute by index.
InvokeRemoteMethod(Int32, Object) Commits method with the SynchronizableMethod attribute on evey client excluding sender with given parameters.
InvokeRemoteMethod(String, Object) Commits method with the SynchronizableMethod attribute on evey client excluding sender with given parameters. with given parameters.
Register
(Overrides CommunicationBridgeUIDRegister)
Reset
(Overrides CommunicationBridgeUIDReset)
Serialize Serialize Synchronizable.
(Overrides CommunicationBridgeUIDSerialize(ITransportStreamWriter, Byte, Boolean))
SyncUpdate Update the internals of the Synchronizable.
Unserialize Unserialize Synchronizable.
(Overrides CommunicationBridgeUIDUnserialize(ITransportStreamReader, Byte, UInt32))

Fields

BucketBehaviors A list of Bucket Behaviors describing how this Synchronizable is syncrhonized depending on which Bucket it is being sent to.
MAX_LOD The highest NetLOD value a Synchronizable can have.
Reliability Reliability of the Synchronizable.

See Also