c# - 从资源文件夹 iOS Unity 中的文件夹创建按钮

标签 c# ios unity-game-engine directory

我试图弄清楚如何将资源文件夹中的所有文件夹作为 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/

相关文章:

c# - 检测符号链接(symbolic link)、连接点、挂载点和硬链接(hard link)

ios - 如何更改导航栏按钮之间的距离

android - 如何与Unity一起存储简单的数据?

c# - 通过 SharePoint Web 部件访问列表数据

c# - 构建一个显示最近更新的网站的 C# 应用程序

ios - 如何使用 XCode 的查找工具查找不是 IBOUtlet 的弱属性?

unity-game-engine - 在unity 5.0.0p2中向刚体添加物理的代码是什么?

ios - 适用于 iOS 的统一构建 : Not able to change Bundle Identifier

c# - 如何在 .Net Core 中使用客户端 SSL 证书

ios - Swift - 如何在 MVC 中正确构建按钮?