MegaShapeOSMWindow.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. public class MegaShapeOSMWindow : EditorWindow
  5. {
  6. public static float importscale = 1.0f;
  7. public static float smoothness = 0.0f;
  8. public static bool constantspeed = true;
  9. public static bool combine = false;
  10. public static MegaShapeOSM osm;
  11. public static string text;
  12. public static string importname;
  13. public static bool showtags = true;
  14. Vector2 pos;
  15. static public void Init()
  16. {
  17. MegaShapeOSMWindow window = ScriptableObject.CreateInstance<MegaShapeOSMWindow>();
  18. #if UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019 || UNITY_2020
  19. window.titleContent = new GUIContent("Import OSM");
  20. #else
  21. window.title = "Import OSM";
  22. #endif
  23. window.position = new Rect(Screen.width / 2, Screen.height / 2, 250, 150);
  24. window.ShowUtility();
  25. }
  26. void OnGUI()
  27. {
  28. importscale = EditorGUILayout.FloatField("Import Scale", importscale);
  29. constantspeed = EditorGUILayout.Toggle("Constant Speed", constantspeed);
  30. //combine = EditorGUILayout.Toggle("Combine Splines", combine);
  31. smoothness = EditorGUILayout.Slider("Smoothness", smoothness, 0.0f, 2.0f);
  32. if ( GUILayout.Button("Open OSM File") )
  33. {
  34. string filename = EditorUtility.OpenFilePanel("OSM File", lastosmpath, "OSM");
  35. if ( filename == null || filename.Length < 1 )
  36. return;
  37. lastosmpath = filename;
  38. StreamReader streamReader = new StreamReader(filename);
  39. text = streamReader.ReadToEnd();
  40. streamReader.Close();
  41. osm = new MegaShapeOSM();
  42. importname = System.IO.Path.GetFileNameWithoutExtension(filename);
  43. osm.readOSMData(text); //, importscale, constantspeed, importname, smoothness); //scale); //.splines[0]);
  44. }
  45. showtags = EditorGUILayout.Foldout(showtags, "Catagories");
  46. if ( showtags )
  47. {
  48. pos = EditorGUILayout.BeginScrollView(pos, "box");
  49. for ( int i = 0; i < MegaShapeOSM.tags.Count; i++ )
  50. {
  51. MegaShapeOSMTag tag = MegaShapeOSM.tags[i];
  52. tag.show = EditorGUILayout.Foldout(tag.show, tag.k);
  53. if ( tag.show )
  54. {
  55. EditorGUILayout.BeginHorizontal();
  56. EditorGUILayout.LabelField("", GUILayout.Width(8));
  57. bool import = EditorGUILayout.Toggle("", tag.import, GUILayout.Width(14));
  58. if ( import != tag.import )
  59. {
  60. tag.import = import;
  61. for ( int j = 0; j < tag.vs.Count; j++ )
  62. {
  63. MegaShapeOSMTag tagv = tag.vs[j];
  64. tagv.import = import;
  65. }
  66. }
  67. EditorGUILayout.LabelField(tag.k);
  68. EditorGUILayout.EndHorizontal();
  69. for ( int j = 0; j < tag.vs.Count; j++ )
  70. {
  71. MegaShapeOSMTag tagv = tag.vs[j];
  72. EditorGUILayout.BeginHorizontal();
  73. EditorGUILayout.LabelField("", GUILayout.Width(24));
  74. tagv.import = EditorGUILayout.Toggle("", tagv.import, GUILayout.Width(14));
  75. EditorGUILayout.LabelField(tagv.k);
  76. EditorGUILayout.EndHorizontal();
  77. }
  78. }
  79. }
  80. EditorGUILayout.EndScrollView();
  81. }
  82. if ( GUILayout.Button("Import") )
  83. {
  84. osm.importData(text, importscale, constantspeed, importname, smoothness, combine); //scale); //.splines[0]);
  85. this.Close();
  86. }
  87. }
  88. static public string lastosmpath = "";
  89. [MenuItem("Assets/Import OSM")]
  90. static void ImportOSM()
  91. {
  92. Init();
  93. }
  94. }