-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncString.cs
71 lines (61 loc) · 1.99 KB
/
SyncString.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
//
namespace HoloToolkit.Sharing.SyncModel
{
/// <summary>
/// This class implements the string primitive for the syncing system.
/// It does the heavy lifting to make adding new strings to a class easy.
/// </summary>
public class SyncString : SyncPrimitive
{
private StringElement element;
private string value = "";
#if UNITY_EDITOR
public override object RawValue
{
get { return value; }
}
#endif
public string Value
{
get { return value; }
set
{
// Has the value actually changed?
if (this.value != value)
{
// Change the value
this.value = value;
if (element != null)
{
// Notify network that the value has changed
element.SetValue(new XString(value));
}
}
}
}
public SyncString(string field) : base(field) { }
public override void InitializeLocal(ObjectElement parentElement)
{
element = parentElement.CreateStringElement(XStringFieldName, new XString(value));
NetworkElement = element;
}
public void AddFromLocal(ObjectElement parentElement, string localValue)
{
InitializeLocal(parentElement);
Value = localValue;
}
public override void AddFromRemote(Element remoteElement)
{
NetworkElement = remoteElement;
element = StringElement.Cast(remoteElement);
value = element.GetValue().GetString();
}
public override void UpdateFromRemote(XString remoteValue)
{
value = remoteValue.GetString();
}
}
}