AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SyncBool.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 SyncBool : SyncPrimitive
11  {
12  private BoolElement element;
13  private bool value;
14 
15 #if UNITY_EDITOR
16  public override object RawValue
17  {
18  get { return value; }
19  }
20 #endif
21 
22  public bool 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(value);
38  }
39  }
40  }
41  }
42 
43  public SyncBool(string field) : base(field) { }
44 
45  public override void InitializeLocal(ObjectElement parentElement)
46  {
47  element = parentElement.CreateBoolElement(XStringFieldName, value);
48  NetworkElement = element;
49  }
50 
51  public void AddFromLocal(ObjectElement parentElement, bool localValue)
52  {
53  InitializeLocal(parentElement);
54  Value = localValue;
55  }
56 
57  public override void AddFromRemote(Element remoteElement)
58  {
59  NetworkElement = remoteElement;
60  element = BoolElement.Cast(remoteElement);
61  value = element.GetValue();
62  }
63 
64  public override void UpdateFromRemote(bool remoteValue)
65  {
66  value = remoteValue;
67  }
68  }
69 }
static BoolElement Cast(Element element)
Definition: BoolElement.cs:42
virtual void SetValue(bool newValue)
Definition: BoolElement.cs:53
Base primitive used to define an element within the data model. The primitive is defined by a field a...
This class implements the boolean primitive for the syncing system. It does the heavy lifting to make...
Definition: SyncBool.cs:10
void AddFromLocal(ObjectElement parentElement, bool localValue)
Definition: SyncBool.cs:51
override void AddFromRemote(Element remoteElement)
Called when being remotely initialized.
Definition: SyncBool.cs:57
override void InitializeLocal(ObjectElement parentElement)
Initializes this object for local use. Doesn't wait for network initialization.
Definition: SyncBool.cs:45
virtual BoolElement CreateBoolElement(XString name, bool value)
override void UpdateFromRemote(bool remoteValue)
Called when the primitive value has changed from a remote action.
Definition: SyncBool.cs:64