Exemplo n.º 1
0
 void OnPlaneAdded(ARPlanesChangedEventArgs eventArgs)
 {
     foreach (var plane in eventArgs.added)
     {
         DisableIfVertical(plane);
     }
 }
Exemplo n.º 2
0
 private void OnPlaneChanged(ARPlanesChangedEventArgs obj)
 {
     foreach (var plane in obj.added)
     {
         plane.gameObject.SetActive(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Keeps track of all planes available.
        /// </summary>
        /// <param name="args"></param>
        private void OnPlanesUpdated(ARPlanesChangedEventArgs args)
        {
            // remove
            foreach (ARPlane plane in args.removed)
            {
                HorizontalPlanes.Remove(plane);
                Walls.Remove(plane);
            }

            // update
            // do nothing

            // add
            foreach (ARPlane plane in args.added)
            {
                if (plane.alignment == PlaneAlignment.Vertical)
                {
                    Walls.Add(plane);
                }
                else
                {
                    HorizontalPlanes.Add(plane);
                }
            }

            // recalculate core parameters
            Recalculate();
        }
    private void OnPlanesChanged(ARPlanesChangedEventArgs args)
    {
        if (args.added != null && args.added.Count > 0)
        {
            arPlanes.AddRange(args.added);
        }
        foreach (ARPlane plane in arPlanes.Where(plane => plane.extents.x * plane.extents.y >= 0.1f))
        {
            if (plane.alignment.IsVertical())
            {
                //vertical plane found
                OnVerticalPlaneFound.Invoke();
            }
            else
            {
                //horizontal plane found
                OnHorizontalPlaneFound.Invoke();
            }

            if (plane.extents.x * plane.extents.y >= dimensionsForBigPlane.x * dimensionsForBigPlane.y)
            {
                //BigPlane found
                OnBigPlaneFound.Invoke();
            }
        }
    }
    private void PlaneChanged(ARPlanesChangedEventArgs args)
    {
        if (args.added != null && placedObject_flask == null)
        {
            ARPlane arPlane        = args.added[0];
            var     rotation_flask = Quaternion.LookRotation(arPlane.transform.position);
            rotation_flask    *= Quaternion.Euler(0, 260, 10);
            placedObject_flask = Instantiate(placedPrefab_flask, arPlane.transform.position, rotation_flask);
            placedObject_flask.transform.localScale -= new Vector3(0.5F, 0.5F, 0.5F);

            //var text_rescued = Instantiate(TextPrefab);
            //var position = arPlane.transform.position;
            //text_rescued.gameObject.transform.position = new Vector3(position.x, position.y + 0.1f, position.z);


            ////Instantiates the Object
            //GameObject rescuedTextBox = (GameObject)Instantiate(rescuedText, arPlane.transform.position, rotation_rescued);

            ////Grabs the TextMesh component from the game object
            //TextMesh theText = rescuedTextBox.transform.GetComponent<TextMesh>();

            ////Sets the text.
            //theText.text = "The Text";

            //var rotation_rescuer = Quaternion.LookRotation(arPlane.transform.position);
            //rotation_rescuer *= Quaternion.Euler(90, -90, 90);
            var rotation_bottle = Quaternion.LookRotation(placedObject_flask.transform.position);
            rotation_bottle *= Quaternion.Euler(0, 180, 0);
            //placedObject_bottle = Instantiate(placedPrefab_bottle, new Vector3((arPlane.transform.position.x)-0.2F,(arPlane.transform.position.y) + 0.42F, (arPlane.transform.position.z) + 0.45F), rotation_rescuer);
            placedObject_bottle = Instantiate(placedPrefab_bottle, new Vector3((placedObject_flask.transform.position.x) - 0.25F, (placedObject_rescued.transform.position.y) - 0.07F, (placedObject_rescued.transform.position.z) + 0.1F), rotation_rescuer);
            placedObject_bottle.transform.localScale -= new Vector3(0.5F, 0.5F, 0.5F);
        }
    }
 void PlanesChanged(ARPlanesChangedEventArgs args)
 {
     if (!Initialized)
     {
         Activate();
     }
 }
Exemplo n.º 7
0
 private void PlaneManagerOnPlanesChanged(ARPlanesChangedEventArgs eventArgs)
 {
     if (UpdatePlaneStatus(eventArgs.added) || UpdatePlaneStatus(eventArgs.updated))
     {
         OnPlaneFound();
     }
 }
Exemplo n.º 8
0
    private void PlaneChanged(ARPlanesChangedEventArgs args)
    {
        if (args.added != null && placedObject1 == null)
        {
            ARPlane arPlane        = args.added[0];
            Vector3 cameraPosition = arCamera.transform.position;
            Vector3 planePosition  = arPlane.transform.position;

            //place on plane pos
            placedObject1 = Instantiate(objectArray[Random.Range(0, objectArray.Length)], planePosition, Quaternion.Euler(0, Random.Range(0, 360), 0));

            // 2 ~ 3 meters away, random x (-2~2)
            Vector3 objectPosition1 = new Vector3(planePosition.x + Random.Range(-2f, 2f), planePosition.y, cameraPosition.z + Random.Range(2f, 3f));
            placedObject2 = Instantiate(objectArray[Random.Range(0, objectArray.Length)], objectPosition1, Quaternion.Euler(0, Random.Range(0, 360), 0));

            // 4 ~ 5 meters
            //Vector3 objectPosition2 = new Vector3(planePosition.x + Random.Range(-2f, 2f), planePosition.y, cameraPosition.z + Random.Range(4f, 5f));
            //placedObject3 = Instantiate(objectArray[Random.Range(0, objectArray.Length)], objectPosition2, Quaternion.Euler(0, Random.Range(0, 360), 0));

            // 6 ~ 7 meters
            //Vector3 objectPosition3 = new Vector3(planePosition.x + Random.Range(-2f, 2f), planePosition.y, cameraPosition.z + Random.Range(6f, 7f));
            //placedObject4 = Instantiate(objectArray[Random.Range(0, objectArray.Length)], objectPosition3, Quaternion.Euler(0, Random.Range(0, 360), 0));

            // 8 ~ 9 meter
            //Vector3 objectPosition4 = new Vector3(planePosition.x + Random.Range(-2f, 2f), planePosition.y, cameraPosition.z + Random.Range(8f, 9f));
            //placedObject5 = Instantiate(objectArray[Random.Range(0, objectArray.Length)], objectPosition4, Quaternion.Euler(0, Random.Range(0, 360), 0));
        }
    }
Exemplo n.º 9
0
    private void PlaneChanged(ARPlanesChangedEventArgs args)
    {
        if (args.updated != null && isPlacedObj == false)
        //if (args.added != null && placedObject==null)
        {
            foreach (var plane in args.updated)
            {
                ARPlane arPlane = plane;

                txtIsPlaced.text = arPlane.size.ToString();
                string str = String.Format("***************** arPlane.size.x : {0}, arPlane.size.y : {1}", arPlane.size.x, arPlane.size.y);
                Debug.Log(str);


                for (int i = 0; i < 5; i++)
                {
                    Vector3 pos = arPlane.center;
                    pos.x += UnityEngine.Random.Range(-1.5f, 1.5f);
                    //pos.y += UnityEngine.Random.Range(-0.03f, 0.03f);
                    pos.y           = arPlane.transform.position.y;
                    pos.z          += UnityEngine.Random.Range(-1.5f, 1.5f);
                    placedObject[i] = Instantiate(placedPrefab, pos, Quaternion.identity);
                }
                Debug.Log("***************** 오브젝트 생성됨");
                isPlacedObj = true;
                //StartCoroutine(coTimedelay(arPlane));
                break;
            }
        }
    }
Exemplo n.º 10
0
 // Callback for planeChanged event. Once Sally's places, inactivated all the added planes as the added
 private void inActivateAddedPlanes(ARPlanesChangedEventArgs eventArgs)
 {
     if (mainPlane != null && eventArgs.added != null && eventArgs.added.Count > 0)
     {
         inActivatePlanes(eventArgs.added);
     }
 }
Exemplo n.º 11
0
    // Added planes accumulate as the app runs
    // https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.XR.ARFoundation.ARPlaneManager.html?q=planes

    void PlaneManager_PlanesChanged(ARPlanesChangedEventArgs obj)
    {
        //Debug.Log("planes changed");
        planeAdded   += obj.added.Count;
        planeRemoved += obj.removed.Count;
        //numberOfPlanesText.text = "planes added: " + planeAdded + "\nplanes removed: " + planeRemoved;
    }
Exemplo n.º 12
0
        void OnPlaneChanged(ARPlanesChangedEventArgs args)
        {
            var added   = args.added.Select(plane => ToBoundedPlane(plane)).ToArray();
            var updated = args.updated.Select(plane => ToBoundedPlane(plane)).ToArray();
            var removed = args.removed.Select(plane => (TrackableId)plane.trackableId).ToArray();

            var meshes = new Dictionary <TrackableId, byte[]>();

            foreach (var plane in args.added)
            {
                meshes[plane.trackableId] = plane.boundary.ToRawBytes();
            }
            foreach (var plane in args.updated)
            {
                meshes[plane.trackableId] = plane.boundary.ToRawBytes();
            }

            planeInfo = new ARKitRemotePacket.PlaneInfo()
            {
                added   = added,
                updated = updated,
                removed = removed,
                meshes  = meshes,
            };
        }
 private void PlaneChanged(ARPlanesChangedEventArgs args)
 {
     // if(args.added != null && placedObject == null)
     // {
     // placedObject = Instantiate(placedPrefab, cam.transform.position + cam.transform.forward, Quaternion.Euler(0, cam.transform.eulerAngles.y, 0));
     // }
 }
    private void OnChangePlanes(ARPlanesChangedEventArgs args)
    {
        if (_found)
        {
            return;
        }

        for (int i = 0; i < args.added.Count; i++)
        {
            if (IsPlaneSuitable(args.added[i]))
            {
                OnSuitablePlaneFound(args.added[i]);
                return;
            }
        }

        for (int i = 0; i < args.updated.Count; i++)
        {
            if (IsPlaneSuitable(args.updated[i]))
            {
                OnSuitablePlaneFound(args.updated[i]);
                return;
            }
        }
    }
    }//FindObj가 호출되면 패널 비활성화 실행하기

/*    public void FindObj()
 *  {
 *      Debug.Log("111111111");
 *      IntroPanel.SetActive(false);
 *  }*/
    private void PlaneChanged(ARPlanesChangedEventArgs args) // 객체가 같은지 비교하는 구조체를 매개변수로 담은 메서드
    {
        /*  args.added != null => 인식된 Plane이 존재하느냐?  / isPlaceObj == false => 5개가 생성된 적이 없을 때 */
        if (args.updated != null && isPlacedObj == false)
        {
            foreach (var plane in args.updated) // 처음 인식된 Plane
            {
                ARPlane arPlane = plane;
                // ARPlane arPlane = args.added[0];        // 처음 인식된 Plane
                string str = String.Format("***************** arPlane.size.x : {0}, arPlane.size.y : {1}", arPlane.size.x, arPlane.size.y);
                Debug.Log(str);

                // 적당한 크기(1.0, 1.0 이하)
                if (arPlane.size.x < 2.0f && arPlane.size.x > 0.0f || arPlane.size.y < 2.0f && arPlane.size.y > 0.0f)
                {
                    // 5개를 생성해라
                    for (int i = 0; i < 5; i++)
                    {
                        Vector3 pos = arPlane.center;                            // 바닥의 중심 위치에 보물 생성하라
                        pos.x          += UnityEngine.Random.Range(-2.0f, 2.0f); /*중심위치에서 좌우 양옆 1m내에*/
                        pos.y           = arPlane.transform.position.y;
                        pos.z          += UnityEngine.Random.Range(-2.0f, 2.0f); /*중심위치에서 전or후 1m내에*/
                        placedObject[i] = Instantiate(placedPrefab, pos, Quaternion.identity);
                    }
                    Debug.Log("***************** 오브젝트 생성됨");
                    isPlacedObj = true;
                    StartCoroutine(coTimedelay(arPlane));
                    break;
                }
            }
        }
    }
Exemplo n.º 16
0
    private void OnPlaneChanged(ARPlanesChangedEventArgs obj)
    {
        if (!onPlaneDetect)
        {
            Debug.Log("OnPlaneChanged --------->>");
            onPlaneDetect = true;
            foreach (var plane in obj.added)
            {
                var hits = new List <ARRaycastHit>();
                Ray ray  = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
                arSessionOrigin.GetComponent <ARRaycastManager>().Raycast(ray, hits, TrackableType.Planes);

                if (hits.Count > 0)
                {
                    Pose pose = hits[0].pose;

                    planeObject = Instantiate(planePrefab, new Vector3(pose.position.x, pose.position.y, pose.position.z), Quaternion.identity);
                    planeYPose  = planeObject.transform.position.y;
                    Debug.Log("planeObject position--------->>" + planeObject.transform.position);
                    SwitchSurfaceDetection();

                    scanPanel.SetActive(false);
                    btnObjectList.SetActive(true);
                    break;
                }
            }
        }
    }
Exemplo n.º 17
0
    // Add and remove planes based on their tracking status
    private void PlaneChanged(ARPlanesChangedEventArgs args)
    {
        // Add planes to tracking and make sure they are destroyed
        // on removal
        for (int i = 0; i < args.added.Count; i++)
        {
            if (!arPlanesTracking.Contains(args.added[i]))
            {
                arPlanesTracking.Add(args.added[i]);
                args.added[i].destroyOnRemoval = true;
            }
        }

        // Don't track planes that aren't reliable, remove active
        for (int j = arPlanesTracking.Count - 1; j >= 0; j--)
        {
            if (arPlanesTracking[j].trackingState.ToString() != "Tracking")
            {
                arPlanesTracking[j].gameObject.SetActive(false);
                arPlanesRemoved.Add(arPlanesTracking[j]);
                arPlanesTracking.Remove(arPlanesTracking[j]);
            }
        }

        // Track planes that switch back to reliable, set active
        for (int j = arPlanesRemoved.Count - 1; j >= 0; j--)
        {
            if (arPlanesRemoved[j].trackingState.ToString() == "Tracking")
            {
                arPlanesRemoved[j].gameObject.SetActive(true);
                arPlanesTracking.Add(arPlanesRemoved[j]);
                arPlanesRemoved.Remove(arPlanesRemoved[j]);
            }
        }
    }
Exemplo n.º 18
0
 void PlanesChanged(ARPlanesChangedEventArgs args)
 {
     if (!Initialized)
     {
         AllowCloudAnchorDelay = true;
     }
 }
 private void PlaneUpdate(ARPlanesChangedEventArgs args)
 {
     if (args.added != null && placedPrefab == null)
     {
         ARPlane arPlane = args.added[0];
         placedPrefab = Instantiate(spawnedObject, arPlane.transform.position, Quaternion.identity);
     }
 }
Exemplo n.º 20
0
 private void PlaneChanged(ARPlanesChangedEventArgs args)
 {
     if (args.added != null && returnedText != null)
     {
         ARPlane arPlane = args.added[0];
         Instantiate(placedObject, arPlane.transform.position, Quaternion.identity);
         TogglePlaneDetection();
     }
 }
Exemplo n.º 21
0
 private void PlaneChanged(ARPlanesChangedEventArgs args)
 {
     //if (args.added != null && placedObject == null)
     if (args.added != null)
     {
         ARPlane arPlane = args.added[0];
         placedObject = Instantiate(placedPrefab, arPlane.transform.position, Quaternion.identity);
     }
 }
Exemplo n.º 22
0
 private void PlaneChange(ARPlanesChangedEventArgs args)
 {
     if (args.added != null && obj == null)
     {
         ARPlane arPlane = args.added[0];
         obj = Instantiate(SpawnObject, new Vector3(arPlane.transform.position.x + 1, arPlane.transform.position.y), Quaternion.identity);
         obj = Instantiate(SpawnObject, arPlane.transform.position, Quaternion.identity);
     }
 }
Exemplo n.º 23
0
 public void PlaneChanged(ARPlanesChangedEventArgs args)
 {
     if (file != null && recordPlanes)
     {
         planesUpdated.AddRange(args.added);
         planesUpdated.AddRange(args.updated);
         planesRemoved.AddRange(args.removed);
     }
 }
Exemplo n.º 24
0
 private void OnPlanesChanged(ARPlanesChangedEventArgs planesChanged)
 {
     if (!_FirstPlaneFound && planesChanged.added.Count > 0)
     {
         _FirstPlaneFound = true;
         _MoveWithScreen  = true;
         _previewObject   = Instantiate(_previewPrefab);
         planeFound?.Invoke();
     }
 }
Exemplo n.º 25
0
 void OnPlaneChanged(ARPlanesChangedEventArgs args)
 {
     if (args.updated != null && args.updated.Count > 0)
     {
         foreach (ARPlane plane in args.updated.Where(plane => plane.extents.x * plane.extents.y >= 0.5f))
         {
             plane.gameObject.SetActive(true);
         }
     }
 }
Exemplo n.º 26
0
 void planesChangedHandler(ARPlanesChangedEventArgs data)
 {
     foreach (ARPlane added in data.added)
     {
         arPlaneList.Add(added);
     }
     foreach (ARPlane removed in data.removed)
     {
         arPlaneList.Remove(removed);
     }
 }
Exemplo n.º 27
0
    private void HandleARPlanesChangedEvent(ARPlanesChangedEventArgs obj)
    {
        // arPlanesCounter += obj.addeid.Count;
        // arPlanesCounter -= obj.remoived.Count;
        arPlanes.UnionWith(obj.added);
        arPlanes.UnionWith(obj.updated);
        arPlanes.ExceptWith(obj.removed);

        arPlanesCounter = arPlanes.Count;
        UpdatePlaneCounterText();
    }
Exemplo n.º 28
0
    /// <summary>平面识别发送改变</summary>
    public override void OnPlanesChanged(ARPlanesChangedEventArgs obj)
    {
        base.OnPlanesChanged(obj);
        if (m_IsPlaneChanged)
        {
            return;
        }
        m_IsPlaneChanged = true;

        ARRulerSceneManager.Instance.uIManager.ButtonsPanelSetActive(true);
        ARRulerSceneManager.Instance.uIManager.FindPanelPanelSetActive(false);
    }
Exemplo n.º 29
0
        private void ToggleChangedPlanes(ARPlanesChangedEventArgs args)
        {
            foreach (ARPlane plane in args.added)
            {
                plane.gameObject.SetActive(enabled);
            }

            foreach (ARPlane plane in args.updated.Where(plane => plane.gameObject.activeSelf != enabled))
            {
                plane.gameObject.SetActive(enabled);
            }
        }
Exemplo n.º 30
0
 private void PlaneChanged(ARPlanesChangedEventArgs args) // 객체가 같은지 비교하는 구조체를 매개변수로 담은 메서드
 {
     /*  args.added != null => 인식된 Plane이 존재하느냐?  / isPlaceObj == false => 5개가 생성된 적이 없을 때 */
     if (args.updated != null && !isPlacedObj)
     {
         foreach (var plane in args.updated) // 처음 인식된 Plane
         {
             ARPlane arPlane = plane;
             StartCoroutine(coTimedelay(arPlane));
         }
     }
 }