Table of Contents

Class CoherenceSyncUtils

Namespace
Coherence.Editor
Assembly
Coherence.Editor.dll

Utility class for CoherenceSync related operations.

public static class CoherenceSyncUtils
Inheritance
CoherenceSyncUtils

Methods

AddBinding(CoherenceSync, Component, Descriptor)

Adds a Binding to a CoherenceSync.

public static Binding AddBinding(CoherenceSync sync, Component component, Descriptor descriptor)

Parameters

sync CoherenceSync
component Component
descriptor Descriptor

Returns

Binding

AddBinding(CoherenceSync, Component, string)

public static Binding AddBinding(CoherenceSync sync, Component component, string memberName)

Parameters

sync CoherenceSync
component Component
memberName string

Returns

Binding

AddBinding(GameObject, Type, string)

public static Binding AddBinding(GameObject gameObject, Type type, string memberName)

Parameters

gameObject GameObject
type Type
memberName string

Returns

Binding

AddBinding<T>(GameObject, string)

public static Binding AddBinding<T>(GameObject gameObject, string memberName) where T : Component

Parameters

gameObject GameObject
memberName string

Returns

Binding

Type Parameters

T

DestroyCoherenceComponents(GameObject)

Destroys the CoherenceSync component for the given GameObject, and any other component that depends on it.

public static void DestroyCoherenceComponents(GameObject gameObject)

Parameters

gameObject GameObject

Exceptions

ArgumentNullException

When gameObject is null.

IsBindingValid(CoherenceSync, Binding, out string)

Check if an existing synced member is still valid.

public static bool IsBindingValid(CoherenceSync sync, Binding binding, out string invalidReason)

Parameters

sync CoherenceSync
binding Binding

The Binding instance that represents a synced member.

invalidReason string

If the binding is invalid, this string holds the reason why.

Returns

bool

true if the binding is valid; false otherwise.

Remarks

A binding is valid if:

  1. The target Component exists.
  2. The associated Descriptor for the given Component type exists.

RemoveBinding(CoherenceSync, Binding)

Removes a Binding from a CoherenceSync.

public static bool RemoveBinding(CoherenceSync sync, Binding binding)

Parameters

sync CoherenceSync
binding Binding

Returns

bool

RemoveBinding(CoherenceSync, Component, Descriptor)

Removes a Binding from a CoherenceSync.

public static bool RemoveBinding(CoherenceSync sync, Component component, Descriptor descriptor)

Parameters

sync CoherenceSync
component Component
descriptor Descriptor

Returns

bool

RemoveBinding(CoherenceSync, Component, string)

public static bool RemoveBinding(CoherenceSync sync, Component component, string memberName)

Parameters

sync CoherenceSync
component Component
memberName string

Returns

bool

RemoveBinding(GameObject, Type, string)

public static bool RemoveBinding(GameObject gameObject, Type type, string memberName)

Parameters

gameObject GameObject
type Type
memberName string

Returns

bool

RemoveBinding<T>(GameObject, string)

public static bool RemoveBinding<T>(GameObject gameObject, string memberName) where T : Component

Parameters

gameObject GameObject
memberName string

Returns

bool

Type Parameters

T

RemoveBindings(CoherenceSync, Predicate<Binding>)

public static int RemoveBindings(CoherenceSync sync, Predicate<Binding> match)

Parameters

sync CoherenceSync
match Predicate<Binding>

Returns

int

RemoveInvalidBindings(CoherenceSync)

Removes all invalid Bindings from a given CoherenceSync.

public static int RemoveInvalidBindings(CoherenceSync sync)

Parameters

sync CoherenceSync

Returns

int

Number of Bindings removed.

See Also

TryConvertToCoherenceSyncPrefab(GameObject, string, out GameObject, InteractionMode)

Adds a CoherenceSync component and converts a GameObject into a Prefab. Prefabs using CoherenceSync are ready to be networked by coherence.

public static bool TryConvertToCoherenceSyncPrefab(GameObject gameObject, string prefabPath, out GameObject prefab, InteractionMode interactionMode = 1)

Parameters

gameObject GameObject

GameObject to convert into a Prefab.

prefabPath string

Path where the Prefab Asset will be written on disk.

prefab GameObject

Reference to the Prefab Asset.

interactionMode InteractionMode

The interaction mode for this action.

Returns

bool

true if the Prefab Asset gets created; false otherwise.

UpdateBindings(CoherenceSync)

Updates Binding Descriptors, adds missing required Bindings, and removes invalid Bindings.

public static bool UpdateBindings(CoherenceSync sync)

Parameters

sync CoherenceSync

The target component.

Returns

bool

true if the component gets modified; false otherwise.

Remarks

When creating CoherenceSync components from code, you must call this method to ensure Bindings are up-to-date.

Exceptions

ArgumentNullException

When sync is null.

See Also

Events

OnBeforeBindingAdded

Raised before adding a binding to Bindings.

public static event Action<CoherenceSync, Binding> OnBeforeBindingAdded

Event Type

Action<CoherenceSync, Binding>

OnBeforeBindingRemoved

Raised before deleting a binding from Bindings.

public static event Action<CoherenceSync, Binding> OnBeforeBindingRemoved

Event Type

Action<CoherenceSync, Binding>