Ejemplo n.º 1
0
 private void Start()
 {
     WorldAnchorStore.GetAsync(AnchorStoreReady);
 }
Ejemplo n.º 2
0
 private void Awake()
 {
     Debug.Log("AnchorMaker: Looking for anchors...");
     WorldAnchorStore.GetAsync(StoreLoaded);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Callback function that contains the WorldAnchorStore object.
 /// </summary>
 /// <param name="anchorStore">The WorldAnchorStore to cache.</param>
 private void AnchorStoreReady(WorldAnchorStore anchorStore)
 {
     AnchorStore = anchorStore;
     print("loaded...");
 }
Ejemplo n.º 4
0
 private void Awake()
 {
     AnchorStore = null;
 }
 protected virtual void Start()
 {
     WorldAnchorStore.GetAsync(AnchorStoreReady);
 }
        /// <summary>
        /// Given a transfer batch, apply the batch's first anchor to the given game object. Once applied, attempt to
        /// save the new anchor to the app's local state. Note that this will delete the previously saved anchor before
        /// attempting to apply the new anchor. Therefore if the application fails, the old saved anchor will be lost.
        /// </summary>
        /// <returns>True if game object is anchored</returns>
        public bool ApplySharedLocation(GameObject gameObject, WorldAnchorTransferBatch batch, WorldAnchorStore store)
        {
            if (gameObject == null)
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor on null gameObject");
                return(false);
            }

            if (batch == null)
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with null WorldAnchorTransferBatch");
                return(false);
            }

            var batchIds = batch.GetAllIds();

            if (batchIds == null)
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an null id list on WorldAnchorTransferBatch");
                return(false);
            }

            if (batchIds.Length == 0)
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an empty WorldAnchorTransferBatch");
                return(false);
            }

            string storageIdString = batchIds[0];

            if (String.IsNullOrEmpty(storageIdString))
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an empty storage id");
                return(false);
            }

            Guid storageId;

            try
            {
                storageId = new Guid(storageIdString);
            }
            catch
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an invalid GUID");
                return(false);
            }

            if (store == null)
            {
                Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with null WorldAnchorStore");
                return(false);
            }

            Debug.Log("[PersistenceSaveLoad] Attempting to apply a shared world position: " + storageId);
            bool successful = false;

            // delete any previous WorldAnchors on this object
            DeleteLocation(gameObject, store);

            RaisePersistenceEvent(PersistenceEventType.ApplyingShared, gameObject, storageIdString);
            WorldAnchor.OnTrackingChangedDelegate trackingChanged = null;
            trackingChanged = (WorldAnchor self, bool located) =>
            {
                if (!located)
                {
                    Debug.Log("[PersistenceSaveLoad] Haven't located anchor yet: " + storageId);
                    return;
                }


                Debug.Log("[PersistenceSaveLoad] Located anchor: " + storageId);
                self.OnTrackingChanged -= trackingChanged;
                SaveExistingLocation(storageId, gameObject, store);
                RaisePersistenceEvent(PersistenceEventType.AppliedShared, gameObject, storageIdString);
            };

            // actually lock the game object to the batch's first anchor
            WorldAnchor anchor = batch.LockObject(storageIdString, gameObject);

            if (anchor != null)
            {
                anchor.OnTrackingChanged += trackingChanged;
                trackingChanged(anchor, anchor.isLocated);

                // assume locating is successful. If a caller wants to trully know when anchor was located, they should
                // listen for the "AppliedShared" and "Saved" events
                successful = true;
            }
            else
            {
                Debug.LogError("[PersistenceSaveLoad] Couldn't lock object with the given storage id: " + storageId);
            }

            return(successful);
        }
Ejemplo n.º 7
0
 void AnchorStoreReady(WorldAnchorStore store)
 {
     anchorStore  = store;
     CurrentState = ControlState.CheckAnchorStatus;
     DisplayUI.Instance.AppendText("Anchor Store Ready");
 }
