Newer
Older
HoloAnatomy / Assets / HoloToolkit / Sharing / Scripts / SyncModel / SyncString.cs
SURFACEBOOK2\jackwynne on 25 May 2018 1 KB v1
  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. {
  6. /// <summary>
  7. /// This class implements the string primitive for the syncing system.
  8. /// It does the heavy lifting to make adding new strings to a class easy.
  9. /// </summary>
  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. }