public void OnClickVideo() { if (videoMenu == null) { videoMenu = Instantiate(buttonVideoPrefab, new Vector3(0, 0, 0), Quaternion.Euler(60, 0, 0)) as StableMenu; } }
public void Start() { m_datetime = DateTime.Now; StartCoroutine(DownloadPlaces(queryURL)); StartCoroutine(DownloadKeywords(queryURL)); this._gestureRecognizer = new UnityEngine.XR.WSA.Input.GestureRecognizer(); this._gestureRecognizer.SetRecognizableGestures( UnityEngine.XR.WSA.Input.GestureSettings.Tap | UnityEngine.XR.WSA.Input.GestureSettings.DoubleTap | UnityEngine.XR.WSA.Input.GestureSettings.Hold | UnityEngine.XR.WSA.Input.GestureSettings.ManipulationTranslate ); /* * this._gestureRecognizer.HoldStartedEvent += (source, ray) => * { * GameObject terrain = GameObject.Find("terrain"); * buttonObject = Instantiate(buttonZoomPrefab, this.gameObject.transform.position + new Vector3(0, 0.2f, 0), Quaternion.Euler(0, -90, 0)) as StableMenu; * buttonObject.transform.parent = terrain.transform; * }; */ // Repond to single and double tap. this._gestureRecognizer.TappedEvent += (source, count, ray) => { switch (count) { case 1: if (this._isMoving) { if (GazeManager.Instance.Hit) { // Cease moving this._isMoving = false; // Stop mapping observer SpatialMappingManager.Instance.StopObserver(); // var terrain = this.transform.Find("terrain"); if (terrain == null) { // Hide footprint this.transform.Find("base").GetComponent <MeshRenderer>().material.color = new Color32(100, 100, 100, 100); // Add Terrain _isFirstTimeLoading = true; } else { // Restore hit test terrain.gameObject.layer = 0; } } } else { // If single tap on stationary terrain then perform reverse geocode. // Exit if nothing found if (!GazeManager.Instance.Hit) { return; } if (GazeManager.Instance.FocusedObject == null) { return; } // Exit if not terrain if (GazeManager.Instance.FocusedObject.GetComponent <Terrain>() == null) { return; } //this.StartCoroutine(this.ChangeMapCoordinates(GazeManager.Instance.Position)); GameObject terrain = GameObject.Find("terrain"); buttonObject = Instantiate(buttonChoosePrefab, GazeManager.Instance.Position + new Vector3(0, 0.2f, 0), Quaternion.Euler(0, -90, 0)) as StableMenu; buttonObject.transform.parent = terrain.transform; //StartCoroutine(DownloadPlaces(queryURL)); //this.StartCoroutine(this.AddStreetAddress(GazeManager.Instance.Position)); } break; case 2: // Resume footprint/terrain movement. if (!this._isMoving) { // Set moving flag for update method this._isMoving = true; // Make terrain hittest invisible this.GetComponentInChildren <Terrain>().gameObject.layer = 2; // Resume mapping observer SpatialMappingManager.Instance.StartObserver(); } break; } }; this._gestureRecognizer.StartCapturingGestures(); // Create terrain footprint. var footprint = GameObject.CreatePrimitive(PrimitiveType.Quad); footprint.name = "base"; footprint.transform.position = new Vector3(0, 0, 0); footprint.transform.localRotation = Quaternion.FromToRotation( new Vector3(0, 1, 0), new Vector3(0, 0, 1) ); footprint.transform.localScale = new Vector3(SIZE, SIZE, 1f); footprint.layer = 2; // Ignore Raycast footprint.transform.parent = this.transform; }
private IEnumerator BuildTerrain(ElevationData elevation, Texture2D[] textures) { GameObject tc = GameObject.Find("terrain"); if (tc != null) { GameObject.Destroy(tc); } yield return(null); // Center position of terrain. var position = this.transform.position; position -= new Vector3(SIZE / 2, 0, SIZE / 2); // Create terrain game object. GameObject terrainObject = new GameObject("terrain"); terrainObject.transform.position = position; terrainObject.transform.parent = this.transform; yield return(null); // Create terrain data. TerrainData terrainData = new TerrainData(); terrainData.heightmapResolution = 33; terrainData.size = new Vector3(SIZE, HEIGHT, SIZE); terrainData.alphamapResolution = 32; terrainData.baseMapResolution = 1024; terrainData.SetDetailResolution(1024, 8); yield return(null); // Tiles per side. var dimension = (int)Math.Sqrt(textures.Length); // Splat maps. var splats = new List <SplatPrototype>(); foreach (var texture in textures) { splats.Add(new SplatPrototype() { tileOffset = new Vector2(0, 0), tileSize = new Vector2( SIZE / dimension, SIZE / dimension ), texture = texture }); yield return(null); } terrainData.splatPrototypes = splats.ToArray(); terrainData.RefreshPrototypes(); yield return(null); // Get tile var tile = this._place.Location.ToTile(this._place.Level); // Construct height map. float[,] data = new float[ terrainData.heightmapWidth, terrainData.heightmapHeight ]; for (int x = 0; x < terrainData.heightmapWidth; x++) { for (int y = 0; y < terrainData.heightmapHeight; y++) { // Scale elevation from 257x257 to 33x33 var x2 = Convert.ToInt32((double)x * 256 / (terrainData.heightmapWidth - 1)); var y2 = Convert.ToInt32((double)y * 256 / (terrainData.heightmapHeight - 1)); // Find index in Esri elevation array var id = y2 * 257 + x2; // Absolute height in map units. var h1 = elevation.Heights[id]; // Height in model units. var h2 = SIZE * (h1 - elevation.Min) / tile.Size; // Apply exaggeration. var h3 = h2 * VERTICAL_EXAGGERATION; // Apply base offset. var h4 = h3 + TERRAIN_BASE_HEIGHT; // Final height. data[terrainData.heightmapHeight - 1 - y, x] = h4; } } terrainData.SetHeights(0, 0, data); yield return(null); // Add alpha mapping //float[,,] maps = terrainData.GetAlphamaps(0, 0, terrainData.alphamapWidth, terrainData.alphamapHeight); var maps = new float[ terrainData.alphamapWidth, terrainData.alphamapHeight, textures.Length ]; for (int y = 0; y < terrainData.alphamapHeight; y++) { for (int x = 0; x < terrainData.alphamapWidth; x++) { // Convert alpha coordinates into tile index. Left to right, bottom to top. var tilex = x / (terrainData.alphamapWidth / dimension); var tiley = y / (terrainData.alphamapHeight / dimension); var index = (dimension - tiley - 1) * dimension + tilex; for (int t = 0; t < textures.Length; t++) { maps[y, x, t] = index == t ? 1f : 0f; } } } terrainData.SetAlphamaps(0, 0, maps); yield return(null); // Create terrain collider. TerrainCollider terrainCollider = terrainObject.AddComponent <TerrainCollider>(); terrainCollider.terrainData = terrainData; yield return(null); // Add terrain component. Terrain terrain = terrainObject.AddComponent <Terrain>(); terrain.terrainData = terrainData; yield return(null); // Calculate mesh vertices and triangles. List <Vector3> vertices = new List <Vector3>(); List <int> triangles = new List <int>(); // Distance between vertices var step = SIZE / 32f; // Front for (int x = 0; x < terrainData.heightmapWidth; x++) { vertices.Add(new Vector3(x * step, 0f, 0f)); vertices.Add(new Vector3(x * step, data[0, x], 0f)); } yield return(null); // Right for (int z = 0; z < terrainData.heightmapHeight; z++) { vertices.Add(new Vector3(SIZE, 0f, z * step)); vertices.Add(new Vector3(SIZE, data[z, terrainData.heightmapWidth - 1], z * step)); } yield return(null); // Back for (int x = 0; x < terrainData.heightmapWidth; x++) { var xr = terrainData.heightmapWidth - 1 - x; vertices.Add(new Vector3(xr * step, 0f, SIZE)); vertices.Add(new Vector3(xr * step, data[terrainData.heightmapHeight - 1, xr], SIZE)); } yield return(null); // Left for (int z = 0; z < terrainData.heightmapHeight; z++) { var zr = terrainData.heightmapHeight - 1 - z; vertices.Add(new Vector3(0f, 0f, zr * step)); vertices.Add(new Vector3(0f, data[zr, 0], zr * step)); } yield return(null); // Quads for (int i = 0; i < vertices.Count / 2 - 1; i++) { triangles.AddRange(new int[] { 2 * i + 0, 2 * i + 1, 2 * i + 2, 2 * i + 2, 2 * i + 1, 2 * i + 3 }); } // Create single mesh for all four sides GameObject side = new GameObject("side"); side.transform.position = position; side.transform.parent = terrainObject.transform; yield return(null); // Create mesh Mesh mesh = new Mesh() { vertices = vertices.ToArray(), triangles = triangles.ToArray() }; mesh.RecalculateNormals(); mesh.RecalculateBounds(); yield return(null); MeshFilter meshFilter = side.AddComponent <MeshFilter>(); meshFilter.mesh = mesh; yield return(null); MeshRenderer meshRenderer = side.AddComponent <MeshRenderer>(); meshRenderer.material = new Material(Shader.Find("Standard")) { color = new Color32(0, 128, 128, 100) }; yield return(null); MeshCollider meshCollider = side.AddComponent <MeshCollider>(); yield return(null); buttonObject = Instantiate(buttonZoomPrefab, terrainObject.transform.position + new Vector3(0, 0.2f, 0), Quaternion.Euler(0, -90, 0)) as StableMenu; buttonObject.transform.parent = terrain.transform; yield return(null); }