프리 패브를로드하기 위해 파일 이름이있는 파일이 있습니다. File.ReadAllLines (hardPathToFile)로 파일을로드했지만 빌드 할 때 작동하지 않습니다. "Resource"폴더를 사용해야합니다. 그래서 Resource.Load(fileName)
을 사용해 보았지만 목록이나 배열을 가져 오지 않았습니다. 나는 그 다음에 File.ReadAllLines(Resource.Load(fileName, typeOf(TextAsset)) as TextAsset))
을 시도했지만로드 된 리소스가 문자열 파일 경로가 아니기 때문에 작동하지 않습니다.File.ReadAllLines에서 리소스 텍스트 파일을 사용하려면 어떻게해야합니까?
void getList(string filePath)
{
prefabObjects.Clear();
//Read all the lines from the file. File loaded from resources
print((Resources.Load(filePath, typeof(TextAsset)) as TextAsset).text);
var prefabs = File.ReadAllLines((Resources.Load(filePath, typeof(TextAsset)) as TextAsset).text);
print(prefabs);
foreach (var prefab in prefabs)
{
print(prefab);
GameObject newPrefab = Resources.Load(prefab, typeof(GameObject)) as GameObject;
prefabObjects.Add(newPrefab);
}
}
가 어떻게이 작업을 얻을 수 :
여기에 전체 코드는? 이전 파일을 하드 경로를 사용하는 경우
모든 도움 감사합니다, 감사합니다 :)
@Fredrik가, 그래 지금 파일 이름 만입니다. 하드 경로를 사용했을 때부터 그냥 남아 있습니다. – crabcrabcam
나는 문제가 다른 곳에 있다는 것을 안다! – Maakep
@Slai, 나는 그렇게 생각하지 않는다. 그것은 Unity가 아닌 C# 리소스에 관한 것입니다. 적어도 내 질문에는 대답하지 않습니다. – crabcrabcam