Ejemplo n.º 8
0
        IEnumerator DoCalibration(bool recalibrate = false)
        {
#if !UNITY_EDITOR
            while (!WorldAnchorManager.IsInitialized)
            {
                yield return(null);
            }

            //give it some time
            yield return(new WaitForSeconds(2f));

            //get anchor store
            if (store == null)
            {
                WorldAnchorStore.GetAsync(GotStore);
                while (store == null)
                {
                    //Debug.Log("Bla");
                    yield return(null);
                }
            }

            //check if we have stored anchorData for this App & WIFI
            anchorXZ       = store.Load(strXZ, goXZ.gameObject);
            anchorMinXMinZ = store.Load(strMinXMinZ, goMinXMinZ.gameObject);
            anchorCenter   = store.Load(strCenter, optitrackCenter.gameObject);
            if (anchorCenter != null)
            {
                //load follow-up directly...
                //if (followupScene != null ) {
                //	SceneManager.LoadScene(followupScene);
                //}
                //yield break;

                //for now always recalibrate until it works...

                /*
                 * if (!recalibrate) {
                 *      //calibration already exists, only continue if we've forced re-calibration
                 *      //store current data (the actual positions will change every time you boot)
                 *      StartCoroutine(StoreCalibrationData());
                 *      yield break;
                 * } */
            }
#endif

            if (anchorCenter != null)
            {
                WorldAnchorManager.Instance.RemoveAnchor(optitrackCenter.gameObject);
                yield return(new WaitForSeconds(.25f));

                optitrackCenter.transform.position = Vector3.zero;
                optitrackCenter.transform.rotation = Quaternion.identity;
            }

            //display message "please place exactly 2 rigidbodies at XZ, -X-Z (two corners of the room)"
            feedbackCanvas.enabled = true;
            feedbackText.text      = "Place rigidbodies called \"xz\" and \"minxminz\" at positive and negative corners of the mocap space (found: 0).";
            feedbackButton.enabled = true;

            List <RigidbodyDefinition> defList = null;

            done = false;
            bool canContinue = false;
            while (!canContinue)
            {
                //check if there are three rigidbodies, and they are in the desired quadrants
                if (OptiTrackOSCClient.GetAllRigidbodies(out defList))
                {
                    int activeCount = 0;
                    for (int i = 0; i < defList.Count; ++i)
                    {
                        if (defList[i].isActive)
                        {
                            activeCount++;
                        }
                    }

                    feedbackText.text = "Place rigidbodies called \"xz\" and \"minxminz\" at positive and negative corners of the mocap space (found: " + activeCount + ").";

                    if (activeCount >= 2)
                    {
                        bool XZ = false, minXMinZ = false;
                        foreach (RigidbodyDefinition def in defList)
                        {
                            if (def.position.x > 0 && def.position.z > 0 && def.name == "xz")
                            {
                                XZ     = true;
                                vXZOsc = def.position;
                            }
                            if (def.position.x < 0 && def.position.z < 0 && def.name == "minxminz")
                            {
                                minXMinZ     = true;
                                vMinXMinZOsc = def.position;
                            }
                        }
                        if (XZ && minXMinZ && done)
                        {
                            canContinue = true;
                            continue;
                        }
                    }
                }
                yield return(null);
            }

            //display message: "align these three anchors with their correct rigidbody as best you can (height & rotation don't need to be exact)"
            //activate button
            feedbackCanvas.enabled = true;
            feedbackText.text      = "Align the two virtual anchors with the real objects you just placed. Say \"Next\" when you are done.";
            feedbackButton.enabled = true;

            //activate anchors that user must place
            goXZ.gameObject.SetActive(true);
            goMinXMinZ.gameObject.SetActive(true);

            //re-create/activate their world anchors
            ReAnchor(ref anchorXZ, ref goXZ);
            ReAnchor(ref anchorMinXMinZ, ref goMinXMinZ);

            //make sure they are movable
            goXZ.movable       = true;
            goMinXMinZ.movable = true;

            done = false;
            while (!done)
            {
                readyToCalibrate = true;
                yield return(null);
            }

            readyToCalibrate = false;

            //make sure we can't move the anchors anymore...
            goXZ.movable       = false;
            goMinXMinZ.movable = false;

            StartCoroutine(StoreCalibrationData());

            feedbackCanvas.enabled = false;

            yield return(null);
        }
Ejemplo n.º 9
0
 private void StoreLoaded(WorldAnchorStore store)
 {
     this.worldAnchorStore = store;
     Debug.Log("StoreLoaded: World anchor store loaded succesfully");
     storeLoaded = true;
 }
