示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mgr"></param>
        /// <returns></returns>
        /// <remarks>
        /// The ARReferencePoint (or later version ARAnchor) returned by mgr.AddReferencePoint() (later mgr.AddAnchor())
        /// is a Unity component, attached (obviously) to a GameObject.
        /// So, an alternate (read better) way might be:
        ///  AnchorManagerARF creates an ARReferencePoint(ARAnchor).
        ///  It then adds a SpongyAnchorARF (while creating it with AddComponent) to the referencePoint's gameObject.
        ///  SpongyAnchorARF then gets ref to referencePoint in Start (or Awake?) to implement IsLocated
        ///  (and hopefully Save/Load later).
        ///  There is a PROBLEM HERE:
        ///  ARReferencePoints (ARAnchors) can't be destroyed via normal Unity destruction path. They must
        ///  be explicitly destroyed via the ARReferencePointManager.RemoveReferencePoint().
        ///  The good news is that we are in control of the destruction of SpongyAnchors. So rather
        ///  than destroying a SpongyAnchor by destroying its GameObject, as we do now (see AnchorManager.Reset()
        ///  for example, plus other Destroy() calls in AnchorManager), we'll need a virtual specifically for
        ///  destroying SpongyAnchors.
        /// </remarks>

        // Start is called before the first frame update
        private void Start()
        {
#if WLT_ARFOUNDATION_PRESENT
            arReferencePoint = GetComponent <ARReferencePoint>();
#endif // WLT_ARFOUNDATION_PRESENT
            lastNotLocatedTime = Time.unscaledTime;
        }
    void Update()
    {
        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (touch.phase != TouchPhase.Began)
        {
            return;
        }

        if (arRaycastManager.Raycast(touch.position, hits, TrackableType.FeaturePoint))
        {
            Pose             hitPose        = hits[0].pose;
            ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(hitPose);

            if (referencePoint == null)
            {
                debugLog.gameObject.SetActive(true);
                string errorEntry = "There was an error creating a reference point\n";
                Debug.Log(errorEntry);
                debugLog.text += errorEntry;
            }
            else
            {
                referencePoints.Add(referencePoint);
                referencePointCount.text = $"Reference Point Count: {referencePoints.Count}";
            }
        }
    }
示例#3
0
    /// <summary>
    /// Deaktiviert ARPlane, ARPointCloudManager und setzt das Placement Prefab des ARPlacementInteractable auf null
    /// </summary>
    /// <param name="arPlacementInteractable"></param>
    /// <param name="placedObject"></param>
    public void SetReferencePointAsParent(ARPlacementInteractable arPlacementInteractable, GameObject placedObject)
    {
        if (gamePrefab == null)
        {
            gamePrefab = arPlacementInteractable.placementPrefab;
        }

        Vector3    position   = placedObject.transform.position;
        Quaternion quaternion = placedObject.transform.rotation;
        Pose       hitPose    = new Pose(position, quaternion);

        // will be null when unsuccessful
        ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(hitPose);

        placedObject.transform.SetParent(referencePoint.transform);

        arPlaneManager.enabled = false;
        foreach (ARPlane plane in arPlaneManager.trackables)
        {
            plane.gameObject.SetActive(false);
        }
        arPointCloudManager.enabled = false;
        foreach (ARPointCloud pointCloud in arPointCloudManager.trackables)
        {
            pointCloud.gameObject.SetActive(false);
        }

        arPlacementInteractable.placementPrefab = null;
    }
示例#4
0
        private void TouchtoHostCloudReferencePoint()
        {
            OutputText.text = m_AppMode.ToString();

            if (Input.touchCount >= 1 &&
                Input.GetTouch(0).phase == TouchPhase.Began &&
                !EventSystem.current.IsPointerOverGameObject(
                    Input.GetTouch(0).fingerId))
            {
                List <ARRaycastHit> hitResults = new List <ARRaycastHit>();
                RaycastManager.Raycast(Input.GetTouch(0).position, hitResults);
                if (hitResults.Count > 0)
                {
                    pose = hitResults[0].pose;

                    // Create a reference point at the touch.
                    ARReferencePoint referencePoint =
                        ReferencePointManager.AddReferencePoint(
                            pose);

                    // Create Cloud Reference Point.
                    m_CloudReferencePoint =
                        ReferencePointManager.AddCloudReferencePoint(
                            referencePoint);
                    if (m_CloudReferencePoint == null)
                    {
                        OutputText.text = "Create Failed!";
                        return;
                    }

                    // Wait for the reference point to be ready.
                    m_AppMode = AppMode.WaitingForHostedReferencePoint;
                }
            }
        }
