/** * Handle the placement query. * * @param success indicates whether the placement query was successful * @param position position result of the placement query */ private void HandlePlacementQuery(bool success, Vector3 position) { if (success) { this.assetAnchor = Instantiate(this.worldAnchorParent, position, this.transform.rotation); this.anchorManager.RemoveAnchor(ANCHOR_ID); this.anchorManager.AttachAnchor(this.assetAnchor, ANCHOR_ID); GameObject paladin = Instantiate(this.gameObject, this.assetAnchor.transform); PaladinController ctrl = paladin.GetComponent <PaladinController>(); ctrl.ResetSword(); ctrl.Grow(this.assetAnchor.transform, this.gameObject); this.gameObject.SetActive(false); } else if (InfoCanvas.IsInitialized) { InfoCanvas.Instance.SetInfoText("An adequate floor position couldn't be found."); } // Activate input again if (InputManager.IsInitialized) { InputManager.Instance.PopInputDisable(); } }
/** * This method is called when the user has clicked on this GameObject. * * @param eventData input click event data */ public void OnInputClicked(InputClickedEventData eventData) { if ((this.size == PaladinSizes.Small) && (!this.interpolating)) { #if UNITY_EDITOR GameObject paladin = Instantiate(this.gameObject); PaladinController ctrl = paladin.GetComponent <PaladinController>(); ctrl.ResetSword(); ctrl.Grow(this.transform.parent, this.gameObject); this.gameObject.SetActive(false); #else this.anchorManager = WorldAnchorManager.Instance; bool found = false; // Check if we have already instantiated a world anchor if (this.assetAnchor != null) { GameObject paladin = Instantiate(this.gameObject, this.assetAnchor.transform); PaladinController ctrl = paladin.GetComponent <PaladinController>(); ctrl.ResetSword(); ctrl.Grow(this.assetAnchor.transform, this.gameObject); this.gameObject.SetActive(false); found = true; } else if (this.anchorManager != null) { // Check if a world anchor for this asset exists UnityEngine.VR.WSA.Persistence.WorldAnchorStore store = this.anchorManager.AnchorStore; if (store != null) { string[] ids = store.GetAllIds(); for (int index = 0; (index < ids.Length) && !found; index++) { if (ids[index].Equals(ANCHOR_ID)) { this.assetAnchor = Instantiate(this.worldAnchorParent); this.anchorManager.AttachAnchor(this.assetAnchor, ANCHOR_ID); GameObject paladin = Instantiate(this.gameObject, this.assetAnchor.transform); PaladinController ctrl = paladin.GetComponent <PaladinController>(); ctrl.ResetSword(); ctrl.Grow(this.assetAnchor.transform, this.gameObject); this.gameObject.SetActive(false); found = true; } } } } // Try to query SpatialUnderstanding if a world anchor was not found if (!found && (this.anchorManager != null)) { SpatialUnderstanding suInstance = SpatialUnderstanding.Instance; PlacementSolver solver = PlacementSolver.Instance; if ((suInstance != null) && (solver != null) && InputManager.IsInitialized && (suInstance.ScanState == SpatialUnderstanding.ScanStates.Done) && suInstance.AllowSpatialUnderstanding) { InputManager.Instance.PushInputDisable(); solver.Query_OnFloor_NearPoint(this.transform.parent.position, false, this.HandlePlacementQuery); } } #endif } else if ((this.size == PaladinSizes.Big) && (!this.interpolating)) { this.Die(); } }