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 HandleLocallyCreateGameObject(GameObject gameObject, string gameObjectType, Action <GameObject> callback) { // Do we have a world anchor for this position already? GameObject worldAnchorParent = null; bool addedAnchor = this.worldAnchorMap.GetOrAddWorldAnchorForPosition( gameObject.transform.position, gameObject.transform.forward, out worldAnchorParent); // parent the GameObject off its anchor without moving it, the assumption // being that if didn't already have an anchor then we just created it // at the same place as the object itself and so once we reparent we // are hoping that object and the anchor are identical in placement // (making for a LocalPosition of 0). gameObject.transform.SetParent(worldAnchorParent.transform, true); #if !UNITY_EDITOR // We only do this work with world anchors if we aren't in the editor // as I don't think a WorldAnchor in the editor will ever say that it // isLocated so it'll break our logic. if (addedAnchor) { // Now export that to get a bunch of bytes for it... WorldAnchorImportExportHelper.ExportWorldAnchorFromGameObject( worldAnchorParent, bits => { if (bits != null) { // We now need to send those bits off to the cloud... AzureBlobStorageHelper.UploadWorldAnchorBlob( this.storageDetails, worldAnchorParent.name, bits, (worked, bytes) => { this.ConfigureTransformSynchronizer(gameObject); this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); } ); } else { // TODO: figure what we do here and make sure that if we do it // then we don't forget to clear our busy status too. } } ); } else { this.ConfigureTransformSynchronizer(gameObject); // Send a message to the world telling them about the new object. this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); } #else // Send a message to the world telling them about the new object - it's // important to note that we pass whether we newly created an anchor or // not as that impacts the message that we send. this.ConfigureTransformSynchronizer(gameObject); this.SendCreatedObjectMessage( gameObjectType, gameObject, worldAnchorParent, callback); #endif }