为什么不从检查员出现新创建的实例?

发布于 2025-02-10 19:41:19 字数 459 浏览 0 评论 0原文

用例:创建卡并将其添加到卡列表中。

我正在创建卡的新实例,并将其添加到卡列表中。

[SerializeField] private List<Card> _deckCards = new List<Card>();


public void LoadDeck()
{
Card newCard = new Card();
newCard.UpdateCardState(CardState.DECK);
_deckCards.Add(newCard);
}

但是,甲板卡列表将添加的卡显示为Unity Inspector中的无。

indepcted 屏幕截图

是否有这样的原因?谢谢!

Use case: Creating a card and adding it on a list of cards.

I'm creating a new instance of a Card and adding it on a list of cards.

[SerializeField] private List<Card> _deckCards = new List<Card>();


public void LoadDeck()
{
Card newCard = new Card();
newCard.UpdateCardState(CardState.DECK);
_deckCards.Add(newCard);
}

However the deckCards list is displaying the added cards as none from the Unity inspector.

Screenshot of the insepcted

Is there a reason why this happens? thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2025-02-17 19:41:19

现在解决了。事实证明,卡是从Monobehavior继承的类。
为了解决这个问题,我必须删除单obehavior,然后从卡类的顶部添加[System.Serializable]。

Solved now. Turns out, Card is a class that inherits from Monobehavior.
To fix this, I had to remove Monobehavior and add [System.Serializable] from the top of the Card class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文