示例#1
0
    void Update()
    {
//		// don't consider taps over the UI
//		if(UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
//			return;

        // check for tap
        if (arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true))
        {
            MultiARInterop.InputAction action = arManager.GetInputAction();

            if (action == MultiARInterop.InputAction.Click || action == MultiARInterop.InputAction.Grip)
            {
                if (modelTransform && modelTransform.gameObject.activeSelf)
                {
                    // raycast world
                    //Vector2 screenPos = Input.GetTouch(0).position;
                    MultiARInterop.TrackableHit hit;

                    if (arManager.RaycastToWorld(true, out hit))
                    {
                        // set model's new position
                        SetModelWorldPos(hit.point, !verticalModel ? hit.rotation : Quaternion.identity);
                    }
                }
            }
        }

        // check if anchorId is still valid
        if (arManager && anchorId != string.Empty && !arManager.IsValidAnchorId(anchorId))
        {
            anchorId = string.Empty;
        }

        // update the model-active and anchor-active transforms
        UpdateModelToggle(modelActiveToggle, modelTransform);
        UpdateModelToggle(anchorActiveToggle, anchorTransform);

        // update the info-text
        if (infoText)
        {
            string sMsg = string.Empty;

            if (!bSessionPaused)
            {
                sMsg = (modelTransform && modelTransform.gameObject.activeSelf ?
                        "Model at " + modelTransform.transform.position + ", " : "No model, ");
                sMsg += (anchorTransform && anchorTransform.gameObject.activeSelf ?
                         "Anchor at " + anchorTransform.transform.position : "No anchor");
                sMsg += !string.IsNullOrEmpty(anchorId) ? "\nAnchorId: " + anchorId : string.Empty;
            }
            else
            {
                sMsg = "AR-Session is paused.";
            }

            infoText.text = sMsg;
        }
    }