AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SyncSpawnArray.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 using System;
5 using UnityEngine;
7 
8 namespace HoloToolkit.Sharing.Spawning
9 {
15  public class SyncSpawnArray<T> : SyncArray<T> where T : SyncSpawnedObject, new()
16  {
17  public SyncSpawnArray(string field) : base(field) { }
18 
19  public SyncSpawnArray() : base(string.Empty) { }
20 
21  protected override T CreateObject(ObjectElement objectElement)
22  {
23  string objectType = objectElement.GetObjectType();
24 
25  Type typeToInstantiate = Type.GetType(objectType);
26  if (typeToInstantiate == null)
27  {
28  Debug.LogError("Could not find the SyncModel type to instantiate.");
29  return null;
30  }
31 
32  object createdObject = Activator.CreateInstance(typeToInstantiate);
33 
34  T spawnedDataModel = (T)createdObject;
35  spawnedDataModel.Element = objectElement;
36  spawnedDataModel.FieldName = objectElement.GetName();
37  // TODO: this should not query SharingStage, but instead query the underlying session layer
38  spawnedDataModel.Owner = SharingStage.Instance.SessionUsersTracker.GetUserById(objectElement.GetOwnerID());
39 
40  return spawnedDataModel;
41  }
42  }
43 }
virtual XString GetName()
Definition: Element.cs:53
A SpawnedObject contains all the information needed for another device to spawn an object in the same...
The SyncArray class provides the functionality of an array in the data model. The array holds entire ...
Definition: SyncArray.cs:17
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
override T CreateObject(ObjectElement objectElement)
Creates the object in the array, based on its underlying object element that came from the sync syste...
The SharingStage is in charge of managing the core networking layer for the application.
Definition: SharingStage.cs:14
This array is meant to hold SyncSpawnedObject and objects of subclasses. Compared to SyncArray...