代码命名
Public变量
所有公开的变量请勿使用简写,如请尽量不要使用pos,而是使用position,私有变量无所谓。
字段(Field)
驼峰命名
public class DemoUI : MonoBehaviour {
[LabelText("一些整数")]
[MinValue(0), MaxValue(10)]
public int someIntegers = 2;
[LabelText("标签")]
[Required, SceneObjectsOnly]
public TextMeshProUGUI label;
}属性(Property)
帕斯卡命名
public class DemoUI : MonoBehaviour {
[SerializeField] //序列化,让其显示在Unity Editor里
private int _health = 4;
[SerializeField] //序列化,让其显示在Unity Editor里
private int _maxHealth = 100;
public int Health //外部需要使用HP值应该调用的接口
{
get => _health.Clamp(0, _maxHealth); //在获取该值时,限制在0和最大HP值之间
set => _health = value.Clamp(0, _maxHealth); //设置HP也是,限制_HP在0到最大HP值之间
}
}特性(Attribute)
与通常的类不同,里面的字段或属性请用帕斯卡命名。
函数(Function)
帕斯卡命名法(Pascal Case)
常值(Constant)
全大写+下划线命名
类(Class)
帕斯卡命名。
结构(Struct)
帕斯卡命名。
模板(Template)
模板的类型请以 T 开头,如下面的 TPrefab和TInstance。
接口(Interface)
全部以 I 开头命名,如IEnumerable<T>。
枚举(Enumeration)
全部帕斯卡命名法
事件(Event)
帕斯卡命名
元组(Tuple)
请带上内部每个类型的命名,而不是只有类型,如下面的(int slotIndex, Item item),而不是(int, Item)
委托(Delegate)
帕斯卡命名
如果委托的参数比较多,请勿用Action<>,请用delegate语法并给每个参数标上名字。
最后更新于
这有帮助吗?