AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SyncObjectSpawner.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 UnityEngine;
7 
8 namespace HoloToolkit.Sharing.Tests
9 {
13  public class SyncObjectSpawner : MonoBehaviour
14  {
15  [SerializeField]
16  private PrefabSpawnManager spawnManager = null;
17 
18  [SerializeField]
19  [Tooltip("Optional transform target, for when you want to spawn the object on a specific parent. If this value is not set, then the spawned objects will be spawned on this game object.")]
20  private Transform spawnParentTransform;
21 
22  private void Awake()
23  {
24  if (spawnManager == null)
25  {
26  Debug.LogError("You need to reference the spawn manager on SyncObjectSpawner.");
27  }
28 
29  // If we don't have a spawn parent transform, then spawn the object on this transform.
30  if (spawnParentTransform == null)
31  {
32  spawnParentTransform = transform;
33  }
34  }
35 
36  public void SpawnBasicSyncObject()
37  {
38  Vector3 position = Random.onUnitSphere * 2;
39  Quaternion rotation = Random.rotation;
40 
41  var spawnedObject = new SyncSpawnedObject();
42 
43  spawnManager.Spawn(spawnedObject, position, rotation, spawnParentTransform.gameObject, "SpawnedObject", false);
44  }
45 
46  public void SpawnCustomSyncObject()
47  {
48  Vector3 position = Random.onUnitSphere * 2;
49  Quaternion rotation = Random.rotation;
50 
51  var spawnedObject = new SyncSpawnTestSphere();
52  spawnedObject.TestFloat.Value = Random.Range(0f, 100f);
53 
54  spawnManager.Spawn(spawnedObject, position, rotation, spawnParentTransform.gameObject, "SpawnTestSphere", false);
55  }
56 
60  public void DeleteSyncObject()
61  {
62  GameObject hitObject = GazeManager.Instance.HitObject;
63  if (hitObject != null)
64  {
65  var syncModelAccessor = hitObject.GetComponent<DefaultSyncModelAccessor>();
66  if (syncModelAccessor != null)
67  {
68  var syncSpawnObject = (SyncSpawnedObject)syncModelAccessor.SyncModel;
69  spawnManager.Delete(syncSpawnObject);
70  }
71  }
72  }
73  }
74 }
The gaze manager manages everything related to a gaze ray that can interact with other objects...
Definition: GazeManager.cs:13
bool Spawn(SyncSpawnedObject dataModel, Vector3 localPosition, Quaternion localRotation, Vector3? localScale, GameObject parent, string baseName, bool isOwnedLocally)
Spawns content with the given parent. If no parent is specified it will be parented to the spawn mana...
Class that handles spawning sync objects on keyboard presses, for the SpawningTest scene...
void DeleteSyncObject()
Deletes any sync object that inherits from SyncSpawnObject.
Spawn manager that creates a GameObject based on a prefab when a new SyncSpawnedObject is created in ...
A SpawnedObject contains all the information needed for another device to spawn an object in the same...
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
Class that demonstrates a custom class using sync model attributes.
override void Delete(SyncSpawnedObject objectToDelete)
Default implementation of a MonoBehaviour that allows other components of a game object access the sh...