[英]Unity: How do I pass as a parameter, a nested list initialized in its own class, to a method?
我會盡量切中要點。 我創建了一個嵌套的 GameObjects 列表:
[System.Serializable] public class TabSlots { public List<GameObject> tabslots; } [System.Serializable] public class Tablature { public List<TabSlots> tablature; } public Tablature allSlots = new Tablature();
這工作得很好,我能夠將適當的 GameObject(s) 放入檢查器中它們各自的插槽中,其層次結構如下所示:
AllSlots(這是嵌套列表的根) Tablature(12 個元素) Tabslots(3 個元素)
我能夠成功訪問 Tabslots 中每個游戲對象的組件。 在下面的示例中,我將 deck[0] 中的一個 object 移動到 allSlots.tablature[0].tabslots[0] 的 position。 (甲板只是游戲對象的一級列表)
deck[0].transform.position = Vector2.MoveTowards(deck[0].transform.position, allSlots.tablature[0].tabslots[0].transform.position, 70f * Time.deltaTime);
我的問題:如何發送由以下內容創建的嵌套列表:public Tablature allSlots = new Tablature(); 到 IEnumerator 方法?
我已經嘗試了所有我能想到的調用組合(???代表未發現的代碼)。
StartCoroutine(MyTest(deck, ??? ));
並且還用IEnumertor方法中的參數列表嘗試了我能想到的一切(???代表未發現的代碼)。
IEnumerator MyTest((List<GameObject> list1, ??? ))
誰能幫我填一下??? 空白?
謝謝轉發。
我已經嘗試了所有我能想到的參考組合。
您可以只傳遞您創建的類型:
...
StartCoroutine(MyTest(deck, allSlots));
}
private IEnumerator MyTest(List<GameObject> deck, Tablature tablature)
{
return null;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.