统一应该首先编写序列化字段变量或公共变量

发布于 2025-02-08 05:36:52 字数 156 浏览 0 评论 0原文

我想知道是否应该按班级顺序编写序列化文件,让我在编辑器中编辑它们,或者公共变量(甚至可以非序列化),但也可以在编辑器中进行编辑。

我用这种方式来做:

-Public vars - 序列化vars - 私人vars - 公共方法 _私人方法

是对吗?

I was wondering if in the order of a class should I write first the Serializedfileds that let me edit them in the editor, or the public variables (that even can be nonSerialized) but can be edited in the editor too.

I use to do it in this way:

-Public Vars
-Serialized vars
-Private Vars
-Public Methods
_Private Methods

It's that right?

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

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

发布评论

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

评论(2

洋洋洒洒 2025-02-15 05:36:52

从功能的角度来看,这并不重要。您可以根据需要订购它们,它仍然可以正常工作。

但是,有大多数开发人员遵守的编码准则。
乔纳森·赖特(Jonathan Wright)回答了一个类似的问题他还链接了 c#编码指南他引用了:您将从:

您将按下以下订购:

  • fields
  • 构造仪
  • [...]属性[...]
  • 属性
  • [...]
  • 这些组中每个组中的方法

都按访问顺序:(SA1202)

  • 公共
  • 内部
  • 受保护的内部
  • 受保护的
  • 私人,

因此,尽管没有明确列出具有属性的成员,但我会以相同的方式订购它们,因为[serializeizefield]属性暴露了Unity编辑器的字段,使其可以从外部访问。

From a functional point of view, it doesn't matter. You can order them however you want, it will still work the same.

However, there are coding guidelines most developers adhere to.
Jonathan Wright answered a similar question where he also linked the c# coding guidelines he cited from:

You would order them as follows:

  • Fields
  • Constructors
  • [...]
  • Properties
  • [...]
  • Methods

Within each of these groups order by access: (SA1202)

  • public
  • internal
  • protected internal
  • protected
  • private

So while members with attributes like [SerializeField] are not explicitly listed, I would order them the same way you do, since the [SerializeField] attribute exposes the field to the Unity Editor and makes them accessible from outside.

我不吻晚风 2025-02-15 05:36:52

只要您保持一致并且具有您遵循的某种结构,您会选择哪个顺序都没关系

It does not matter which order you choose, so long as you are consistent and have some sort of structure that you follow

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