RealWorldTerrainOSMMeta.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* INFINITY CODE */
  2. /* https://infinity-code.com */
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace InfinityCode.RealWorldTerrain.OSM
  7. {
  8. /// <summary>
  9. /// This class contains meta-information about the building.
  10. /// </summary>
  11. [Serializable]
  12. [AddComponentMenu("")]
  13. public class RealWorldTerrainOSMMeta : MonoBehaviour
  14. {
  15. /// <summary>
  16. /// The coordinate of the center point of the building
  17. /// </summary>
  18. public Vector2 center;
  19. /// <summary>
  20. /// Indicates that building has a URL.
  21. /// </summary>
  22. public bool hasURL;
  23. /// <summary>
  24. /// Indicates that building has a website.
  25. /// </summary>
  26. public bool hasWebsite;
  27. /// <summary>
  28. /// Indicates that building has a Wikipedia page.
  29. /// </summary>
  30. public bool hasWikipedia;
  31. /// <summary>
  32. /// Array of meta-information.
  33. /// </summary>
  34. public RealWorldTerrainOSMMetaTag[] metaInfo;
  35. private void AddInfo(string title, string info)
  36. {
  37. if (metaInfo == null) metaInfo = new RealWorldTerrainOSMMetaTag[0];
  38. List<RealWorldTerrainOSMMetaTag> metaList = new List<RealWorldTerrainOSMMetaTag>(metaInfo)
  39. {
  40. new RealWorldTerrainOSMMetaTag {info = info, title = title}
  41. };
  42. if (title == "url") hasURL = true;
  43. else if (title == "website") hasWebsite = true;
  44. else if (title == "wikipedia") hasWikipedia = true;
  45. metaInfo = metaList.ToArray();
  46. }
  47. public bool ContainKeyOrValue(string tag, bool searchInKey, bool searchInValue)
  48. {
  49. if (metaInfo == null) return false;
  50. for (int i = 0; i < metaInfo.Length; i++)
  51. {
  52. RealWorldTerrainOSMMetaTag t = metaInfo[i];
  53. if (t.CompareKeyOrValue(tag, searchInKey, searchInValue)) return true;
  54. }
  55. return false;
  56. }
  57. public RealWorldTerrainOSMMeta GetFromOSM(RealWorldTerrainOSMBase item, Vector2 center = default(Vector2))
  58. {
  59. foreach (RealWorldTerrainOSMTag itemTag in item.tags) AddInfo(itemTag.key, itemTag.value);
  60. this.center = center;
  61. return this;
  62. }
  63. }
  64. }