URPExample.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Google.Maps.Coord;
  2. using Google.Maps.Event;
  3. using Google.Maps.Examples.Shared;
  4. using Google.Maps.Feature.Style.Settings;
  5. using UnityEngine;
  6. namespace Google.Maps.Examples {
  7. /// <summary>
  8. /// This example demonstrates a basic usage of the Maps SDK for Unity with the Lightweight
  9. /// Render Pipeline.
  10. /// </summary>
  11. [RequireComponent(typeof(MapsService))]
  12. public class URPExample : MonoBehaviour {
  13. /// <summary>
  14. /// Settings used to style regions.
  15. /// </summary>
  16. [Tooltip("Settings used to style regions.")]
  17. public RegionStyleSettings RegionStyleSettings;
  18. /// <summary>
  19. /// Settings used to style roads.
  20. /// </summary>
  21. [Tooltip("Settings used to style roads.")]
  22. public SegmentStyleSettings RoadStyleSettings;
  23. /// <summary>
  24. /// Settings used to style are water.
  25. /// </summary>
  26. [Tooltip("Settings used to style area water.")]
  27. public AreaWaterStyleSettings WaterStyleSettings;
  28. /// <summary>
  29. /// Settings used to style extruded structures.
  30. /// </summary>
  31. [Tooltip("Settings used to style extruded structures.")]
  32. public ExtrudedStructureStyleSettings ExtrudedStructureStyleSettings;
  33. /// <summary>
  34. /// Settings used to style modeled structures.
  35. /// </summary>
  36. [Tooltip("Settings used to style modeled structures.")]
  37. public ModeledStructureStyleSettings ModeledStructureStyleSettings;
  38. /// <summary>
  39. /// <see cref="LatLng"/> of the initial load position.
  40. /// </summary>
  41. [Tooltip("LatLng to load (must be set before hitting play).")]
  42. public LatLng LatLng = new LatLng(40.6892199, -74.044601);
  43. /// <summary>
  44. /// Load range, in meters, of map around <see cref="LatLng"/> above.
  45. /// </summary>
  46. [Tooltip("Map load range in meters.")]
  47. public float LoadRange = 500;
  48. /// <summary>
  49. /// Use <see cref="MapsService"/> to load geometry.
  50. /// </summary>
  51. private void Start() {
  52. // Get required MapsService component on this GameObject.
  53. MapsService mapsService = GetComponent<MapsService>();
  54. // Set real-world location to load.
  55. mapsService.InitFloatingOrigin(LatLng);
  56. // Configure Map Styling.
  57. GameObjectOptions options = new GameObjectOptions();
  58. options.RegionStyle =
  59. RegionStyleSettings.Apply(options.RegionStyle);
  60. options.SegmentStyle =
  61. RoadStyleSettings.Apply(options.SegmentStyle);
  62. options.AreaWaterStyle =
  63. WaterStyleSettings.Apply(options.AreaWaterStyle);
  64. options.ExtrudedStructureStyle =
  65. ExtrudedStructureStyleSettings.Apply(options.ExtrudedStructureStyle);
  66. options.ModeledStructureStyle =
  67. ModeledStructureStyleSettings.Apply(options.ModeledStructureStyle);
  68. // Load map with default options.
  69. Bounds bounds = new Bounds(Vector3.zero, Vector3.one * LoadRange);
  70. mapsService.LoadMap(bounds, options);
  71. }
  72. }
  73. }