8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unityでファイル選択画面を使う

Last updated at Posted at 2020-08-20

###↓こんな感じのダイアログボックスを使ってファイルを選択したい:thinking:
image.png

追記
※ビルド後にこのダイアログボックスを使用することはできないらしい
ビルド後に使うならOpenFileDialogを使うのが正解
こことかここの記事が使えそう

#Script

script
using UnityEditor;

 public void OpenFile()
    {
        //パスの取得
        var path = EditorUtility.OpenFilePanel("Open csv", "", "CSV");
        if (string.IsNullOrEmpty(path))
            return;
        Debug.Log(path);

        //読み込み
        var reader = new StreamReader(path);
        Debug.Log(reader);
    }

#詳細 //ここでダイアログボックスを出す

##1つのファイルを選択

script
        var path = EditorUtility.OpenFilePanel("Open csv", "", "CSV");
        var path = EditorUtility.OpenFilePanel(ダイアログボックスの名前, ディレクトリのデフォルト設定,読み込むファイルの拡張子 );

EditorUtility.OpenFilePanel

##複数種類のファイル拡張子を指定する場合

script
var path = EditorUtility.OpenFilePanelWithFilters("Open Music", "", {"音楽ファイル","mp3,ogg,wav"});

EditorUtility.OpenFilePanelWithFilters

##フォルダーを選択する場合

script
var path = EditorUtility.OpenFolderPanel("Open Folder", "", "");

EditorUtility.OpenFolderPanel

8
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?