private void Release(Ray ray) { RaycastHit hit; if (lastStatus == Status.HOLDING) { targetInteractable?.onUntarget(this, currentMovable); } if (currentStatus == Status.WAITING) { selectedInteractable?.onTap(this); } selectedInteractable?.onRelease(this); if (currentMovable) { Socket target = (Socket)selectedInteractable; if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Sockets"))) { target = hit.transform.GetComponent <Socket>(); } ReleaseMovable(target); } selectedInteractable = null; ChangeStatus(Status.NO_TOUCH); }
private void UnsetObject(ARInteractable oldInteractable, ARInteractable newInteractable) { print(newInteractable); print(oldInteractable); if (newInteractable != null && newInteractable != oldInteractable) { this.currentObject = null; } }
public void onRelease(ARInteractable dropInteractable) { material.DOFade(1f, "_BaseColor", .2f); // transform.parent = originalParent; // transform.localRotation = originalRotation; // transform.localPosition = originalPosition; rb.isKinematic = true; if (trackableBehaviour?.CurrentStatus == TrackableBehaviour.Status.NO_POSE) { DisableObject(); } //releaseAction(dropInteractable); }
/// <summary> /// The Unity Update method. /// </summary> public void Update() { _UpdateApplicationLifecycle(); // Check that motion tracking is tracking. if (Session.Status != SessionStatus.Tracking) { return; } // Get updated augmented images for this frame. Session.GetTrackables <AugmentedImage> (m_TempAugmentedImages, TrackableQueryFilter.Updated); // create objects on each augmented image foreach (var image in m_TempAugmentedImages) { ARInteractable visualizer = null; m_Visualizers.TryGetValue(image.DatabaseIndex, out visualizer); if (image.TrackingState == TrackingState.Tracking && visualizer == null) { // Create an anchor to ensure that ARCore keeps tracking this augmented image. Anchor anchor = image.CreateAnchor(image.CenterPose); Prefabs.TryGetValue(image.Name, out currentObj); visualizer = (ARInteractable)Instantiate(currentObj, anchor.transform); var targetPosition = Camera.main.transform.position; targetPosition.y = visualizer.transform.position.y; visualizer.transform.LookAt(targetPosition); visualizer.Image = image; m_Visualizers.Add(image.DatabaseIndex, visualizer); } else if (image.TrackingState == TrackingState.Stopped && visualizer != null) { m_Visualizers.Remove(image.DatabaseIndex); GameObject.Destroy(visualizer.gameObject); } } // Show the fit-to-scan overlay if there are no images that are Tracking. foreach (var visualizer in m_Visualizers.Values) { if (visualizer.Image.TrackingState == TrackingState.Tracking) { FitToScanOverlay.SetActive(false); return; } } FitToScanOverlay.SetActive(true); }
private void InputStateMachine(Ray ray) { RaycastHit hit; if (currentStatus == Status.NO_TOUCH) { timer = 0.0f; if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Sockets"))) { selectedInteractable = hit.transform.GetComponent <ARInteractable>(); if (selectedInteractable is Socket) { lastSocket = (Socket)selectedInteractable; } } ChangeStatus(Status.WAITING); } if (currentStatus == Status.HOLDING) { if (lastStatus == Status.WAITING) { selectedInteractable?.onHold(this); ChangeStatus(Status.HOLDING); } Debug.DrawRay(ray.origin, ray.direction, Color.green); if (currentMovable) { if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Sockets"))) { targetInteractable = hit.transform.GetComponent <ARInteractable>(); targetInteractable?.onTarget(this, currentMovable); } else { targetInteractable?.onUntarget(this, currentMovable); } } } if (currentStatus == Status.WAITING) { timer += Time.deltaTime; if (timer >= holdThreshold) { ChangeStatus(Status.HOLDING); } } }