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("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;
            }
        }
Example #2
0
        CachedEntryStatus GetFileStatus(string path)
        {
            switch (Path.GetExtension(path))
            {
            case ".msg":
                string builtPath = MessageAutoGen.GetMessageClassPath(path, MessageGenBrowserSettings.Get().outputPath);
                return(File.Exists(builtPath) ? CachedEntryStatus.BuiltMsgFile : CachedEntryStatus.UnbuiltMsgFile);

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

            return(CachedEntryStatus.Ignored);
        }
Example #3
0
    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
        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 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;
                    }
                    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);
                    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);
                    }
                }
            }
        }