AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SyncString.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 namespace HoloToolkit.Sharing.SyncModel
5 {
10  public class SyncString : SyncPrimitive
11  {
12  private StringElement element;
13  private string value = "";
14 
15 #if UNITY_EDITOR
16  public override object RawValue
17  {
18  get { return value; }
19  }
20 #endif
21 
22  public string Value
23  {
24  get { return value; }
25 
26  set
27  {
28  // Has the value actually changed?
29  if (this.value != value)
30  {
31  // Change the value
32  this.value = value;
33 
34  if (element != null)
35  {
36  // Notify network that the value has changed
37  element.SetValue(new XString(value));
38  }
39  }
40  }
41  }
42 
43  public SyncString(string field) : base(field) { }
44 
45  public override void InitializeLocal(ObjectElement parentElement)
46  {
47  element = parentElement.CreateStringElement(XStringFieldName, new XString(value));
48  NetworkElement = element;
49  }
50 
51  public void AddFromLocal(ObjectElement parentElement, string localValue)
52  {
53  InitializeLocal(parentElement);
54  Value = localValue;
55  }
56 
57  public override void AddFromRemote(Element remoteElement)
58  {
59  NetworkElement = remoteElement;
60  element = StringElement.Cast(remoteElement);
61  value = element.GetValue().GetString();
62  }
63 
64  public override void UpdateFromRemote(XString remoteValue)
65  {
66  value = remoteValue.GetString();
67  }
68  }
69 }
void AddFromLocal(ObjectElement parentElement, string localValue)
Definition: SyncString.cs:51
virtual void SetValue(XString newString)
override void InitializeLocal(ObjectElement parentElement)
Initializes this object for local use. Doesn't wait for network initialization.
Definition: SyncString.cs:45
Base primitive used to define an element within the data model. The primitive is defined by a field a...
This class implements the string primitive for the syncing system. It does the heavy lifting to make ...
Definition: SyncString.cs:10
static StringElement Cast(Element element)
override void UpdateFromRemote(XString remoteValue)
Called when the primitive value has changed from a remote action.
Definition: SyncString.cs:64
override void AddFromRemote(Element remoteElement)
Called when being remotely initialized.
Definition: SyncString.cs:57
virtual StringElement CreateStringElement(XString name, XString value)