RealWorldTerrainVectorTerrainLayerFeature.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* INFINITY CODE */
  2. /* https://infinity-code.com */
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine;
  7. namespace InfinityCode.RealWorldTerrain
  8. {
  9. [Serializable]
  10. public class RealWorldTerrainVectorTerrainLayerFeature
  11. {
  12. public const float TerrainLayerLineHeight = 20;
  13. private static string[] _layerNames;
  14. private static List<string> _landuseNames;
  15. private static List<string> _landuseOverlayNames;
  16. private static List<string> _structureNames;
  17. private static List<string> _waterwayNames;
  18. public List<TerrainLayer> terrainLayers;
  19. public Vector2 noiseOffset = Vector2.zero;
  20. public float noiseScale = 16;
  21. public List<Rule> rules;
  22. [NonSerialized]
  23. private float? _height;
  24. public float height
  25. {
  26. get
  27. {
  28. if (!_height.HasValue) UpdateHeight();
  29. return _height.Value;
  30. }
  31. }
  32. public static List<string> landuseNames
  33. {
  34. get
  35. {
  36. if (_landuseNames == null) _landuseNames = Enum.GetNames(typeof(RealWorldTerrainMapboxLanduse)).ToList();
  37. return _landuseNames;
  38. }
  39. }
  40. public static List<string> landuseOverlayNames
  41. {
  42. get
  43. {
  44. if (_landuseOverlayNames == null) _landuseOverlayNames = Enum.GetNames(typeof(RealWorldTerrainMapboxLanduseOverlay)).ToList();
  45. return _landuseOverlayNames;
  46. }
  47. }
  48. public static string[] layerNames
  49. {
  50. get
  51. {
  52. if (_layerNames == null) _layerNames = Enum.GetNames(typeof(RealWorldTerrainMapboxLayer));
  53. return _layerNames;
  54. }
  55. }
  56. public static List<string> structureNames
  57. {
  58. get
  59. {
  60. if (_structureNames == null) _structureNames = Enum.GetNames(typeof(RealWorldTerrainMapboxStructure)).ToList();
  61. return _structureNames;
  62. }
  63. }
  64. public static List<string> waterwayNames
  65. {
  66. get
  67. {
  68. if (_waterwayNames == null) _waterwayNames = Enum.GetNames(typeof(RealWorldTerrainMapboxWaterway)).ToList();
  69. return _waterwayNames;
  70. }
  71. }
  72. public void UpdateHeight()
  73. {
  74. int rows = 3;
  75. if (terrainLayers == null) rows += 1;
  76. else if (terrainLayers.Count == 1) rows += 1;
  77. else rows += terrainLayers.Count + 2;
  78. if (rules != null)
  79. {
  80. foreach (Rule rule in rules) rows += rule.hasExtra ? 3 : 2;
  81. }
  82. _height = rows * TerrainLayerLineHeight + 5;
  83. }
  84. [Serializable]
  85. public class Rule
  86. {
  87. public RealWorldTerrainMapboxLayer layer = RealWorldTerrainMapboxLayer.building;
  88. public int extra = ~0;
  89. [NonSerialized]
  90. private string _layerName;
  91. public string layerName
  92. {
  93. get
  94. {
  95. if (_layerName == null) _layerName = layer.ToString();
  96. return _layerName;
  97. }
  98. }
  99. public bool hasExtra
  100. {
  101. get
  102. {
  103. return layer == RealWorldTerrainMapboxLayer.landuse_overlay ||
  104. layer == RealWorldTerrainMapboxLayer.landuse ||
  105. layer == RealWorldTerrainMapboxLayer.waterway ||
  106. layer == RealWorldTerrainMapboxLayer.structure;
  107. }
  108. }
  109. }
  110. }
  111. }