示例#5
0
        /// <summary>
        /// Creates a new cloud reference point using an existing local Reference Point.
        /// <example>
        /// The sample code below illustrates how to host a cloud reference point.
        /// <code>
        /// private ARCloudReferencePoint m_CloudReferencePoint;
        ///
        /// void HostCloudReference(Pose pose)
        /// {
        ///     // Create a local Reference Point, you may also use another
        ///     // Reference Point you may already have.
        ///     ARReferencePoint localReferencePoint =
        ///         ReferencePointManager.AddReferencePoint(pose);
        ///
        ///     // Request the cloud reference point.
        ///     m_CloudReferencePoint =
        ///         ReferencePointManager.AddCloudReferencePoint(localReferencePoint);
        /// }
        ///
        /// void Update()
        /// {
        ///     if (m_CloudReferencePoint)
        ///     {
        ///         // Check the cloud reference point state.
        ///         CloudReferenceState cloudReferenceState =
        ///             m_CloudReferencePoint.cloudReferenceState;
        ///         if (cloudReferenceState == CloudReferenceState.Success)
        ///         {
        ///             myOtherGameObject.transform.SetParent
        ///                 m_CloudReferencePoint.transform, false);
        ///             m_CloudReferencePoint = null;
        ///         }
        ///         else if (cloudReferenceState == CloudReferenceState.TaskInProgress)
        ///         {
        ///             // Wait, not ready yet.
        ///         }
        ///         else
        ///         {
        ///             // An error has occurred.
        ///         }
        ///     }
        /// }
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="referencePointManager">The ReferencePointManager instance for extending.
        /// </param>
        /// <param name="referencePoint">The local <c>ARReferencePoint</c> to be used as the
        /// basis to host a new cloud reference point.</param>
        /// <returns>If successful, a <see cref="ARCloudReferencePoint"/>,
        /// otherwise <c>null</c>.</returns>
        public static ARCloudReferencePoint AddCloudReferencePoint(
            this ARReferencePointManager referencePointManager,
            ARReferencePoint referencePoint)
        {
            // Create the underlying ARCore Cloud Anchor.
            IntPtr cloudAnchorHandle = SessionApi.HostCloudAnchor(
                ARCoreExtensions.Instance.CurrentARCoreSessionHandle,
                referencePoint.AnchorHandle());

            if (cloudAnchorHandle == IntPtr.Zero)
            {
                return(null);
            }

            // Create the GameObject that is the cloud reference point.
            ARCloudReferencePoint cloudReferencePoint =
                (new GameObject(k_GameObjectName)).AddComponent <ARCloudReferencePoint>();

            if (cloudReferencePoint)
            {
                cloudReferencePoint.SetAnchorHandle(cloudAnchorHandle);
            }

            // Parent the new cloud reference point to the session origin.
            cloudReferencePoint.transform.SetParent(
                ARCoreExtensions.Instance.SessionOrigin.trackablesParent, false);

            return(cloudReferencePoint);
        }
        void OnRayHit(ARRaycastHit hit)
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            var referencePointManager = m_ARSessionOrigin.GetComponent <ARReferencePointManager>();
            var planeManager          = m_ARSessionOrigin.GetComponent <ARPlaneManager>();

            if (referencePointManager == null || planeManager == null)
            {
                return;
            }

            var plane = planeManager.GetPlane(hit.trackableId);

            if (plane == null)
            {
                return;
            }

            if (m_Attachment != null)
            {
                referencePointManager.RemoveReferencePoint(m_Attachment);
                m_Attachment = null;
            }

            var planeNormal = plane.transform.up;
            var pose        = new Pose(hit.pose.position + planeNormal * m_DistanceFromPlane, hit.pose.rotation);

            m_Attachment = referencePointManager.AttachReferencePoint(plane, pose);
        }
    /*bool TryGetTouchPosition(out Vector2 touchPosition)
     * {
     *  if(Input.touchCount > 0)
     *  {
     *      touchPosition = Input.GetTouch(0).position;
     *      return true;
     *  }
     *
     *  touchPosition = default;
     *
     *  return false;
     * }*/

    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            touchPosition = touch.position;

            if (arRaycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))
            {
                var hitPose = hits[0].pose;


                if (spawnedObject == null)
                {
                    referencePoint0 = arReferencePointManager.AddReferencePoint(hitPose);
                    Quaternion rotation90 = Quaternion.Euler(0, 0, 0);
                    spawnedObject = Instantiate(gameObjectToInstantiate, referencePoint0.transform.position, rotation90, referencePoint0.transform);

                    arPlaneManager.enabled = false;
                    foreach (ARPlane plane in arPlaneManager.trackables)
                    {
                        plane.gameObject.SetActive(false);
                    }
                }
                else
                {
                    referencePoint1 = arReferencePointManager.AddReferencePoint(hitPose);
                    //Quaternion rotation90 = Quaternion.Euler(90,0,0);
                    spawnedObject.transform.parent   = referencePoint1.transform;
                    spawnedObject.transform.position = referencePoint1.transform.position;
                    //spawnedObject.transform.rotation = referencePoint1.transform.rotation;
                }
            }
        }
    }
