void HandleRemotelyCreatedGameObject(GameObject gameObject, CreatedObjectMessage message) { // TODO: Many ways through the code in this function that would not result // in us clearing our 'busy' status. bool newAnchor = false; // Do we already know the anchor that the GameObject is associated with? var anchorObject = this.worldAnchorMap.GetById(message.ParentAnchorId); newAnchor = (anchorObject == null); // If we don't have one... if (newAnchor) { // Make one but it's not anchored at this point anchorObject = this.worldAnchorMap.AddAnchorWithExistingIdAtOrigin( message.ParentAnchorId); } // Parent the object off the anchor object, hoping that this // will be ok even if we later go on to import the anchor. gameObject.transform.SetParent(anchorObject.transform, false); gameObject.transform.localPosition = message.LocalPosition; gameObject.transform.localRotation = message.LocalRotation; this.sharedObjectsInSceneMessages.Add(message); this.ConfigureTransformSynchronizer(gameObject); #if !UNITY_EDITOR if (newAnchor) { // We need to go off to the cloud and download that anchor. AzureBlobStorageHelper.DownloadWorldAnchorBlob( this.storageDetails, message.ParentAnchorId, (worked, bits) => { if (worked) { // Having got the bits, we need to import them onto the // game object which means that this object is likely // to change its position and orientation. WorldAnchorImportExportHelper.ImportWorldAnchorToGameObject( anchorObject, bits, imported => { this.FireBusy(false); this.FireHologramCreatedRemotely(new Guid(message.ObjectId)); } ); } } ); } #else this.FireHologramCreatedRemotely(new Guid(message.ObjectId)); #endif }
void SendCreatedObjectMessage( string gameObjectType, GameObject gameObject, GameObject worldAnchorParent, Action <GameObject> callback) { var message = CreatedObjectMessage.Send( this.messageService, gameObjectType, gameObject, worldAnchorParent); this.sharedObjectsInSceneMessages.Add(message); if (callback != null) { callback(gameObject); } FireBusy(false); }