【问题标题】:Create buttons from folders in the resource folder iOS Unity从资源文件夹 iOS Unity 中的文件夹创建按钮
【发布时间】:2019-02-12 15:20:21
【问题描述】:

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


    【解决方案1】:

    该代码仅在编辑器中有效。因此,我创建了一个解决方法。 我在资源文件夹中创建了一个空的游戏对象。 所以我没有使用文件夹来获取按钮,而是使用游戏对象来创建按钮。

    我使用代码的方式与我的问题相同,但这次它在编辑器之外工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多