/** * Use this for initialization that has to be done before the Start() function of other GameObjects is invoked. */ private void Awake() { if (ShapeDetection.Instance == null) { ShapeDetection.Instance = this; } }
/** * This method is called when this object will be destroyed. */ protected override void OnDestroy() { base.OnDestroy(); if (ShapeDetection.Instance == this) { ShapeDetection.Instance = null; } }
/** * Perform necessary calculations for the 3D asset of this artwork. */ private void Perform3DAssetCalculations() { bool found = false; #if ENABLE_WINMD_SUPPORT // Check if a world anchor of this artwork exists UnityEngine.VR.WSA.Persistence.WorldAnchorStore store = this.anchorManager.AnchorStore; if (store != null) { string[] ids = store.GetAllIds(); // Try to find the world anchor of the 3D asset this.logger.Log("Find 3D assets's world anchor:"); for (int index = 0; (index < ids.Length) && !found; index++) { string anchorID = ids[index]; // The anchor ID should have a specific format if ((anchorID.Length > ASSET_ANCHOR_PREFIX.Length) && anchorID.Substring(0, ASSET_ANCHOR_PREFIX.Length).Equals(ASSET_ANCHOR_PREFIX)) { try { int id = int.Parse(anchorID.Substring(ASSET_ANCHOR_PREFIX.Length)); if (id == this.artwork.artworkID) { this.logger.Log(" -> found: " + anchorID); this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); this._3DButton.GetComponent <Button>().interactable = true; found = true; } } catch (System.Exception ex) { this.logger.Log("EXCEPTION: " + ex.Message); } } } } #endif // Try to query SpatialUnderstanding if a world anchor was not found if (!found) { SpatialUnderstanding suInstance = SpatialUnderstanding.Instance; ShapeDetection shapeDetection = ShapeDetection.Instance; PlacementSolver solver = PlacementSolver.Instance; HoloToolkit.Unity.InputModule.InputManager inputManager = HoloToolkit.Unity.InputModule.InputManager.Instance; if ((suInstance != null) && (solver != null) && (shapeDetection != null) && (inputManager != null) && (suInstance.ScanState == SpatialUnderstanding.ScanStates.Done) && suInstance.AllowSpatialUnderstanding) { switch (this.artwork.artworkID) { case 2: inputManager.PushInputDisable(); this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); shapeDetection.FindTable(this.middlePoint, this.HandleArtwork2); break; case 3: inputManager.PushInputDisable(); this._3DButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); solver.Query_OnFloor_NearPoint(this.middlePoint, false, this.HandleArtwork3); break; } } } }