官术网_书友最值得收藏!

XML comments

Note that previously we did not use a Tooltip attribute on the private rb variable. Since it's not being displayed in the editor, it's not really needed. However, there is a way that we can enhance that as well, making use of XML comments. XML comments have a couple of nice things that we get when using them instead of traditional comments, which we were using previously. When using the variables/functions instead of code in Visual Studio, we will now see a comment about it. This will help other coders on your team have additional information and details to ensure that they are using your code correctly.

XML comments look something like this:

/// <summary> 
/// A reference to the Rigidbody component
/// </summary>
private Rigidbody rb;

It may appear to be a lot more writing is needed to use this format, but I did not actually type the entire thing out. XML comments are a fairly standard C# feature, so if you are using MonoDevelop or Visual Studio and type ///, it will automatically generate the summary blocks for you (and the param tags needed, if there are parameters needed for something like a function).

Now, why would we want to do this? Well, now, if you select the variable in Intellisense, it will display the following information to us:

This is a great help for when other people are trying to use your code and it is how Unity's staff write their code. We can also extend this to functions and classes to ensure that our code is more self-documented.

Unfortunately, XML comments do not show up in the Inspector, and the Tooltip attribute doesn't show info in the editor. With that in mind, I used Tooltips for public instructions and/or things that will show up in the Inspector window, and XML comments for everything else.

If you're interested in looking into XML comments more, feel free to check out: https://msdn.microsoft.com/en-us/library/b2s063f7.aspx.

主站蜘蛛池模板: 涿鹿县| 邵阳县| 枝江市| 尉氏县| 兴山县| 石林| 平舆县| 宜兰县| 咸丰县| 普定县| 克什克腾旗| 淳化县| 青龙| 上饶县| 同德县| 和林格尔县| 江源县| 五大连池市| 石景山区| 秦皇岛市| 翼城县| 定南县| 固始县| 县级市| 炉霍县| 潜江市| 德庆县| 界首市| 普陀区| 漠河县| 辽宁省| 西乡县| 正阳县| 佳木斯市| 当阳市| 静乐县| 九寨沟县| 绥芬河市| 广南县| 林口县| 广州市|