protected virtual void OnGUI() { EditorGUILayout.BeginHorizontal(); MessageGenBrowserSettings settings = MessageGenBrowserSettings.Get(); string inPath = settings.inputPath; inPath = EditorGUILayout.TextField("ROS message path", inPath); if (GUILayout.Button("Select Folder...", GUILayout.Width(150))) { inPath = EditorUtility.OpenFolderPanel("Select ROS message folder", inPath, ""); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); string relativeOutPath = settings.relativeOutPath; relativeOutPath = EditorGUILayout.TextField("Built message path", relativeOutPath); if (GUILayout.Button("Select Folder...", GUILayout.Width(150))) { string absOutPath = EditorUtility.OpenFolderPanel("Select Unity message folder...", settings.outputPath, ""); if (absOutPath != "") { relativeOutPath = MessageGenBrowserSettings.ToRelativePath(absOutPath); } } EditorGUILayout.EndHorizontal(); if (!Directory.Exists(inPath)) { if (GUILayout.Button("Select ROS folder", GUILayout.Width(200))) { inPath = EditorUtility.OpenFolderPanel("Select ROS message folder", inPath, ""); } } else { EditorGUILayout.LabelField(inPath + ":"); m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos); if (m_IsCacheDirty || m_CacheRoot.path == null) { RefreshCache(inPath); } ShowCachedEntry(m_CacheRoot); EditorGUILayout.EndScrollView(); } if (inPath != settings.inputPath || relativeOutPath != settings.relativeOutPath) { if (inPath != "") { settings.inputPath = inPath; } settings.relativeOutPath = relativeOutPath; settings.Save(); m_IsCacheDirty = true; } }
public override void OnImportAsset(AssetImportContext ctx) { string inputPath = Path.Combine(Directory.GetCurrentDirectory(), ctx.assetPath); string outputPath = MessageGenBrowserSettings.Get().outputPath; MessageAutoGen.GenerateSingleMessage(inputPath, outputPath); string builtPath = MessageAutoGen.GetMessageClassPath(inputPath, outputPath); string builtAssetPath = Path.Combine("Assets", MessageGenBrowserSettings.ToRelativePath(builtPath)); AssetDatabase.ImportAsset(builtAssetPath); Object messageClass = AssetDatabase.LoadAssetAtPath(builtAssetPath, typeof(MonoScript)); if (messageClass != null) { ctx.AddObjectToAsset("messageClass", messageClass); } }