示例#8
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (touch.phase != TouchPhase.Began)
        {
            return;
        }

        if (arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
        {
            Pose             hitPose        = hits[0].pose;
            ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(hitPose);

            if (referencePoint == null)
            {
                string errorEntry = "There was an error creating a reference point";
                Debug.Log(errorEntry);
            }
            else
            {
                referencePoints.Add(referencePoint);
                referencePointCount.text = $"Reference Point Count: {referencePoints.Count}";
            }
        }
    }
示例#9
0
    private void PlacePlanet()
    {
        if (placementIsPoseValid)
        {
            Pose planetPose = placementIndicatorPose;
            planetPose.position.y += 0.8f;
            ARReferencePoint planetReferencePoint = arReferencePointManager.AddReferencePoint(planetPose);

            if (planetReferencePoint == null)
            {
                string errorEntry = "There was an error creating a reference point\n";
                Debug.Log(errorEntry);
            }
            else
            {
                planetEarth.transform.SetParent(planetReferencePoint.gameObject.transform);
                planetEarth.transform.localPosition = new Vector3(0, 0, 0);
                planetEarth.GetComponent <Planet_Explosion_Fast>().enabled = true;
                planetEarth.GetComponent <MeteorsSpawn>().enabled          = true;
                planetEarth.GetComponent <PlanetController>().enabled      = true;
                referencePoints.Add(planetReferencePoint);
                planetPlaced = true;
                placementIndicator.SetActive(false);
            }
        }
    }
示例#10
0
    private void PlaceObject()
    {
        try {
            ARReferencePoint referencePoint = referencePointManager.AddReferencePoint(placementPose);
            //referencePointManager.referencePointPrefab = objectToSpawn;

            if (referencePoint != null)
            {
                referencePoints.Add(packageCounter, referencePoint);
                GameObject packageObject = Instantiate(objectToSpawn, placementPose.position, Quaternion.Euler(0, 180, 0));
                packageObject.transform.SetParent(referencePoint.transform, true);
                packageHistory.Add(packageCounter, packageObject);

                if (packageCounter < 3)
                {
                    packageCounter++;
                    objectToSpawn = packagePrefabs[packageCounter];
                }
                else
                {
                    uiText.text       = "";
                    objectToSpawn     = null;
                    placementIsActive = false;
                    placementIndicator.SetActive(false);
                    HidePlaneDetection();
                    StartCoroutine(WaitAfterPlacementFinished());
                }
            }
        }
        catch (Exception e)
        {
            DebugText.SetText(1, "9 " + e.Message);
        }
    }
 /// <summary>
 /// Destroying the attached Behaviour will result in the game or Scene
 /// receiving OnDestroy.
 /// </summary>
 private void OnDestroy()
 {
     if (this.WorldAnchor != null)
     {
         SpatialAnchorManager.arReferencePointManager.RemoveReferencePoint(this.WorldAnchor);
         this.WorldAnchor = null;
     }
 }
示例#12
0
 public void Cleanup(ARReferencePointManager arReferencePointManager)
 {
     if ((arReferencePointManager != null) && (arReferencePoint != null))
     {
         arReferencePointManager.RemoveReferencePoint(arReferencePoint);
         arReferencePoint = null;
     }
 }
        public static IntPtr AnchorHandle(this ARReferencePoint referencePoint)
        {
            NativePointerStruct info = (NativePointerStruct)
                                       Marshal.PtrToStructure(
                referencePoint.nativePtr,
                typeof(NativePointerStruct));

            return(info.AnchorHandle);
        }
