Example #1
0
        protected virtual void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            MessageGenBrowserSettings settings = MessageGenBrowserSettings.Get();
            string inPath = settings.inputPath;

            inPath = EditorGUILayout.TextField("ROS message path", inPath);
            if (GUILayout.Button("Browse", GUILayout.Width(100)))
            {
                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("Browse", GUILayout.Width(100)))
            {
                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 static MessageGenBrowserSettings Get()
 {
     if (settings == null)
     {
         settings = AssetDatabase.LoadAssetAtPath <MessageGenBrowserSettings>(Path.Combine("Assets", SETTINGS_FILENAME));
         if (settings == null)
         {
             settings                 = ScriptableObject.CreateInstance <MessageGenBrowserSettings>();
             settings.inputPath       = "";
             settings.relativeOutPath = "RosMessages";
         }
     }
     return(settings);
 }
        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);
            }
        }
Example #4
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var inputPath  = Path.Combine(Directory.GetCurrentDirectory(), ctx.assetPath);
            var outputPath = MessageGenBrowserSettings.Get().outputPath;

            ActionAutoGen.GenerateSingleAction(inputPath, MessageGenBrowserSettings.Get().outputPath);

            foreach (string builtPath in ServiceAutoGen.GetServiceClassPaths(inputPath, outputPath))
            {
                var builtAssetPath = Path.Combine("Assets", MessageGenBrowserSettings.ToRelativePath(builtPath));
                AssetDatabase.ImportAsset(builtAssetPath);
                var messageClass = AssetDatabase.LoadAssetAtPath(builtAssetPath, typeof(MonoScript));
                if (messageClass != null)
                {
                    ctx.AddObjectToAsset("messageClass", messageClass);
                }
            }
        }
Example #5
0
        CachedEntryStatus GetFileStatus(string path)
        {
            switch (Path.GetExtension(path))
            {
            case ".msg":
                string builtMessagePath = MessageAutoGen.GetMessageClassPath(path, MessageGenBrowserSettings.Get().outputPath);
                return(File.Exists(builtMessagePath) ? CachedEntryStatus.BuiltMsgFile : CachedEntryStatus.UnbuiltMsgFile);

            case ".srv":
                string[] builtServicePaths = ServiceAutoGen.GetServiceClassPaths(path, MessageGenBrowserSettings.Get().outputPath);
                return(builtServicePaths.All(file => File.Exists(file)) ? CachedEntryStatus.BuiltSrvFile : CachedEntryStatus.UnbuiltSrvFile);

            case ".action":
                string[] builtActionPaths = ActionAutoGen.GetActionClassPaths(path, MessageGenBrowserSettings.Get().outputPath);
                return(builtActionPaths.All(file => File.Exists(file)) ? CachedEntryStatus.BuiltActionFile : CachedEntryStatus.UnbuiltActionFile);
            }

            return(CachedEntryStatus.Ignored);
        }
Example #6
0
        void ShowCachedEntry(CachedEntry entry)
        {
            if (entry.status == CachedEntryStatus.Ignored)
            {
                return;
            }
            else if (entry.status != CachedEntryStatus.Folder)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(entry.label);

                if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH)))
                {
                    // build this msg, srv, or action file
                    switch (entry.status)
                    {
                    case CachedEntryStatus.BuiltMsgFile:
                    case CachedEntryStatus.UnbuiltMsgFile:
                        MessageAutoGen.GenerateSingleMessage(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;

                    case CachedEntryStatus.BuiltSrvFile:
                    case CachedEntryStatus.UnbuiltSrvFile:
                        ServiceAutoGen.GenerateSingleService(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;

                    case CachedEntryStatus.BuiltActionFile:
                    case CachedEntryStatus.UnbuiltActionFile:
                        ActionAutoGen.GenerateSingleAction(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;
                    }
                    AssetDatabase.Refresh();
                    m_IsCacheDirty = true;
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                bool isFoldedOut = m_FoldedOutHash.Contains(entry.path);

                EditorGUILayout.BeginHorizontal();
                bool shouldBeFoldedOut = EditorGUILayout.Foldout(isFoldedOut, entry.label, true, EditorStyles.foldout);
                if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH)))
                {
                    // build this directory
                    MessageAutoGen.GenerateDirectoryMessages(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    ServiceAutoGen.GenerateDirectoryServices(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    ActionAutoGen.GenerateDirectoryActions(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    AssetDatabase.Refresh();
                    m_IsCacheDirty = true;
                }
                EditorGUILayout.EndHorizontal();

                if (isFoldedOut)
                {
                    EditorGUI.indentLevel++;
                    foreach (CachedEntry subEntry in entry.contents)
                    {
                        ShowCachedEntry(subEntry);
                    }
                    EditorGUI.indentLevel--;
                }

                if (shouldBeFoldedOut != isFoldedOut)
                {
                    m_IsCacheDirty = true;

                    if (shouldBeFoldedOut)
                    {
                        m_FoldedOutHash.Add(entry.path);
                    }
                    else
                    {
                        m_FoldedOutHash.Remove(entry.path);
                    }
                }
            }
        }