私はUnity 5でアーケードGUIを作成しています。実装したい主な機能は、(ファイル構造内の)各ゲームのボタンを自動的に作成するシステムです。ビルドに含まれていないファイルから1スプライトとテキストをロードします。私はアーケードにビルドと同じフォルダにファイルを読み込ませ、それらのファイルをビルドに含める必要はありません。ここで私はで実験し、いくつかのコードは次のとおりです。誰も私が私が使用する必要がある具体的な方法を知らせることができた場合実行時にイメージを読み込む際の問題(ビルド後)
DirectoryInfo DirectoryToFiles = new DirectoryInfo ("Games");
DirectoryInfo[] Folders = DirectoryToFiles.GetDirectories();
foreach (DirectoryInfo Folder in Folders) {
FileInfo[] Files = Folder.GetFiles();
string filename = Files [0].Name.Substring(0,Files [0].Name.IndexOf("."));
//Loads Image
Image = Resources.Load ("Games" + "/" + Folder.Name + "/" + filename + ".png") as Texture2D;
ButtonSprite = Sprite.Create (Image, new Rect (0, 0, Image.width, Image.height), new Vector2 (0f, 0f));
//The Declaration of "ButtonSprite" returns a NullReferenceException
//Reads Description File
GameDescription = ReadFile (Folder,filename);
//Gives Path to Play Button
GameObject.Find ("Play").GetComponent<PlayButton>().UpdatePath ("Games" + "/" + Folder.Name + "/" + filename + ".exe");
//Transfers All Variables to the new Button
CurrentButton = Instantiate (GameButton, GameObject.Find ("Content").GetComponent<Transform>());
CurrentButton.GetComponent<Transform>().localPosition = new Vector3 (x,0f,1f);
x += 230;
CurrentButton.GetComponent<ButtonInstantiate>().UpdateVariables (ButtonSprite, GameName.Substring(0,GameName.IndexOf(".")), GameDescription, Hours);
This is what my Build file looks like.
This is what the File structure looks like
、私はそれをお願い申し上げます。ありがとう!