質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

2回答

13440閲覧

unity の外部参照について

kmiura

総合スコア16

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

1クリップ

投稿2015/02/20 08:21

編集2015/02/20 08:28

unityを使ってエディターを作成しています。使用言語はc#です。
OSはWindowsとMacを対象(開発はMac)
unityeditor上で読み込む(ダイアログボックスを出す)時には
string path = EditorUtility.OpenFilePanel ("ファイルを選択します", "", "png");
を使えばパスを入手できます。
WindowsならOpenFileDialogを使えば出来ると書いてあります。
こちらはpluginsフォルダにSystem.Windows.Forms.dllを入れるだけでエラー1になり、
using System.Windows.Forms;
で認識できずエラー
2になります。

質問は
1、unityエディターのOpenFilePanelと同じ事をMacでやりたいが、どうすればいいか?
2、プラグインエラーが出るが、対処の方法が分からない

2、補足 エラーメッセージ
*1The Assembly System.Drawing is referenced by System.Windows.Forms. But the dll is not allowed to be included or could not be found.
*2
Internal compiler error. See the console log for more information. output was:
`Unhandled Exception: System.TypeLoadException: Could not load type 'System.ComponentModel.CancelEventHandler' from assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.``

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

UnityEditor系を使わずに、という意味だったんですね。

でしたら、OSX環境なら、こんな感じでしょうか。

lang

1using UnityEngine; 2using System.Collections; 3using System.Diagnostics; 4using System.Text; 5 6public class FileChooser : MonoBehaviour 7{ 8 public const string CHOOSE_FILE = 9 "-e 'POSIX path of (get choose file of application \"System Events\" activate)'"; 10 public const string CHOOSE_FOLDER = 11 "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'"; 12 public const string CHOOSE_NEW_FILE = 13 "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'"; 14 public const string SIMPLE_DIALOG = 15 "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'"; 16 public const string FORCE_ACTIVATE = 17 "-e 'tell application \"System Events\" to activate'"; 18 19 void Start() 20 { 21 StartCoroutine (FileChooseDialog (CHOOSE_FILE, (string path) => { 22 UnityEngine.Debug.Log ("this is " + path); 23 })); 24 } 25 26 /// <summary> 27 /// osascript -e 'tell application "System Events" to POSIX path of (active choose file)' 28 /// or 29 /// osascript -e 'POSIX path of (get choose file of application "System Events" activate)' 30 /// </summary> 31 /// <returns>The choose dialog.</returns> 32 public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed) 33 { 34 Process fileDialog = new Process (); 35 fileDialog.StartInfo = new ProcessStartInfo () 36 { 37 FileName = "osascript", 38 Arguments = chooseType, 39 CreateNoWindow = true, 40 UseShellExecute = false, 41 RedirectStandardOutput = true, 42 RedirectStandardError = true, 43 }; 44 StringBuilder result = new StringBuilder (); 45 fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { 46 result.Append (e.Data); 47 }; 48 fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => { 49 UnityEngine.Debug.LogError (e.Data); 50 }; 51 fileDialog.Start (); 52 fileDialog.BeginOutputReadLine (); 53 fileDialog.BeginErrorReadLine (); 54 yield return null; 55 Process.Start (new ProcessStartInfo () { FileName = "osascript", Arguments = FORCE_ACTIVATE }); 56 while (fileDialog.HasExited == false) { 57 yield return null; 58 } 59 fileDialog.Close (); 60 fileDialog.Dispose (); 61 onClosed.Invoke (result.ToString ()); 62 } 63}

osascriptというコマンドがあるので、これを使えば標準機能なら概ね操作できます。
ただ、ファイル選択ダイアログ周りは急に反応が無くなったりもするので、注意です。
反応が無い場合は、シンプルなダイアログ(サンプルならSIMPLE_DIALOGを使って)を表示してやれば上手くいったりします。

投稿2015/02/21 07:14

編集2015/03/04 11:02
satanabe1

総合スコア113

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kmiura

2015/02/25 10:38

yieldから進まなくなり、アップル系の時間切れエラーが返ってきました。 osascriptについては全然分からないので少し勉強してみます。
satanabe1

2015/02/25 12:42

System Eventsがアクティブにならないとダメかもしれませんね。 コードを若干修正しました。 1frame後に`Process.Start (new ProcessStartInfo () { FileName = "osascript", Arguments = FORCE_ACTIVATE });`で強制アクティベートを挟みました。 おそらく、これでいけるかと。
satanabe1

2015/02/25 12:47

すみません。 なんか変なエスケープ入ってますね・・・
AliHassan

2018/05/04 08:59

i think dll file doesn't have permission to do so, perhaps you need set permission , hopefully i work
guest

0

windowsでもmacでも、 EditorUtility.OpenFilePanel(string,string,string)でファイル選択ダイアログを開けます。

*1のエラーは、System.Windows.Forms.dllがSystem.Drawing.dllに依存しているのに、System.Drawing.dllが見つからないためエラーになっています。

投稿2015/02/20 17:43

satanabe1

総合スコア113

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kmiura

2015/02/21 00:52

回答ありがとうございます。 windows、macというのはexe、appで書き出した物で実行した場合ですので、 EditorUtilityというのはUnityEditor用の命令文なため書き出そうとするとエラーになっています 他にもDLLが必要だったのですね!ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問