addLOD.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Google.Maps.Examples.Shared;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. [RequireComponent(typeof(DynamicMapsService))]
  6. public class addLOD : MonoBehaviour
  7. {
  8. private string[] strs = { "Parapet", "Border" };
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. }
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. }
  17. private void Awake()
  18. {
  19. // Get the required Dynamic Maps Service on this GameObject.
  20. DynamicMapsService dynamicMapsService = GetComponent<DynamicMapsService>();
  21. // Sign up to event called after each new building is loaded, so can assign Materials to this
  22. // new building. Note that:
  23. // - DynamicMapsService.MapsService is auto-found on first access (so will not be null).
  24. // - This event must be set now during Awake, so that when Dynamic Maps Service starts loading
  25. // the map during Start, this event will be triggered for all Extruded Structures.
  26. dynamicMapsService.MapsService.Events.ExtrudedStructureEvents.DidCreate.AddListener(
  27. args =>
  28. {
  29. //LOD[] lods = new LOD[2];
  30. //lods[0] = new LOD();
  31. //lods[0].renderers[0] = args.GameObject.GetComponent<MeshRenderer>();
  32. //lods[1] = new LOD();
  33. //lods[1].renderers[0] = args.GameObject.AddComponent<MeshRenderer>();
  34. //GameObject dup = Instantiate(obj);
  35. //dup.name = "dup";
  36. //dup.transform.SetParent(args.GameObject.transform);
  37. LODGroup group = args.GameObject.AddComponent<LODGroup>();
  38. LOD[] lods = new LOD[3];
  39. lods[0] = new LOD();
  40. Debug.LogError(args.GameObject.transform.childCount);
  41. //foreach (var baum in )
  42. //{
  43. // List<Renderer> renderers = new List<Renderer>(lods[0].renderers)
  44. // {
  45. // baum.GetComponent<MeshRenderer>()
  46. // };
  47. // lods[0].renderers = renderers.ToArray();
  48. //}
  49. group.SetLODs(lods);
  50. //group.SetLODs(lods);
  51. });
  52. }
  53. }