示例#14
0
    void Update()
    {
        if (Input.touchCount == 0)
        {
            return;
        }
        Touch touch = Input.GetTouch(0);

        if (touch.phase != TouchPhase.Began)
        {
            return;
        }
        if (arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
        {
            Pose hitPose = hits[0].pose;
            Debug.Log("hit pose" + hitPose);
            ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(hitPose);
            if (referencePoint == null)
            {
                debugLog.gameObject.SetActive(true);
                string errorEntry = "Error creating a reference point\n";
                Debug.Log(errorEntry);
                debugLog.text += errorEntry;
            }

            else
            {
                referencePoint.GetComponent <AddText>().positionItem.SetText(referencePoint.transform.position.ToString());
                referencePoint.GetComponent <AddText>().Name_Scene.SetText("Reference point");
                referencePoints.Add(referencePoint);
                if (referencePoints.Count == 1)
                {
                    Scene.referencePoint1 = referencePoint.transform.position;
                }
                if (referencePoints.Count == 2)
                {
                    Scene.referencePoint2 = referencePoint.transform.position;

                    foreach (Item item in Scene.items)
                    {
                        GameObject _item    = Instantiate(prefabSphere, item.position, Quaternion.identity);
                        Color      MyColour = Color.clear;
                        ColorUtility.TryParseHtmlString(item.color, out MyColour);
                        _item.GetComponent <MeshRenderer>().material.color = MyColour;
                        _item.GetComponent <AddText>().Name_Scene.SetText(item.name);
                        _item.GetComponent <AddText>().Color_Item.SetText("Color: " + item.color);
                        _item.GetComponent <AddText>().positionItem.SetText(_item.transform.position.ToString());
                        Get_Param(MyColour, item.name, item.color, _item.transform.position);
                    }

                    arReferencePointManager.referencePointPrefab.SetActive(false);
                }
            }
            //referencePointCount.text = $"Reference Point Count: {referencePoints.Count}";
        }
    }
示例#15
0
    private void RemoveSelectedBall()
    {
        ARReferencePoint point = selectedBall.GetComponent <ARReferencePoint> ();

        referencePoints.Remove(point);
        arReferencePointManager.RemoveReferencePoint(point);
        selectedBall = null;
        removeBallButton.gameObject.SetActive(false);
        referencePointCount.text = $"Reference Point Count: {referencePoints.Count}";
    }
示例#16
0
 public void RemoveFirstReferencePoint()
 {
     if (arReferencePoints.Count > 0)
     {
         ARReferencePoint arrp = arReferencePoints [0];
         if (referencePointManager.TryRemoveReferencePoint(arrp.sessionRelativeData.Id))
         {
             arReferencePoints.Remove(arrp);
         }
     }
 }
示例#17
0
        /// <summary>
        /// Creates an ARReferencePoint from the specified <see cref="Transform"/>.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="rotation">The rotation.</param>
        /// <returns>An ARFoundation <see cref="ARReferencePoint"/>.</returns>
        /// <exception cref="InvalidOperationException">Unable to create an anchor.</exception>
        public static ARReferencePoint CreateReferencePoint(Vector3 position, Quaternion rotation)
        {
            Pose             anchorPose     = new Pose(position, rotation);
            ARReferencePoint referencePoint = SpatialAnchorManager.arReferencePointManager.AddReferencePoint(anchorPose);

            if (referencePoint == null)
            {
                Debug.LogError("Unable to create an anchor.");
                throw new InvalidOperationException("Unable to create an anchor.");
            }

            return(referencePoint);
        }
 public void DeleteAllPoints()
 {
     while (measureblePoints.Count > 0)
     {
         MeasurablePoint point = measureblePoints[0];
         measureblePoints.Remove(point);
         ARReferencePoint referencePoint = point.transform.parent.GetComponent <ARReferencePoint>();
         if (referencePoint != null)
         {
             referencePointManager.RemoveReferencePoint(referencePoint);
         }
     }
 }
示例#19
0
    void UpdateReferencePoint(ARReferencePoint referencePoint)
    {
        var canvas = referencePoint.GetComponentInChildren <Canvas>();

        if (canvas == null)
        {
            return;
        }

        canvas.worldCamera = GetComponent <ARSessionOrigin>().camera;

        var text = canvas.GetComponentInChildren <Text>();

        if (text == null)
        {
            return;
        }

        var sessionId = referencePoint.sessionId;

        if (sessionId.Equals(session.subsystem.sessionId))
        {
            text.text = $"Local";
        }
        else
        {
            text.text = $"Remote";
        }

        var cube = referencePoint.transform.Find("Scale/SessionId Indicator");

        if (cube != null)
        {
            var renderer = cube.GetComponent <Renderer>();
            {
                // Generate a color from the sessionId
                Color color;
                unsafe
                {
                    var bytes = *(byte128 *)&sessionId;
                    color = new Color(
                        bytes.data[0] / 255f,
                        bytes.data[4] / 255f,
                        bytes.data[8] / 255f,
                        bytes.data[12] / 255f);
                }
                renderer.material.color = color;
            }
        }
    }
示例#20
0
 public void PlaceObject()
 {
     if (appStateManager.placementCursorIsSurface)
     {
         //logText.text = placementObjects.Count.ToString();
         ARReferencePoint newAnchor = anchorManager.AddReferencePoint(appStateManager.placementCursorPose);
         PlacementObject  newPlaced = Instantiate(objectToPlace, appStateManager.placementCursorPose.position, appStateManager.placementCursorPose.rotation, newAnchor.transform);
         //newPlaced.SetActiveMedia(false);
         placementObjects.Add(newPlaced);
         anchors.Add(newAnchor);
         DragDropBar.gameObject.SetActive(true);
         createRaycastPanel.SetActive(false);
     }
 }
示例#21
0
    public void UpdateAnchor(Vector3 pos, Quaternion rot, Action callback = null)
    {
        ClearAnchor();

        currentAnchor = mAnchorManager.AddReferencePoint(new Pose(pos, rot));
        if (currentAnchor != null)
        {
            navModel.transform.SetParent(currentAnchor.transform, false);
        }

        SetTransform(navModel, pos, rot);
        ToggleTransform(navModel, true);
        callback?.Invoke();
    }
示例#22
0
    public GameObject CreateReferencePoint(Pose pose, Transform parentObject)
    {
        ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(pose);

        if (referencePoint == null)
        {
            return(null);
        }
        else
        {
            referencePoints.Add(referencePoint);
            referencePoint.gameObject.transform.SetParent(parentObject);
            return(referencePoint.gameObject);
        }
    }
    public void PlacePickedUpPoint()
    {
        ARReferencePoint result = CreateAnchor();
        MeasurablePoint  point  = CameraHandler.Instance.GetComponentInChildren <MeasurablePoint>();

        if ((result == null) || (point == null))
        {
            return;
        }
        else
        {
            point.transform.position = result.transform.position;
            point.transform.parent   = result.transform;
        }
    }
示例#24
0
    public IEnumerator SpawnMeteors()
    {
        while (canSpawnmeteors)
        {
            Pose pose;
            pose.position = RandomPointOnSphere();
            pose.rotation = Quaternion.identity;
            ARReferencePoint meteorReferencePoint = arReferencePointManager.AddReferencePoint(pose);

            GameObject meteor = Instantiate(meteorPrefab, pose.position, Quaternion.identity);
            meteor.transform.SetParent(meteorReferencePoint.gameObject.transform);
            meteor.transform.localPosition = new Vector3(0, 0, 0);
            meteor.transform.LookAt(center);
            yield return(new WaitForSeconds(3f));
        }
    }
示例#25
0
    void ReferencePointTrackPlacement2(Vector3 track)
    {
        if (arRaycastManager.Raycast(track, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
        {
            //var hitPose = hits[0].pose;
            ARReferencePoint referencePoint = aRReferencePointManager.AddReferencePoint(new Pose(track, Quaternion.identity));

            if (referencePoint == null)
            {
                Debug.Log("nothing");
            }
            else
            {
                referencePoints.Add(referencePoint);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (referencePoints.Count >= 2)
        {
            usaPlane.SetActive(true);

            float aX = referencePoints[0].transform.position.x;
            float aZ = referencePoints[0].transform.position.z;

            float bX = referencePoints[1].transform.position.x;
            float bZ = referencePoints[1].transform.position.z;

            usaPlane.transform.localScale = new Vector3((bX - aX) / 10, 1, (bZ - aZ) / 10);
            usaPlane.transform.position   = new Vector3((aX + bX) / 2, (referencePoints[0].gameObject.transform.position.y), (aZ + bZ) / 2);
            adjustAspectRatio(1.305f, usaPlane);
            //referencePoints[0].gameObject.GetComponent<Material>().color = new Color32(0, 255, 0, 255);
            //referencePoints[1].gameObject.transform.rotation.SetEulerAngles(referencePoints[1].gameObject.transform.rotation;
        }

        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (touch.phase != TouchPhase.Began)
        {
            return;
        }

        if (arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon) && !planeSearch)
        {
            Pose             hitPose        = hits[0].pose;
            ARReferencePoint referencePoint = arReferencePointManager.AddReferencePoint(hitPose);

            if (referencePoint == null)
            {
                Debug.Log("There was an error creating a reference point here");
            }
            else if (!planeSearch)
            {
                referencePoints.Add(referencePoint);
            }
        }
    }
示例#27
0
        /// <summary>
        /// Gets an anchor <see cref="Pose"/> from the specified native anchor <see cref="IntPtr"/>.
        /// </summary>
        /// <param name="anchorPointer">The anchor pointer.</param>
        /// <returns><see cref="Pose"/>.</returns>
        /// <exception cref="System.InvalidOperationException">Invalid anchor pointer. Can't get the pose.</exception>
        private static Pose GetPose(IntPtr anchorPointer)
        {
            if (anchorPointer == IntPtr.Zero)
            {
                throw new InvalidOperationException("Invalid anchor pointer. Can't get the pose.");
            }

            ARReferencePoint referencePoint = SpatialAnchorManager.ReferencePointFromPointer(anchorPointer);

            if (referencePoint == null)
            {
                Debug.Log("Didn't find the anchor");
                return(Pose.identity);
            }

            return(new Pose(referencePoint.transform.position, referencePoint.transform.rotation));
        }
    public void PickUpPoint(MeasurablePoint point)
    {
        //Check if point exists
        int index = measureblePoints.FindIndex((MeasurablePoint obj) => Object.ReferenceEquals(obj, point));

        if (index == -1)
        {
            Debug.Log("Tried to remove a non-tracked point");
            return;
        }

        ARReferencePoint referencePoint = point.transform.parent.GetComponent <ARReferencePoint>();

        if (referencePoint != null)
        {
            point.transform.parent = CameraHandler.Instance.transform;
            referencePointManager.RemoveReferencePoint(referencePoint);
        }
    }
示例#29
0
    void ReferencePointPlacement()
    {
        if (!TryGetTouchPosition(out Vector2 touchPosition))
        {
            return;
        }

        if (arRaycastManager.Raycast(touchPosition, hits, UnityEngine.XR.ARSubsystems.TrackableType.PlaneWithinPolygon))
        {
            var hitPose = hits[0].pose;
            ARReferencePoint referencePoint = aRReferencePointManager.AddReferencePoint(hitPose);

            if (referencePoint == null)
            {
                Debug.Log("nothing");
            }
            else
            {
                referencePoints.Add(referencePoint);
            }
        }
    }
示例#30
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            //Vector2 RawPosition = new Vector2 (touch.rawPosition);
            Vector3 position = arCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 1.0f));
            Pose    pose     = new Pose(position, Quaternion.identity);


            if (spawnedObject == null)
            {
                referencePoint0 = arReferencePointManager.AddReferencePoint(pose);
                spawnedObject   = Instantiate(placedPrefab, referencePoint0.transform.position, referencePoint0.transform.rotation, referencePoint0.transform);
            }
            else
            {
                referencePoint1 = arReferencePointManager.AddReferencePoint(pose);
                spawnedObject.transform.position = referencePoint1.transform.position;
                spawnedObject.transform.rotation = referencePoint1.transform.rotation;
                // spawnedObject.transform.parent = referencePoint1.transform;
            }


            /*if (arRaycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
             *      {
             *              var hitPose = hits[0].pose;
             *              var anchorPoint = arAnchorManager.AddAnchor(hitPose);
             *              var spawnObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
             *              spawnObject.transform.parent = anchorPoint.transform;
             *      }
             * }*/
        }
        else
        {
            return;
        }
    }