示例#1
0
        /**
         * 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;
                    }
                }
            }
        }
示例#2
0
        /**
         * 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();
            }
        }