我试图弄清楚如何将资源文件夹中的所有文件夹作为 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 上的按钮?
最佳答案
该代码仅在编辑器中有效。所以我创建了一个解决方法。 我在资源文件夹中创建了一个空的游戏对象。 因此,我没有使用文件夹来获取按钮,而是使用游戏对象来创建按钮。
我使用代码的方式与我的问题相同,但这次它在编辑器之外工作
关于c# - 从资源文件夹 iOS Unity 中的文件夹创建按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54653338/