Search Unity

Inspector GUI - Opening a file?

Discussion in 'Scripting' started by astracat111, Apr 28, 2017.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    Hey there,

    I have like a custom inspector in where I use my own kind of scripting language...I don't know if you'd even call it that, but in any case my inspector ends up looking like this:



    My plan with this was to go into Notepad++ and create a custom auto completion thing or whatever so that I can color my language.

    What I want to do now, though, is to create a button after the 'load script' button underneath the save button.

    I know that once I have the path to the file I can use this little snippet:

    Code (CSharp):
    1. List<string> eventCommandsFromFile = File.ReadAllLines(filePathAndName).ToList();
    I can also see that you have to use this:

    https://docs.unity3d.com/ScriptReference/EditorUtility.OpenFilePanel.html

    I've got my custom inspector script all set up, I know how to create the button, but I'm not sure how to implement this properly:

    Code (CSharp):
    1. if (GUILayout.Button ("Add From Script", GUILayout.Width (300f), GUILayout.MinWidth (0f))) {
    2.    if (EditorUtility.DisplayDialog ("Add From Script", "This will overwrite all Ecmds on the current page. Are you sure?", "Yes", "Cancel")) {
    3.           //Not sure what I would put here...
    4.     }
    5. }
    I'm wondering if I put in like....

    Code (CSharp):
    1. string fileAndPath = EditorUtility.OpenFilePanel("Select Event File", "", "event");
    I don't know why but last time I did that it had the open file panel open and I couldn't close it.