コード例 #1
0
 /**
  * Update is called once per frame.
  */
 private void Update()
 {
     if (this.interpolating && (this.targetTransform != null))
     {
         // Smoothly interpolate the position value
         this.duration += Time.deltaTime;
         float t = this.duration / this.smoothTime;
         this.transform.position   = Vector3.Lerp(this.smallPaladin.transform.position, this.targetTransform.position, t);
         this.transform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, t);
         if (t >= 1.0f)
         {
             //this.size = PaladinSizes.Big;
             //this.interpolating = false;
             GameObject        paladin = Instantiate(this.gameObject, this.transform.parent);
             PaladinController ctrl    = paladin.GetComponent <PaladinController>();
             ctrl.size = PaladinSizes.Big;
             ctrl.SetSmallPaladin(this.smallPaladin);
             ctrl.ResetSword();
             GameObject lookAtTarget = new GameObject();
             lookAtTarget.transform.SetParent(paladin.transform, false);
             lookAtTarget.transform.Translate(POINT_OF_INTEREST);
             if (UIArrows.IsInitialized)
             {
                 UIArrows.Instance.targetTransform = lookAtTarget.transform;
             }
             Destroy(this.gameObject);
         }
     }
 }
コード例 #2
0
        /**
         * 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();
            }
        }
コード例 #3
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();
            }
        }