Jump to content

Troubles opening file explorer from plugin (UnityEditor and System.Windows.Forms)


Fishfinger

Recommended Posts

Hello Mod Community!

I'm currently developing a mod which requires the selection of an or several image(s) by the player. Preferably I would like to do using the Windows File Explorer. I've tried two methods, using UnityEngine and another one using System.Windows.Forms. None of them worked and I've heard that apparently people have had issues with the file explorer when modding before...

UnityEditor method

EditorUtility.OpenFilePanel("Select reference image!", "", "png");

Which gave me this error:
unknown.png

I heard the apparently KSP doesn't use UnityEditor so I added the UnityEditor.dll file into the plugins folder which changed the error from the beforementioned one to this one:

unknown.png

Anyone have any experience with UnityEditor and KSP modding, please let me know!

System Windows Forms method

            string refImgPath = "";

            OpenFileDialog fileDialog_ = new OpenFileDialog();
            fileDialog_.InitialDirectory = @"c:\";
            fileDialog_.Filter = "png";
            fileDialog_.RestoreDirectory = false;

            if (fileDialog_.ShowDialog() == DialogResult.OK)
            {
                refImgPath = fileDialog_.FileName;
            }
            Debug.Log(refImgPath);

Which gave me this error:

unknown.png

I didn't know where to continue from here, anyone know what's wrong?

Basically I need help with getting an file (image) explorer window working to get the path to any given image. Thank you in advance for any help!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...