Ejemplo n.º 10
0
        /**
         * Try to load the world anchors that are saved in the World Anchor Store of the HoloLens device.
         */
        private void LoadWorldAnchors()
        {
#if UNITY_EDITOR
            this.worldAnchorsLoaded = true;
#elif ENABLE_WINMD_SUPPORT
            WorldAnchorStore store = this.anchorManager.AnchorStore;
            if ((store != null) && HoloToolkit.Unity.SpatialUnderstanding.IsInitialized)
            {
                // Get spatial understanding references
                HoloToolkit.Unity.SpatialUnderstanding suScript = HoloToolkit.Unity.SpatialUnderstanding.Instance;
                GameObject suObj      = suScript.gameObject;
                CachedRoom roomScript = suObj.GetComponent <CachedRoom>();

                // Get all world anchor IDs
                string[] ids = store.GetAllIds();
                this.logger.Log("Active world anchors:");

                // Try to interpret the anchors
                for (int index = 0; index < ids.Length; index++)
                {
                    // Print out all anchor IDs
                    string anchorID = ids[index];
                    this.logger.Log("        " + anchorID);

                    // Check if we have a cached room anchored
                    if ((roomScript != null) && anchorID.Equals(roomScript.fileName))
                    {
                        suScript.CleanupUnderstanding();
                        roomScript.LoadRoom();
                        this.CurrentScanState = ScanState.UserMode;

                        // Try to load the artwork anchors
                    }
                    else if ((anchorID.Length > RecognizedArtwork.ARTWORK_ANCHOR_PREFIX.Length) && anchorID.Substring(0, RecognizedArtwork.ARTWORK_ANCHOR_PREFIX.Length).Equals(RecognizedArtwork.ARTWORK_ANCHOR_PREFIX))
                    {
                        // The anchor ID should have a specific format
                        try {
                            int id = int.Parse(anchorID.Substring(RecognizedArtwork.ARTWORK_ANCHOR_PREFIX.Length));
                            if (this.IsIdEligible(id))
                            {
                                // Instantiate the anchors far away from the camera collider to avoid early collision
                                GameObject gameObject = Instantiate(this.scanningArea, new Vector3(0.0f, 10.0f, 0.0f), Quaternion.identity);
                                this.anchorManager.AttachAnchor(gameObject, anchorID);
                                ScanningArea anchor = gameObject.GetComponent <ScanningArea>();
                                anchor.artworkID = id;
                                anchor.ActivateCollider();
                                this.worldAnchors[id] = true;
                                this.newRoom          = false;
                            }
                            else
                            {
                                this.logger.Log("World anchor ID " + id + " not eligible.");
                            }
                        } catch (System.Exception ex) {
                            this.logger.Log("EXCEPTION: " + ex.Message);
                        }
                    }
                }

                // Remove all anchors if the room is not cached or a cached room has no cached scan areas
                if ((!this.newRoom && (this.CurrentScanState != ScanState.UserMode)) || (this.newRoom && (this.CurrentScanState == ScanState.UserMode)))
                {
                    this.anchorManager.RemoveAllAnchors();
                    this.TabulaRasa();
                }

                this.worldAnchorsLoaded = true;
            }
#endif
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Callback function that contains the WorldAnchorStore object.
 /// </summary>
 /// <param name="anchorStore">The WorldAnchorStore to cache.</param>
 private void AnchorStoreReady(WorldAnchorStore anchorStore)
 {
     AnchorStore = anchorStore;
 }
Ejemplo n.º 12
0
 private void Start()
 {
     WorldAnchorStore.GetAsync(StoreLoaded);
     InteractionManager.InteractionSourcePressed += InteractionSourcePressed;
 }
Ejemplo n.º 13
0
    void AnchorStoreReady(WorldAnchorStore store)
    {
        anchorStore = store;

        // list of strings
        List <string> spawnIds           = new List <string>();
        List <string> dummySpawnIds      = new List <string>();
        List <string> ammoBoxIds         = new List <string>();
        List <string> infiniteAmmoBoxIds = new List <string>();
        List <string> mistIds            = new List <string>();
        List <string> hotspotIds         = new List <string>();


        // gather all stored anchors
        string[] ids = anchorStore.GetAllIds();

        for (int index = 0; index < ids.Length; index++)
        {
            if (ids[index] == AnchorName_StemBase)
            {
                // if anchor is stem base
                GameObject    obj     = Instantiate(stemBase) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(false);
                stemBasePlaced = true;
            }
            else if (ids[index] == AnchorName_ConsoleObject)
            {
                // if anchor is console object
                GameObject    obj     = Instantiate(consoleObject) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(true);
                pscript.KeepUpright(true);
            }
            else if (ids[index] == AnchorName_ScoreBoard)
            {
                // if anchor is the scoreboard
                GameObject    obj     = Instantiate(scoreboard) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(true);
                pscript.KeepUpright(true);
                scoreboardPlaced = true;
            }

            //----------------------------------------------------------------
            else if (ids[index] == AnchorName_Target)
            {
                // if anchor is weapons rack
                GameObject    obj     = Instantiate(target) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(true);
                pscript.KeepUpright(true);
                targetPlaced = true;
            }

            //----------------------------------------------------------------

            else if (ids[index] == AnchorName_StartButton)
            {
                // if anchor is weapons rack
                GameObject    obj     = Instantiate(startButton) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(true);
                pscript.KeepUpright(true);
                startButtonPlaced = true;
            }

            //----------------------------------------------------------------
            else if (ids[index] == AnchorName_MetalBarrel)
            {
                // if anchor is weapons rack
                GameObject    obj     = Instantiate(metalBarrel) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pscript.SetRotateOnNormals(true);
                pscript.KeepUpright(true);
            }


            else if (ids[index] == AnchorName_PathFinder)
            {
                // if anchor is the pathfinder object
                GameObject    obj     = Instantiate(pathFinder) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                pathFinderPlaced = true;
            }

            else if (ids[index] == AnchorName_MistEnd)
            {
                // if anchor is the mistEnd
                GameObject    obj     = Instantiate(mistEnd) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                mist_End_Placed = true;
            }
            else if (ids[index] == AnchorName_MistEmitter)
            {
                // if anchor is the mistEnd
                GameObject    obj     = Instantiate(mist) as GameObject;
                PersistoMatic pscript = obj.GetComponent <PersistoMatic>();
                pscript.SetAnchorStoreName(ids[index]);
                mistPlaced = true;
            }



            else if (ids[index].Contains(AnchorName_AmmoBoxInfinite))
            {
                // if anchor is an infinite ammo box
                // get id number
                int thisId = int.Parse(ids[index].Substring(AnchorName_AmmoBoxInfinite.Length));

                // set spawn id to highest anchorIdNum
                if (thisId > spawnIdNum)
                {
                    infiniteAmmoBoxIdNum = thisId;
                }

                // add id to string list to instantiate later
                infiniteAmmoBoxIds.Add(ids[index]);
            }


            else if (ids[index].Contains(AnchorName_SpawnPoint))
            {
                // if anchor is a spawn point
                // get spawn id number
                int thisId = int.Parse(ids[index].Substring(AnchorName_SpawnPoint.Length));

                // set spawn id to highest anchorIdNum
                if (thisId > spawnIdNum)
                {
                    spawnIdNum = thisId;
                }

                // add id to string list to instantiate later
                spawnIds.Add(ids[index]);
            }



            else if (ids[index].Contains(AnchorName_HotSpot))
            {
                // if anchor is a hostpot
                // get id number
                int thisId = int.Parse(ids[index].Substring(AnchorName_HotSpot.Length));

                // set spawn id to highest anchorIdNum
                if (thisId > hotspotIdNum)
                {
                    hotspotIdNum = thisId;
                }

                // add id to string list to instantiate later
                hotspotIds.Add(ids[index]);
            }
        }

        //-------------------------------------------------------------------------------------------------------------
        // load and instantiate all infinite ammo boxes
        foreach (string id in infiniteAmmoBoxIds)
        {
            infiniteAmmoBoxes.Add(InstantiateObject(infiniteAmmoBox, id));
        }

        // load and instantiate all spawn points
        foreach (string id in spawnIds)
        {
            spawns.Add(InstantiateObject(spawnPoint, id));
        }



        // load and instantiate all hostpot objects
        foreach (string id in hotspotIds)
        {
            hotspots.Add(InstantiateObject(hotspot, id));
        }
    }
Ejemplo n.º 14
0
 private void StoreLoaded(WorldAnchorStore store)
 {
     anchorStore = store;
 }
Ejemplo n.º 15
0
 // Start is called before the first frame update
 void Start()
 {
     rootGameObject = GameObject.Find("Sphere");
     WorldAnchorStore.GetAsync(StoreLoaded);
 }
Ejemplo n.º 16
0
 void GotStore(UnityEngine.XR.WSA.Persistence.WorldAnchorStore newStore)
 {
     Debug.Log("GOT STORE");
     store = newStore;
 }
Ejemplo n.º 17
0
 public void SetAnchorStoreName(string value)
 {
     anchorStoreName     = value;
     AnchorStoreBaseName = value;
     WorldAnchorStore.GetAsync(AnchorStoreReady);
 }
 protected override void Awake()
 {
     base.Awake();
     AnchorStore = null;
 }
Ejemplo n.º 19
0
 public void Start()
 {
     WorldAnchorStore.GetAsync(WorldAnchorStoreLoaded);
 }
Ejemplo n.º 20
0
 private void Start()
 {
     device = coreDevice.GetComponent <SixenseCore.Device>();
     WorldAnchorStore.GetAsync(AnchorStoreReady);
 }
Ejemplo n.º 21
0
 private void WorldAnchorStoreLoaded(WorldAnchorStore store)
 {
     _store = store;
     LoadAllAnchors();
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Called when the local anchor store is ready.
 /// </summary>
 /// <param name="store"></param>
 void AnchorStoreReady(WorldAnchorStore store)
 {
     anchorStore  = store;
     CurrentState = ImportExportState.AnchorStore_Initialized;
 }
Ejemplo n.º 23
0
 private void Awake()
 {
     WorldAnchorStore.GetAsync(StoreLoaded);
 }