protected override List <string> Generate(string inPath, string outPath, string rosPackageName = "")
 {
     return(ActionAutoGen.GenerateSingleAction(inPath, outPath, rosPackageName));
 }
示例#2
0
        private void OnGUI()
        {
            GUILayout.Label("Directory actions auto generation", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            inPath = EditorGUILayout.TextField("Input Path", inPath);
            if (GUILayout.Button("Select Folder...", GUILayout.Width(150)))
            {
                inPath = EditorUtility.OpenFolderPanel("Select Folder...", "", "");
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            outPath = EditorGUILayout.TextField("Output Location", outPath);
            if (GUILayout.Button("Select Folder...", GUILayout.Width(150)))
            {
                outPath = EditorUtility.OpenFolderPanel("Select Folder...", "", "");
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("GENERATE!"))
            {
                if (inPath.Equals(""))
                {
                    EditorUtility.DisplayDialog(
                        title: "Error",
                        message: "Empty input path!\nPlease specify input path",
                        ok: "Bricks without straw");
                }
                else
                {
                    try
                    {
                        List <string> warnings = new List <string>();
                        string[]      files    = Directory.GetFiles(inPath, "*.action", SearchOption.AllDirectories);
                        if (files.Length == 0)
                        {
                            EditorUtility.DisplayDialog(
                                title: "No action files found!",
                                message: "No action files found!",
                                ok: "Bricks without straw");
                            Reset();
                        }
                        else
                        {
                            for (int i = 0; i < files.Length; i++)
                            {
                                string   file           = files[i];
                                string[] hierarchy      = file.Split(new char[] { '/', '\\' });
                                string   rosPackageName = hierarchy[hierarchy.Length - 3];
                                try
                                {
                                    EditorUtility.DisplayProgressBar(
                                        "Working...(" + (i + 1) + "/" + files.Length + ") Checkout xkcd.com/303",
                                        "Parsing " + file,
                                        (float)(i + 1) / (float)files.Length);
                                    warnings.AddRange(ActionAutoGen.GenerateSingleAction(file, outPath, rosPackageName));
                                }
                                catch (MessageTokenizerException e)
                                {
                                    Debug.LogError(e.ToString() + e.Message);
                                    EditorUtility.DisplayDialog(
                                        title: "Message Tokenizer Exception",
                                        message: e.Message,
                                        ok: "Wait. That's illegal");
                                }
                                catch (MessageParserException e)
                                {
                                    Debug.LogError(e.ToString() + e.Message);
                                    EditorUtility.DisplayDialog(
                                        title: "Message Parser Exception",
                                        message: e.Message,
                                        ok: "Sorry but you can't ignore errors.");
                                }
                            }
                            // Done
                            EditorUtility.ClearProgressBar();
                            if (warnings.Count > 0)
                            {
                                EditorUtility.DisplayDialog(
                                    title: "Code Generation Complete",
                                    message: "Output at: " + outPath + "\nYou have " + warnings.Count + " warning(s)",
                                    ok: "I like to live dangerously");
                                foreach (string w in warnings)
                                {
                                    Debug.LogWarning(w);
                                }
                            }
                            else
                            {
                                EditorUtility.DisplayDialog(
                                    title: "Code Generation Complete",
                                    message: "Output at: " + outPath,
                                    ok: "Thank you!");
                            }
                            Reset();
                        }
                    }
                    catch (DirectoryNotFoundException e)
                    {
                        EditorUtility.DisplayDialog(
                            title: "Folder not found",
                            message: e.Message,
                            ok: "Bricks without straw");
                        Reset();
                    }
                }
            }
        }
示例#3
0
        private void OnGUI()
        {
            GUILayout.Label("Single action auto generation", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            inFilePath = EditorGUILayout.TextField("Input File Path", inFilePath);
            if (GUILayout.Button("Browse File...", GUILayout.Width(120)))
            {
                inFilePath = EditorUtility.OpenFilePanel("Select Action File...", "", "action");
                if (!inFilePath.Equals(""))
                {
                    string[] directoryLevels = inFilePath.Split('/');
                    rosPackageName = directoryLevels[directoryLevels.Length - 3];
                }
            }
            EditorGUILayout.EndHorizontal();

            rosPackageName = EditorGUILayout.TextField("ROS Package Name:", rosPackageName);

            EditorGUILayout.BeginHorizontal();
            outFilePath = EditorGUILayout.TextField("Output File Location", outFilePath);
            if (GUILayout.Button("Select Folder...", GUILayout.Width(120)))
            {
                outFilePath = EditorUtility.OpenFolderPanel("Select Folder...", "", "");
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("GENERATE!"))
            {
                if (inFilePath.Equals(""))
                {
                    EditorUtility.DisplayDialog(
                        title: "Error",
                        message: "Empty input file path!\nPlease specify input file",
                        ok: "Bricks without straw");
                }
                else
                {
                    try
                    {
                        List <string> warnings = ActionAutoGen.GenerateSingleAction(inFilePath, outFilePath, rosPackageName);
                        if (warnings.Count == 0)
                        {
                            EditorUtility.DisplayDialog(
                                title: "Code Generation Complete",
                                message: "Output at: " + outFilePath,
                                ok: "Thank you!");
                        }
                        else
                        {
                            foreach (string w in warnings)
                            {
                                Debug.LogWarning(w);
                            }
                            EditorUtility.DisplayDialog(
                                title: "Code Generation Complete",
                                message: "Output at: " + outFilePath + "\nYou have " + warnings.Count + " warning(s)",
                                ok: "I like to live dangerously");
                        }
                    }
                    catch (MessageTokenizerException e)
                    {
                        Debug.LogError(e.ToString() + e.Message);
                        EditorUtility.DisplayDialog(
                            title: "Message Tokenizer Exception",
                            message: e.Message,
                            ok: "Wait. That's illegal");
                    }
                    catch (MessageParserException e)
                    {
                        Debug.LogError(e.ToString() + e.Message);
                        EditorUtility.DisplayDialog(
                            title: "Message Parser Exception",
                            message: e.Message,
                            ok: "Sorry but you can't ignore errors.");
                    }
                }
            }
        }