void Update() { // check for local & active player if (!isLocalPlayer) { return; } if (!gameObject.activeSelf) { return; } if (!arMainCamera && arManager && arManager.IsInitialized()) { arMainCamera = arManager.GetMainCamera(); } if (arMainCamera) { transform.position = arMainCamera.transform.position; transform.rotation = arMainCamera.transform.rotation; } // fire when clicked (world anchor must be present) if (arClient && arClient.WorldAnchorObj != null && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click) { CmdFire(); } } }
// // invoked when the hold-gesture is started by the user // void GestureRecognizer_HoldStarted(HoldStartedEventArgs obj) // { // inputAction = MultiARInterop.InputAction.Grip; // inputTimestamp = lastFrameTimestamp; // Debug.Log("GestureRecognizer_HoldStarted"); // } // // // invoked when the hold-gesture is completed by the user // void GestureRecognizer_HoldCompleted(HoldCompletedEventArgs obj) // { // inputAction = MultiARInterop.InputAction.Release; // inputTimestamp = lastFrameTimestamp; // Debug.Log("GestureRecognizer_HoldCompleted"); // } // // // invoked when the hold-gesture is canceled by the user // void GestureRecognizer_HoldCanceled(HoldCanceledEventArgs obj) // { // inputAction = MultiARInterop.InputAction.Release; // inputTimestamp = lastFrameTimestamp; // Debug.Log("GestureRecognizer_HoldCanceled"); // } void GestureRecognizer_NavigationStarted(NavigationStartedEventArgs obj) { inputAction = MultiARInterop.InputAction.Grip; inputNavCoordinates = Vector3.zero; inputTimestamp = lastFrameTimestamp; //Debug.Log("GestureRecognizer_NavigationStarted"); }
void GestureRecognizer_NavigationUpdated(NavigationUpdatedEventArgs obj) { inputAction = MultiARInterop.InputAction.Grip; inputNavCoordinates = obj.normalizedOffset; inputTimestamp = lastFrameTimestamp; //Debug.Log("GestureRecognizer_NavigationUpdated: " + obj.normalizedOffset); }
// invoked when the tap-gesture is done by the user void GestureRecognizer_Tapped(TappedEventArgs obj) { inputAction = MultiARInterop.InputAction.Click; inputNavCoordinates = Vector3.zero; inputTimestamp = lastFrameTimestamp; //Debug.Log("GestureRecognizer_Tapped"); }
void Update() { // // don't consider taps over the UI // if(UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) // return; // check for click if (objectPrefab && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click) { // raycast world //Vector2 screenPos = Input.GetTouch(0).position; MultiARInterop.TrackableHit hit; if (arManager.RaycastToWorld(true, out hit)) { // instantiate the object and anchor it to the world position GameObject spawnObj = Instantiate(objectPrefab, hit.point, !verticalModel ? hit.rotation : Quaternion.identity); arManager.AnchorGameObjectToWorld(spawnObj, hit); // look at the camera if (modelLookingAtCamera) { Camera arCamera = arManager.GetMainCamera(); MultiARInterop.TurnObjectToCamera(spawnObj, arCamera, hit.point, hit.normal); } } } } }
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; } }
void InteractionManager_InteractionSourceReleased(InteractionSourceReleasedEventArgs obj) { if (obj.pressType == InteractionSourcePressType.Thumbstick) { inputAction = MultiARInterop.InputAction.Release; inputTimestamp = lastFrameTimestamp; } }
void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj) { if (obj.state.thumbstickPressed) { inputAction = MultiARInterop.InputAction.Grip; inputNavCoordinates = obj.state.thumbstickPosition; inputTimestamp = lastFrameTimestamp; } }
// Update is called once per frame void Update() { //// test only //if(arManager && arManager.IsInitialized()) //{ // Texture texBack = arManager.GetBackgroundTex(); //} // check for click if (ballPrefab && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click) { // gets the main camera Camera arCamera = arManager.GetMainCamera(); if (!arCamera) { return; } // raycast scene objects (including overlay surfaces) MultiARInterop.TrackableHit hit; Vector3 targetPoint = Vector3.zero; if (arManager.RaycastToScene(true, out hit)) { targetPoint = hit.point; } else { targetPoint = arCamera.transform.forward * 3f; // emulate target in the line of sight } // instantiate the cannonball. schedule it for destroy in 3 seconds GameObject cannonBall = Instantiate(ballPrefab, arCamera.transform.position, arCamera.transform.rotation); cannonBall.name = ballPrefab.name + "-" + objectCounter; objectCounter++; if (destroyInSeconds > 0f) { Destroy(cannonBall, destroyInSeconds); } // set random ball material SetBallMaterial(cannonBall); // fire the cannonball targetPoint.y -= aimAboveDistance; FireCannonball(cannonBall, arCamera.transform.position, targetPoint); } } }
void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs evt) { if (evt.state.source.kind == InteractionSourceKind.Hand || (evt.state.source.kind == InteractionSourceKind.Controller && evt.state.source.handedness == controllerHandedness)) { GetHandPosAndDir(evt.state.sourcePose, evt.state.source.kind == InteractionSourceKind.Controller); if (isHandGripping != evt.state.anyPressed) { isHandGripping = evt.state.anyPressed; if (evt.state.source.kind == InteractionSourceKind.Controller) { if (isHandGripping) { inputAction = MultiARInterop.InputAction.Click; inputNavCoordinates = Vector3.zero; startMousePos = mainCamera.transform.InverseTransformPoint(handPosition); startTimestamp = inputTimestamp = lastFrameTimestamp; Debug.Log("Click, Pos: " + handPosition + ", Time: " + lastFrameTimestamp); } else { if ((lastFrameTimestamp - startTimestamp) >= 0.25f) // check for Grip { inputAction = MultiARInterop.InputAction.Release; inputTimestamp = lastFrameTimestamp; Debug.Log("Release, Pos: " + handPosition + ", Time: " + lastFrameTimestamp); } } } } if (evt.state.source.kind == InteractionSourceKind.Controller && isHandGripping) { if ((lastFrameTimestamp - startTimestamp) >= 0.25f) { inputAction = MultiARInterop.InputAction.Grip; Vector3 localHandPos = mainCamera.transform.InverseTransformPoint(handPosition); inputNavCoordinates = (localHandPos - startMousePos) / 0.5f; inputTimestamp = lastFrameTimestamp; Debug.Log("Grip, Pos: " + handPosition + ", Nav: " + inputNavCoordinates + ", Time: " + lastFrameTimestamp); } } // if (evt.state.source.kind == InteractionSourceKind.Controller && !isHandGripping) // { // Debug.Log ("Cursor, Pos: " + handPosition + ", Time: " + lastFrameTimestamp); // } } }
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) { // check if there is a model selected if (currentModel == null) { Debug.LogError("No model selected!"); return; } // update the currently selected model currentModel = GetModelHit(); // raycast world MultiARInterop.TrackableHit hit; if (currentModel && arManager.RaycastToWorld(true, out hit)) { // anchor the model if needed if (currentModel.parent == null) { arManager.AnchorGameObjectToWorld(currentModel.gameObject, hit); } // set the new position of the model SetModelWorldPos(hit.point, !verticalModel ? hit.rotation : Quaternion.identity); } } } // update the info if (infoText) { infoText.text = currentModel ? "Selected: " + currentModel.gameObject.name : "No model selected"; } // turn off the toggles, if the respective models are not active UpdateToggleStatus(toggle1, model1); UpdateToggleStatus(toggle2, model2); UpdateToggleStatus(toggle3, model3); }
void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs obj) { if (obj.pressType == InteractionSourcePressType.Select) { inputAction = MultiARInterop.InputAction.Click; inputTimestamp = lastFrameTimestamp; } else if (obj.pressType == InteractionSourcePressType.Thumbstick) { inputAction = MultiARInterop.InputAction.Grip; inputNavCoordinates = Vector3.zero; inputTimestamp = lastFrameTimestamp; } }
void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs evt) { if (evt.state.source.kind == InteractionSourceKind.Hand || (evt.state.source.kind == InteractionSourceKind.Controller && evt.state.source.handedness == controllerHandedness)) { handDetected = false; isHandGripping = false; if ((lastFrameTimestamp - startTimestamp) >= 0.25f) // check for Grip { inputAction = MultiARInterop.InputAction.Release; inputTimestamp = lastFrameTimestamp; Debug.Log("Release (int-source-lost), Pos: " + handPosition + ", Time: " + lastFrameTimestamp); } } }
/// <summary> /// Gets the input action. /// </summary> /// <returns>The input action.</returns> public MultiARInterop.InputAction GetInputAction() { if (arInterface != null) { MultiARInterop.InputAction inputAction = arInterface.GetInputAction(); // input action should be consumed only once if (inputAction != MultiARInterop.InputAction.None) { arInterface.ClearInputAction(); if (CheckForCanvasInputAction()) { inputAction = MultiARInterop.InputAction.None; } } return(inputAction); } return(MultiARInterop.InputAction.None); }
// check for mouse input action (as fallback input) private void CheckForInputAction() { bool bInputAction = true; if (Input.GetMouseButtonDown(0)) { inputAction = MultiARInterop.InputAction.Click; startMousePos = Input.mousePosition; startTimestamp = lastFrameTimestamp; } else if (Input.GetMouseButton(0)) { if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; //Vector3 screenSize = new Vector3(Screen.width, Screen.height, 0f); float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = Input.mousePosition - startMousePos; inputNavCoordinates = mouseRelPos / screenMinDim; // new Vector3(mouseRelPos.x / screenSize.x, mouseRelPos.y / screenSize.y, 0f); } } else if (Input.GetMouseButtonUp(0)) { inputAction = MultiARInterop.InputAction.Release; } else { bInputAction = false; } if (bInputAction) { //inputPos = Input.mousePosition; inputTimestamp = lastFrameTimestamp; } }
/// <summary> /// Clears the input action. /// </summary> public void ClearInputAction() { inputAction = MultiARInterop.InputAction.None; //inputTimestamp = lastFrameTimestamp; }
// check for input action (phone touch) private void CheckForInputAction() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); bool bInputAction = true; switch (touch.phase) { case TouchPhase.Began: inputAction = MultiARInterop.InputAction.Click; inputNavCoordinates = Vector3.zero; startInputPos = touch.position; startTimestamp = lastFrameTimestamp; break; case TouchPhase.Moved: case TouchPhase.Stationary: if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = touch.position - startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; } break; case TouchPhase.Ended: inputAction = MultiARInterop.InputAction.Release; break; default: bInputAction = false; break; } if (bInputAction) { inputPos = touch.position; inputTimestamp = lastFrameTimestamp; } } else { #if UNITY_EDITOR bool bInputAction = true; if (Input.GetMouseButtonDown(0)) { inputAction = MultiARInterop.InputAction.Click; startInputPos = Input.mousePosition; startTimestamp = lastFrameTimestamp; } else if (Input.GetMouseButton(0)) { if ((lastFrameTimestamp - startTimestamp) >= 0.25) { inputAction = MultiARInterop.InputAction.Grip; //Vector3 screenSize = new Vector3(Screen.width, Screen.height, 0f); float screenMinDim = Screen.width < Screen.height ? Screen.width : Screen.height; Vector3 mouseRelPos = Input.mousePosition - (Vector3)startInputPos; inputNavCoordinates = mouseRelPos / screenMinDim; // new Vector3(mouseRelPos.x / screenSize.x, mouseRelPos.y / screenSize.y, 0f); } } else if (Input.GetMouseButtonUp(0)) { inputAction = MultiARInterop.InputAction.Release; } else { bInputAction = false; } if (bInputAction) { inputPos = Input.mousePosition; inputTimestamp = lastFrameTimestamp; } #endif } }
protected override void Update() { base.Update(); if (netClient == null || !clientConnected) { return; } if (marManager == null || !marManager.IsTracking()) { return; } if (setAnchorAllowed && !worldAnchorObj) { if (statusText) { statusText.text = "Tap the floor to anchor the play area."; } } // if there is no world anchor set yet, check for click if (setAnchorAllowed && worldAnchorObj == null && marManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = marManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click) { MultiARInterop.TrackableHit hit; if (marManager.RaycastToWorld(true, out hit)) { // create the world anchor object worldAnchorObj = new GameObject("SharedWorldAnchor"); worldAnchorObj.transform.position = hit.point; worldAnchorObj.transform.rotation = hit.rotation; // Quaternion.identity marManager.AnchorGameObjectToWorld(worldAnchorObj, hit); gameAnchorGo = GameObject.CreatePrimitive(PrimitiveType.Cube); gameAnchorGo.name = "GameAnchor"; Transform gameAnchorTransform = gameAnchorGo.transform; gameAnchorTransform.SetParent(worldAnchorObj.transform); gameAnchorTransform.localPosition = Vector3.zero; gameAnchorTransform.localRotation = Quaternion.identity; gameAnchorTransform.localScale = new Vector3(0.1f, 0.2f, 0.3f); } } } // check if the world anchor needs to be saved if (setAnchorAllowed && worldAnchorObj != null) { if (setAnchorTillTime < Time.realtimeSinceStartup) { setAnchorTillTime = Time.realtimeSinceStartup + k_MaxWaitTime; setAnchorAllowed = false; LogMessage("Saving world anchor..."); marManager.SaveWorldAnchor(worldAnchorObj, (anchorId, errorMessage) => { worldAnchorId = anchorId; if (string.IsNullOrEmpty(errorMessage)) { LogMessage("World anchor saved: " + anchorId); if (gameAnchorGo != null) { gameAnchorGo.name = "GameAnchor-" + anchorId; Renderer renderer = gameAnchorGo.GetComponent <Renderer>(); if (renderer != null && cloudAnchorMaterial != null) { renderer.material = cloudAnchorMaterial; } } if (!string.IsNullOrEmpty(anchorId)) { SetGameAnchorRequestMsg request = new SetGameAnchorRequestMsg { gameName = this.gameName, anchorId = worldAnchorId, anchorPos = worldAnchorObj.transform.position, anchorRot = worldAnchorObj.transform.rotation, anchorData = marManager.GetSavedAnchorData() }; netClient.Send(NetMsgType.SetGameAnchorRequest, request); if (statusText) { statusText.text = "Tap to shoot."; } } } else { LogErrorMessage("Error saving world anchor: " + errorMessage); // allow new world anchor setting worldAnchorId = string.Empty; Destroy(worldAnchorObj); worldAnchorObj = null; } }); } } // check if the world anchor needs to be restored if (getAnchorAllowed && !string.IsNullOrEmpty(worldAnchorId) && worldAnchorObj == null) { if (getAnchorTillTime < Time.realtimeSinceStartup) { getAnchorTillTime = Time.realtimeSinceStartup + k_MaxWaitTime; getAnchorAllowed = false; LogMessage("Restoring world anchor..."); marManager.SetSavedAnchorData(worldAnchorData); marManager.RestoreWorldAnchor(worldAnchorId, (anchorObj, errorMessage) => { worldAnchorObj = anchorObj; if (string.IsNullOrEmpty(errorMessage)) { LogMessage("World anchor restored: " + worldAnchorId); gameAnchorGo = GameObject.CreatePrimitive(PrimitiveType.Cube); gameAnchorGo.name = "GameAnchor-" + worldAnchorId; Transform gameAnchorTransform = gameAnchorGo.transform; gameAnchorTransform.SetParent(worldAnchorObj.transform); gameAnchorTransform.localPosition = Vector3.zero; gameAnchorTransform.localRotation = Quaternion.identity; gameAnchorTransform.localScale = new Vector3(0.1f, 0.2f, 0.3f); Renderer renderer = gameAnchorGo.GetComponent <Renderer>(); if (renderer != null && cloudAnchorMaterial != null) { renderer.material = cloudAnchorMaterial; } if (statusText) { statusText.text = "Tap to shoot."; } } else { LogErrorMessage("Error restoring world anchor: " + errorMessage); // send Get-game-anchor GetGameAnchorRequestMsg request = new GetGameAnchorRequestMsg { gameName = this.gameName }; netClient.Send(NetMsgType.GetGameAnchorRequest, request); } }); } } }
void Update() { // report location position if (locationEnabled && Input.location.status == LocationServiceStatus.Running) { lastLoc = Input.location.lastData; compHeading = Input.compass.enabled ? Input.compass.trueHeading : 0f; if (locationInfoText) { string sMessage = "LocStatus: " + Input.location.status.ToString() + ", Enabled: " + Input.location.isEnabledByUser; sMessage += "\nLat: " + lastLoc.latitude + ", Lon: " + lastLoc.longitude + ", Alt: " + lastLoc.altitude; sMessage += "\nHeading: " + FormatHeading(compHeading) + ", Start: " + FormatHeading(startHeading); locationInfoText.text = sMessage; } } else { string sMessage = "LocStatus: " + Input.location.status.ToString() + ", Enabled: " + Input.location.isEnabledByUser; locationInfoText.text = sMessage; } // report gyro rotation string sGyroMessage = string.Empty; if (gyroEnabled) { gyroAttitude = gyro.attitude; gyroRotation = gyroParentRot * (gyroAttitude * initialGyroRot); sGyroMessage = "GyroEnabled: " + gyro.enabled + "\nAtt: " + FormatQuat(gyroAttitude) + ", Rot: " + FormatQuat(gyroRotation); } // get the main camera Camera mainCamera = arManager ? arManager.GetMainCamera() : null; // report ar-camera pose and point-cloud size if (mainCamera) { camPosition = mainCamera.transform.position; camRotation = mainCamera.transform.rotation; sGyroMessage += string.Format("\nCamPos: {0}, CamRot: {1}\n", camPosition, FormatQuat(camRotation)); } if (gyroInfoText) { gyroInfoText.text = sGyroMessage; } // set start heading, when one is available //if (!startHeadingSet && mainCamera && gyroEnabled && gyroAttitude != Quaternion.identity) if (!startHeadingSet && mainCamera && locationEnabled && compHeading != 0f) { Debug.Log("Set heading with gyroRot: " + gyroRotation.eulerAngles + ", and gyroAtt: " + gyroAttitude.eulerAngles + ", compHead: " + compHeading); //startHeading = (gyroRotation.eulerAngles.y + 90f); startHeading = compHeading; // if (startHeading >= 360f) // startHeading -= 360f; startHeadingSet = true; } // check for click if (arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); float navMagnitude = action == MultiARInterop.InputAction.Grip ? arManager.GetInputNavCoordinates().magnitude : 0f; if (action == MultiARInterop.InputAction.Grip && navMagnitude >= 0.1f && !routineRunning) { routineRunning = true; StartCoroutine(LoadButtonClicked()); } } }
void Update() { // check for click if (objectPrefab && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click && (Time.time - lastInstanceTime) >= 1.5f) { // dont allow too often instance creation lastInstanceTime = Time.time; // remove current object, if any if (objectInstance) { DestroyObjectInstance(); } // raycast world MultiARInterop.TrackableHit hit; if (arManager.RaycastToWorld(true, out hit)) { // instantiate the object and anchor it to the world position objectInstance = Instantiate(objectPrefab, hit.point, !verticalModel ? hit.rotation : Quaternion.identity); arManager.AnchorGameObjectToWorld(objectInstance, hit); // get object renderer & initial scale objectRenderer = GetObjectRenderer(objectInstance); objectScale = objectInstance.transform.localScale; // look at the camera if (modelLookingAtCamera) { Camera arCamera = arManager.GetMainCamera(); MultiARInterop.TurnObjectToCamera(objectInstance, arCamera, hit.point, hit.normal); } if (infoText) { infoText.text = string.Format("{0} placed at {1}", objectPrefab.name, hit.point); } } } else if (objectInstance && action == MultiARInterop.InputAction.Grip) { // get nav coordinates Vector3 navCoords = arManager.GetInputNavCoordinates(); lastInstanceTime = Time.time; // estimate the scale change and target scale Vector3 scaleChange = navCoords.x >= 0 ? (objectScale * navCoords.x) : ((objectScale / 2f) * navCoords.x); targetScale = objectScale + scaleChange; objectInstance.transform.localScale = Vector3.Lerp(objectInstance.transform.localScale, targetScale, smoothFactor * Time.deltaTime); if (infoText) { float fScaleChange = 1f + (navCoords.x >= 0 ? navCoords.x : (0.5f * navCoords.x)); infoText.text = string.Format("Scale change: {0:F2}", fScaleChange); } // outline object bounds if (objectRenderer && boundsPrefab) { Bounds objectBounds = objectRenderer.bounds; // instantiate bounds-cube, if needed if (boundsInstance == null) { boundsInstance = GameObject.Instantiate(boundsPrefab); boundsInstance.transform.SetParent(objectInstance.transform); } // set the bounds-cube tras=nsform boundsInstance.transform.position = objectBounds.center; boundsInstance.transform.rotation = objectInstance.transform.rotation; Vector3 objScale = objectInstance.transform.localScale; Vector3 boundsScale = new Vector3(objectBounds.size.x / objScale.x, objectBounds.size.y / objScale.y, objectBounds.size.z / objScale.z); boundsInstance.transform.localScale = boundsScale; } } else if (action == MultiARInterop.InputAction.Release) { // instantiate bounds-cube, if needed if (boundsInstance != null) { Destroy(boundsInstance); boundsInstance = null; } if (infoText) { infoText.text = "Tap to place the object, then drag right or left, to scale it up or down."; } } } }
void GestureRecognizer_NavigationCompleted(NavigationCompletedEventArgs obj) { inputAction = MultiARInterop.InputAction.Release; inputTimestamp = lastFrameTimestamp; //Debug.Log("GestureRecognizer_NavigationCompleted: " + obj.normalizedOffset); }
void GestureRecognizer_NavigationCanceled(NavigationCanceledEventArgs obj) { inputAction = MultiARInterop.InputAction.Release; inputTimestamp = lastFrameTimestamp; //Debug.Log("GestureRecognizer_NavigationCanceled"); }
// Update is called once per frame void Update() { // check for tap if (portalPrefab && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true)) { MultiARInterop.InputAction action = arManager.GetInputAction(); if (action == MultiARInterop.InputAction.Click) { // raycast to world MultiARInterop.TrackableHit hit; if (arManager.RaycastToWorld(true, out hit)) { // create the portal object, if needed if (!portalObj) { portalObj = Instantiate(portalPrefab); } // set its position and rotation portalObj.transform.position = hit.point; portalObj.transform.rotation = !verticalPortal ? hit.rotation : Quaternion.identity; // look at the camera if (portalLookingAtCamera) { Camera arCamera = arManager.GetMainCamera(); MultiARInterop.TurnObjectToCamera(portalObj, arCamera, hit.point, hit.normal); } // remove object anchor, if it was anchored before string anchorId = arManager.GetObjectAnchorId(portalObj); if (anchorId != string.Empty) { arManager.RemoveGameObjectAnchor(anchorId, true); } // anchor it to the new world position arManager.AnchorGameObjectToWorld(portalObj, hit); // apply the vertical offset if (verticalOffset != 0f) { Vector3 objPos = portalObj.transform.position; //objPos.y += verticalOffset; objPos += portalObj.transform.up * verticalOffset; portalObj.transform.position = objPos; } // play portal-open animation if (playAnimation != string.Empty) { // get reference to the portal animator if (!animator) { animator = portalObj.GetComponent <Animator>(); } if (animator) { animator.Play(playAnimation, 0, 0f); } } // create camera rigidbody (no gravity) & box-collider, if needed if (cameraBoxCollider != Vector3.zero) { Camera arCamera = arManager.GetMainCamera(); Rigidbody camRigidbody = arCamera.gameObject.GetComponent <Rigidbody>(); if (camRigidbody == null) { camRigidbody = arCamera.gameObject.AddComponent <Rigidbody>(); camRigidbody.useGravity = false; } BoxCollider camBoxCollider = arCamera.gameObject.GetComponent <BoxCollider>(); if (camBoxCollider == null) { camBoxCollider = arCamera.gameObject.AddComponent <BoxCollider>(); camBoxCollider.size = cameraBoxCollider; camBoxCollider.isTrigger = true; } } } } } }