private void SetPathMaterial(int x, int z) { if (!_path[x, z]) { _terrain.SetSubmaterial(x, z, 0); } else { // check the 4 adjacent squares to pick the correct image int[] adj = new int[4]; for (int i = 0; i < 4; ++i) { int checkX = x + dx[i]; int checkZ = z + dz[i]; adj[i] = (checkX > 0 && checkX < _terrain.CountX && checkZ > 0 && checkZ < _terrain.CountZ && _path[checkX, checkZ]) ? 1 : 0; } _terrain.SetSubmaterial( x, z, _subMaterial[adj[0], adj[1], adj[2], adj[3]], _rotation[adj[0], adj[1], adj[2], adj[3]]); } }
/// <summary> /// Handle a click event on the terrain. /// </summary> /// <param name="sender">Not used.</param> /// <param name="args">The terrain click arguments.</param> private void Clicked(object sender, TerrainClickedArgs args) { if (args.Button == MouseButton.Left) { Transition(GameState.EditingTerrain, args); } if (Application.isEditor) { GameLogger.Info("Selected ({0}); Point Heights ({1}, {2}, {3}, {4})", args.ClickLocation, _terrain.GetVertexHeight(args.ClickLocation.x, args.ClickLocation.z), _terrain.GetVertexHeight(args.ClickLocation.x + 1, args.ClickLocation.z), _terrain.GetVertexHeight(args.ClickLocation.x, args.ClickLocation.z + 1), _terrain.GetVertexHeight(args.ClickLocation.x + 1, args.ClickLocation.z + 1)); if (Input.GetKey(KeyCode.LeftControl)) { int submaterial = _terrain.GetSubmaterial(args.ClickLocation.x, args.ClickLocation.z); _terrain.SetSubmaterial(args.ClickLocation.x, args.ClickLocation.z, (submaterial + 1) % _terrain.SubmaterialCount, Rotation.deg270); } } }