前提・実現したいこと
ここに質問の内容を詳しく書いてください。
(例)unity とc#をつかって下記のコードを書きました。
やりたいことはprocessedfileという配列にunity Resources内の既存のfile名を格納
Unity Resources内に新たにimportしたfile名とprocessedfile内のfileが一致したか、してないかで条件作成
条件があてはまらなければprefab作成といものを考えています
発生している問題・エラーメッセージ
ArgumentNullException: Value cannot be null. Parameter name: array System.Array.IndexOf[T] (T[] array, T value) (at <437ba245d8404784b9fbab9b439ac908>:0) getfish.Update () (at Assets/getfish.cs:39)
該当のソースコード
c#
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.IO; using System.Threading; public class getfish : MonoBehaviour { public static String[] processedFiles; // Start is called before the first frame update static void Main(string[] args) { processedFiles = new String[1]; //動的に配列のサイズを変えるので最初は配列の数を1個で作成。 Console.WriteLine(processedFiles.Length); } // Update is called once per frame void Update() { IEnumerable<string> files = System.IO.Directory.EnumerateFiles( @"C:\Users\pokem\aquarium\Assets\Resources", "*", System.IO.SearchOption.AllDirectories); foreach (string f in files) { //ファイル名を取得 string str = Path.GetFileName(f); //処理済み一覧に一致するファイル名があるかどうかチェック int i = Array.IndexOf(processedFiles, str); Console.WriteLine("0以上なら配列に同じファイルが存在する " + i); //配列に一致するファイル名があれば、このファイルの処理を飛ばす if (i > -1) { Console.WriteLine("continueしました"); continue;//次のファイルの処理へ移る } GameObject obj = (GameObject)Resources.Load("Quad"); Quaternion rote = Quaternion.Euler(0.0f, 45.0f, 90.0f); GameObject instance = (GameObject)Instantiate(obj, new Vector3(5.0f, 5.0f, 5.0f), Quaternion.identity); var rend = instance.GetComponent<Renderer>(); rend.material.mainTexture = Resources.Load(str) as Texture; getfish.processedFiles[getfish.processedFiles.Length - 1] = str; Console.WriteLine(getfish.processedFiles[getfish.processedFiles.Length - 1]); //次回の配列操作処理に備えて配列のサイズを1つ大きくしておく Array.Resize(ref processedFiles, processedFiles.Length + 1); Console.WriteLine("processedFiles[]配列の数" + processedFiles.Length); for (int count = 0; count < processedFiles.Length; count++) { Console.WriteLine("processedFiles[]配列リスト" + processedFiles[count]); } } } } ースコード
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
まだ回答がついていません
会員登録して回答してみよう