我试图弄清楚如何将所有资源文件夹中的所有文件夹作为按钮在iOS中获取。
我使用以下代码在Windows上运行它:
string path = Application.dataPath + "/Resources/Prefabs/Models/";
foreach (string s in Directory.GetDirectories(path))
{
projects.Add(s.Remove(0, path.Length));
}
foreach (string result in projects)
{
buttonResult = Instantiate(buttonProjectPrefab).GetComponent<Button>();
buttonResult.transform.SetParent(GameObject.FindGameObjectWithTag("Level").transform);
buttonResult.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
buttonResult.GetComponent<Button>().onClick.AddListener(delegate { CreateModelButtons(); });
buttonResult.name = result;
buttonResult.GetComponentInChildren<Text>().text = result;
}
所以现在我想弄清楚如何针对iOS执行此操作。
我知道Unity对文件进行编码,所以我用的东西不可能。
我该如何获取资源文件夹中的所有文件夹以在iOS上将它们创建为按钮?
最佳答案
该代码仅在编辑器中有效。因此,我创建了一个解决方法。
我在资源文件夹中创建了一个空的游戏对象。
因此,我不是使用文件夹来获取按钮,而是使用游戏对象来创建按钮。
我以与问题相同的方式使用了代码,但是这次它在编辑器之外起作用