Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Dudledok · Aug 13, 2014 at 01:17 PM · c#editorunityeditorload

Equivalent of OpenFilePanel without using UnityEditor?

I used OpenFilePanel to allow players to select text files they have created and make levels from that, but have since discovered the issue with using this. See my code below:

 if (GUI.Button(new Rect(210, 260, 100, 40), "Select file")) {
     filePath = EditorUtility.OpenFilePanel("level",Application.streamingAssetsPath,"txt");
     if(filePath.Length != 0) {
         selectedFile = true;
     }
 }

As you can see I simply let users select a file from the Panel which pops up, and then save that path which is used later to create the level accordingly, and it works fine, but using UnityEditor I can't compile this. Is there an alternative which does the same?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by niall1111 · Aug 13, 2014 at 01:19 PM

It's quite a bit more difficult than doing it in the editor, and sort of ugly, but I did it starting from this thing: http://wiki.unity3d.com/index.php?title=ImprovedFileBrowser

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dudledok · Aug 17, 2014 at 09:18 AM 0
Share

A lot of faff for a file browser when the editor has such a simple way of doing it. Anyway, if anyone sees this and is looking for a quicker way, there's a free asset here: https://www.assetstore.unity3d.com/en/#!/content/18308

avatar image
4

Answer by gkngkc · Jan 11, 2017 at 08:43 AM

You can use this simple native file wrapper standalone builds;

https://github.com/gkngkc/UnityStandaloneFileBrowser

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image giggioz · Mar 14, 2019 at 08:53 PM 0
Share

This works and it's very easy to use!

avatar image
2

Answer by DanielSRRosky1999 · Nov 25, 2019 at 05:08 AM

Download and import this Unity Asset Store: https://assetstore.unity.com/packages/tools/gui/runtime-file-browser-113006

This plugin is for Mac, Windows and Android

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by viju · Jan 27, 2016 at 03:17 PM

I was finding difficulty to do it using OpenFilePanel for my simple requirement of opening some files. So, I did a bit of lateral thinking to do it this way.

Create a Panel and a Dropdown with any name. I have named the dropdown as "File Selection". Please see the image attached.

Wrote a small code to load all the files from "Application.persistentDataPath".

 using UnityEngine;
 using UnityEngine.UI;
 using System.IO;

 public class BehaviorScript : MonoBehaviour
 {
     // Use this for initialization
     void Start ()
     {
         DirectoryInfo directoryInfo = new DirectoryInfo (Application.persistentDataPath);
         FileInfo[] fileInfo = directoryInfo.GetFiles ("*.*", SearchOption.AllDirectories);
         GameObject.Find ("File Selection").GetComponent<Dropdown> ().options.Clear ();
         foreach (FileInfo file in fileInfo) {
             Dropdown.OptionData optionData = new Dropdown.OptionData (file.Name);
             GameObject.Find ("File Selection").GetComponent<Dropdown> ().options.Add (optionData);
             GameObject.Find ("File Selection").GetComponent<Dropdown> ().value = 1;
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by coolraiman · Jan 27, 2016 at 06:12 PM

you cant use it in a build

in the editor it work but it cant get in a build. you may need to make your own custom file selector/explorer

also, if you want to build without removing code everytime do it like how i did

 #if UNITY_EDITOR
 using UnityEditor;

 #endif
 //only in editor
     #if UNITY_EDITOR
     //prevent multiple dialogs
     public bool dialogIsOpen = false;
 
     protected virtual void Update()
     {
         if(rend == null)
         {
             rend = GetComponent<Renderer>();
         }
         //make sure to only show dialog in editor mode while not playing
         if(!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isPaused)
         {
             //get the colliders
             MeshCollider box = GetComponent<MeshCollider>();
             BoxCollider poly = GetComponent<BoxCollider>();
             //if no dialogs && no collider && currently a sprite
             if(!dialogIsOpen && box == null && poly == null && rend.material.mainTexture.name != null)
             {
                 setCollider();
             }
 
         }
     }
     //show a dialog ans ask the user wich collider to use
     private void setCollider()
     {
         dialogIsOpen = true;
         //destroy current collider
         DestroyImmediate(GetComponent<MeshCollider>());
         DestroyImmediate(GetComponent<BoxCollider>());
         //show dialog box
         if(UnityEditor.EditorUtility.DisplayDialog("Choose a Component", "You need one of the two component for your button to work","MeshCollider", "BoxCollider"))
         {
             gameObject.AddComponent<MeshCollider>();
         }
         else
         {
             gameObject.AddComponent<BoxCollider>();
         }
         dialogIsOpen = false;
     }
 
     #endif


i used it with [ExecuteInEditMode] to make some kind of conditionnal [RequireComponent] to make sure the game designer dont forget some component or to prevent to duplicate prefabs with just a different collider

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Working with Unity Editor 1 Answer

Custom Unity Editor Issue 1 Answer

Unity Editor script arrows to display a variable 2 Answers

Initialising List array for use in a custom Editor 1 Answer

Looking for a editor with a charcoal theme? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges