Sync Property
For synchronizing not frequently updated GameObject States

Create Sync Property

Sync Properties are created in the Unity Editor Inspector by clicking the Add Sync Property button.
You can have up to 250 Sync Properties in one Sync Property Agent.
Maximum message size of a syncProperty is 4KB.
Name
Function
Name
Unique name of the Sync Property. Sync Property name must be unique in the same Sync Property Agent Component.
Type
Bool: Bool Property
Float: Float Property
Int: Int Property
String: String Property
Vector 3: Vector 3 Property
Vector 2: Vector 2 Property
Serializable: Serializable Property
TinyJSON: Any class and struct property
Conflict Resolution
Mine: takes the local change
Their: takes the remote change
Custom: use a custom method to resolve the conflict
Data
The current value of the Sync Property
Version
The current Version of the Sync Property

Events

Event
Description
OnValueChange
Invoked when the Sync Property is modified.
OnConflict
Invoked when conflict occurs and Conflict Resolution is set to Custom.
OnReady
invoked when the Sync Property finished fetching its value from the game server and is ready to be used.

Modify and Read Sync Property

Sync Properties can be modified by calling SWNetwork API in C# scripts

SyncPropertyAgent Class

Modify Sync Property
1
public void Modify(string name, bool value);
2
public void Modify(string name, int value);
3
public void Modify(string name, float value);
4
public void Modify(string name, string value);
5
public void Modify(string name, Vector2 value);
6
public void Modify(string name, Vector3 value);
7
public void Modify(string name, Vector4 value);
8
public void Modify(string name, Quaternion value);
9
public void Modify<T>(string name, T value);
10
public void ModifyTinyJson(string name, object value);
Copied!
Get Sync Property
1
public SWSyncedProperty GetPropertyWithName(string name);
Copied!

SWSyncedProperty Class

Read Sync property values
1
public int GetIntValue();
2
public bool GetBoolValue();
3
public float GetFloatValue();
4
public string GetStringValue();
5
public Vector2 GetVector2Value();
6
public Vector3 GetVector3Value();
7
public Vector4 GetVector4Value();
8
public Quaternion GetQuaternionValue();
9
public T GetValue<T>();
10
public T GetTinyJsonValue<T>();
Copied!

Example

In this example, an Int Synced Property of name "hp" is modified.
1
public void GotHit(int damage)
2
{
3
SyncPropertyAgent syncPropertyAgent = gameObject.GetComponent<SyncPropertyAgent>();
4
5
// change hp to 100
6
syncPropertyAgent.Modify("hp", 100);
7
}
Copied!
To get updates when a SyncProperty is modified, you can add a handler to the OnValueChange event of the SyncProperty.
1
public void OnHpChanged()
2
{
3
// read hp value
4
int currentHP = syncPropertyAgent.GetPropertyWithName("hp").GetIntValue();
5
}
Copied!