Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Callback and events

Discussion in 'AR' started by riccardokhm, Jun 12, 2020.

  1. riccardokhm

    riccardokhm

    Joined:
    Oct 22, 2019
    Posts:
    5
    hi all! Need some help with this script for a Unity Learn course: the aim is to show on the screen the number of planes and points detected by the camera. I think some definition have changed with the release of the last sdk of ARFoundation, since the project asks for ARPlaneAdded, ARPlaneRemoved and ARPlnaUpdate events callbacks. Any help? Here my scritpt, as for the status of the ar session i can say it work, but for planes and points i'm not able to implement the request.

    using JetBrains.Annotations;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.ARFoundation;
    public class ARLesson : MonoBehaviour
    {
    // Definizione variabili iniziali
    [SerializeField] TMPro.TMP_Text StateText;
    [SerializeField] TMPro.TMP_Text PlaneText;
    [SerializeField] TMPro.TMP_Text PointText;
    [SerializeField] ARPlaneManager PlaneManager;
    [SerializeField] ARPointCloudManager PointManager;

    public int PlaneCount { get; }
    int totalNumber;
    List<Vector3> featurePoints = new List<Vector3>();


    //Linee possibili
    // List<ARPlane> CurrentPlane = new List<ARPlane>();
    void Update()
    {
    ARSession.stateChanged += OnStateChanged;
    PlaneManager.planesChanged += CountPlane;
    PointManager.pointCloudsChanged += PointManager_pointCloudsChanged;
    featurePoints = new List<Vector3>(PointManager.trackables.count);
    totalNumber = featurePoints.Count;
    }
    private void PointManager_pointCloudsChanged(ARPointCloudChangedEventArgs obj)
    {
    /*foreach(ARPointCloud point in PointManager.trackables)
    {

    }*/
    PointText.SetText("Points detected" + totalNumber);
    }
    void OnStateChanged(ARSessionStateChangedEventArgs e)
    {
    StateText.SetText("state changed to : " + e.state);
    }
    void CountPlane( ARPlanesChangedEventArgs c)
    {
    // foreach(ARPlane plane in PlaneManager.trackables )

    PlaneText.SetText("Plane and points detected" + PlaneCount );

    }
    }
     
  2. AlexWilson19

    AlexWilson19

    Joined:
    Jun 15, 2020
    Posts:
    2
    Hello, I faced the exact same problem and I am also interested in finding a way to solve it.
     
  3. riccardokhm

    riccardokhm

    Joined:
    Oct 22, 2019
    Posts:
    5
    This script works perfectly, the only problem is related to Points Clouds, since it gives me constantly that it is tracked just 1 PointCloud system, instead i am looking for the exact number of particles in the point cloud system. But for the planes and state it works!
     
unityunity