OnValueSyncedAttribute
Designates a method to be called when the value of a synced field or property changes on a remote instance.
Examples
using UnityEngine;
using Coherence.Toolkit;
using UnityEngine.Scripting;
public class Example : MonoBehaviour
{
[Sync]
public int myInt;
[Preserve, OnValueSynced(nameof(myInt))]
void OnMyIntSynced(int oldValue, int newValue)
{
// ...
}
}
using UnityEngine;
using Coherence.Toolkit;
using UnityEngine.Scripting;
public class Example : MonoBehaviour
{
[Sync]
[OnValueSynced(nameof(OnBoxColliderSynced))]
public BoxCollider boxCollider;
[Preserve]
void OnBoxColliderSynced(BoxCollider oldValue, BoxCollider newValue)
{
// ...
}
}
Remarks
This attribute can be applied to a field, a property, or a method.
- Applied to a field or property — Member identifies the name of the method to invoke when the value of the decorated member changes.
- Applied to a method — Member identifies the name of the synced field or property whose changes trigger the decorated method.
- If applied to both a method and a field or property, relating to one another, the field or property one takes precedence.
- It must be defined in the same component as the synced field or property.
- It must declare exactly two parameters of same type as the synced field or property. These parameters represent the previous and the current value.
Constructors
| OnValueSyncedAttribute | Initializes a new instance of OnValueSyncedAttribute with the specified member name. |
Fields
| Member | Gets the name of the member linked to this attribute. |
Properties
| Callback | Gets the name of the member linked to this attribute. |
| SuppressNotBoundError | Suppress error when the attribute targets a field or property not marked as synced. |
| SuppressParamOrderError | Suppress error when the attribute targets a method where parameter naming suggests incorrect order. |