public void Display() { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.BeginHorizontal(); // Grid toggle. showGrid = EditorGUILayout.Toggle("Grid", showGrid); // Width and height labels and text fields. GUILayout.Label("Width: "); width = GUILayout.TextField(width, GUILayout.MaxWidth(30)); GUILayout.Label("Height: "); height = GUILayout.TextField(height, GUILayout.MaxWidth(30)); GUILayout.EndHorizontal(); if (showGrid) { try { GridVisualiser.BuildGrid(Convert.ToInt32(width), Convert.ToInt32(height)); } catch (FormatException exception) { Debug.Log( "Grid width/height format exception." + "Please make sure you write an integer."); } } else { GridVisualiser.DestroyGrid(); } }
// Update is called once per frame void Update() { if (IsCreate == true) { if (Session.Status != SessionStatus.Tracking) { return; } Session.GetTrackables <TrackedPlane>(m_NewTrackedPlanes, TrackableQueryFilter.New); for (int i = 0; i < m_NewTrackedPlanes.Count; i++) { grid = Instantiate(GridPrefab, Vector3.zero, Quaternion.identity, transform); grid.GetComponent <GridVisualiser>().Initialize(m_NewTrackedPlanes[i]); } Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } TrackableHit hit; if (Frame.Raycast(touch.position.x, touch.position.y, TrackableHitFlags.PlaneWithinPolygon, out hit)) { // scale portal //Portal.transform.localScale = new Vector3(1f, 1f, 1f); Portal.SetActive(true); Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose); Portal.transform.position = hit.Pose.position; Portal.transform.rotation = hit.Pose.rotation; Vector3 cameraPosition = ArCamera.transform.position; cameraPosition.y = hit.Pose.position.y; Portal.transform.LookAt(cameraPosition, Portal.transform.up); // Portal.transform.parent = anchor.transform; } IsCreate = false; } if (IsCreate == false) { foreach (GameObject plane in GameObject.FindGameObjectsWithTag("Plane")) { Renderer r = plane.GetComponent <Renderer>(); GridVisualiser t = plane.GetComponent <GridVisualiser>(); r.enabled = false; t.enabled = false; } } }
public void VisualizePlanes(bool showPlanes) { foreach (GameObject plane in GameObject.FindGameObjectsWithTag("Plane")) { Renderer r = plane.GetComponent <Renderer>(); GridVisualiser t = plane.GetComponent <GridVisualiser>(); r.enabled = showPlanes; t.enabled = showPlanes; } }