外部のjsonファイルを読み込みたいので,以下のようなものを作りました. ほぼ参考記事の通りです!!
成果物
コード
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //Input Field用に使う using System.Windows.Forms; //OpenFileDialog用に使う public class GetFiles : MonoBehaviour { // Start is called before the first frame update public InputField input_field_path_; void Start () { } // Update is called once per frame void Update () { } public void OpenExistFile () { OpenFileDialog open_file_dialog = new OpenFileDialog (); // ハング解消をするため open_file_dialog.ShowHelp = true; //InputFieldの初期値を代入しておく(こうするとダイアログがその場所から開く) // open_file_dialog.FileName = input_field_path_.text; //jsonファイルを開くことを指定する open_file_dialog.Filter = "jsonファイル|*.json"; //ファイルが実在しない場合は警告を出す(true)、警告を出さない(false) open_file_dialog.CheckFileExists = true; //ダイアログを開く open_file_dialog.ShowDialog (); //取得したファイル名をInputFieldに代入する Debug.Log (open_file_dialog.FileName); // input_field_path_.text = open_file_dialog.FileName; // Debug.Log (input_field_path_.text); } }
設定など
ボタンには,上のスクリプトをアタッチしたobjectからダイアログを開く関数を呼んでいます