В Unity Arkit, как показать текст в сцене UnityARHitTestExample, пока не будет найдена вертикальная плоскость? - PullRequest
0 голосов
/ 12 сентября 2018

Я пытаюсь показать текст «Сканирование поверхности» до тех пор, пока он не отсканирует плоскую поверхность. Как только устройство подхватит плоскую поверхность, сообщение должно исчезнуть. Где мне написать код для этой цели. Я нашел два экземпляра где сборная плоскость инициализирована, одна в UnityARGeneratePlane.cs и UnityARUtility.cs. Я добавил Gameobject как текст в UnityARGeneratePlane.cs и использовал setactive для true и false, чтобы показать и скрыть текст. Он отображается, когда я использовал его в начале Метод. Как скрыть текст, где я борюсь. Где использовать код, чтобы скрыть текст при обнаружении плоскости? Это в UnityARGeneratePlane.cs или UnityARUtility.cs.

public class UnityARGeneratePlane : MonoBehaviour
{
    public GameObject planePrefab;
    public GameObject scantxt;
    private UnityARAnchorManager unityARAnchorManager;

    // Use this for initialization
    void Start () {
        unityARAnchorManager = new UnityARAnchorManager();
        UnityARUtility.InitializePlanePrefab (planePrefab);
       scantxt.SetActive(true); //Tried to show the text working when app opens
    }

    void OnDestroy()
    {
        unityARAnchorManager.Destroy ();
        scantxt.SetActive(false); //Here is where I tried to hide the text until a Vertical or Horizontal plane is detected
    }

    void OnGUI()
    {
        IEnumerable<ARPlaneAnchorGameObject> arpags = unityARAnchorManager.GetCurrentPlaneAnchors ();
        foreach(var planeAnchor in arpags)
        {
            //ARPlaneAnchor ap = planeAnchor;
            //GUI.Box (new Rect (100, 100, 800, 60), string.Format ("Center: x:{0}, y:{1}, z:{2}", ap.center.x, ap.center.y, ap.center.z));
            //GUI.Box(new Rect(100, 200, 800, 60), string.Format ("Extent: x:{0}, y:{1}, z:{2}", ap.extent.x, ap.extent.y, ap.extent.z));
        }
    }
}

Код ниже - UnityARUtility.cs

public class UnityARUtility
{
    private MeshCollider meshCollider; //declared to avoid code stripping of class
    private MeshFilter meshFilter; //declared to avoid code stripping of class
    public static GameObject planePrefab = null;
   // public  Text text1;


    public static void InitializePlanePrefab(GameObject go)
    {
        planePrefab = go;
    }





    public static GameObject CreatePlaneInScene(ARPlaneAnchor arPlaneAnchor)
    {
        GameObject plane;
        if (planePrefab != null)
        {
            plane = GameObject.Instantiate(planePrefab); //I dont understand why again Plane prefab is initialized.Other than Generate planes.
        //  text1.text = "Select Any Painting from panel";

        } 
        else {
            plane = new GameObject (); //put in a blank gameObject to get at least a transform to manipulate
        }

        //plane.name = arPlaneAnchor.identifier;

        ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> ();
        if (apmr != null) {
            apmr.InitiliazeMesh (arPlaneAnchor);
        }

        return UpdatePlaneWithAnchorTransform(plane, arPlaneAnchor);

    }

    public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor)
    {

        //do coordinate conversion from ARKit to Unity
        plane.transform.position = UnityARMatrixOps.GetPosition (arPlaneAnchor.transform);
        plane.transform.rotation = UnityARMatrixOps.GetRotation (arPlaneAnchor.transform);

        ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> ();
        if (apmr != null) {
            apmr.UpdateMesh (arPlaneAnchor);
        }


        MeshFilter mf = plane.GetComponentInChildren<MeshFilter> ();

        if (mf != null) {
            if (apmr == null) {
                //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f
                mf.gameObject.transform.localScale = new Vector3 (arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f);

                //convert our center position to unity coords
                mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x,arPlaneAnchor.center.y, -arPlaneAnchor.center.z);
            }

        }

        return plane;
    }



}

}

...