Unity-RIder开发常用缩写

Unity 开发最常用

缩写用途展开结果
logDebug.LogUnityEngine.Debug.Log(...);
logvar打印变量名和值Debug.Log("var = " + var);
logwarnWarningDebug.LogWarning(...);
logerrErrorDebug.LogError(...);
logexExceptionDebug.LogException(...);
bsampleProfiler BeginSampleProfiler.BeginSample("...");
esampleProfiler EndSampleProfiler.EndSample();
sfield[SerializeField] 字段[SerializeField] private Type name;
spropSerializeField + Property序列化字段 + 属性
reqcomp[RequireComponent][RequireComponent(typeof(...))]
menuitem[MenuItem]Unity Editor 菜单项
assetmenu[CreateAssetMenu]ScriptableObject 创建菜单
corCoroutineIEnumerator Xxx() { ... }

这些是我认为 Unity 程序员最应该优先记住的一组。官方文档中的 Unity 模板包括 log、logvar、logwarn、logerr、logex、sfield、sprop、reqcomp、menuitem、assetmenu、cor 等。

C# 高频模板

缩写用途
foreachforeach 循环
for普通 for 循环
forr反向 for 循环
itar遍历数组
ritar反向遍历数组
itli遍历 IList<T>
ifif
elseelse
switchswitch
whilewhile
dodo...while
trytry/catch
tryftry/finally
locklock
usingusing
prop自动属性
propgget; private set; 属性
ctor构造函数
classclass
structstruct
interfaceinterface
enumenum
namespacenamespace
thrthrow new
sfc安全类型转换 as + null check

这些都是 Rider 官方预置的 C# 模板。

还有几个比较实用的

缩写用途
nguid生成 GUID
ctx当前代码上下文
ear创建空数组
#region创建 region
#if创建条件编译
asrtDebug.Assert
asrtnAssert 非 null
outConsole.WriteLine
outv打印变量
psrpublic static readonly
pcipublic const int
pcspublic const string

nguid、ctx 这类属于不一定天天用,但记住后很方便的模板。

DOTS / ECS 专用

如果你做 Unity DOTS,这几个也值得记:

缩写用途
baker生成 Baker<T>
componentdataIComponentData
jobentityIJobEntity

例如 componentdata 会直接生成:

public struct MyComponent : Unity.Entities.IComponentData
{
}

baker 则会生成对应的 Baker<T> 基础结构。


我建议你实际只背这一套

如果你的目标是提高 Unity Rider 编码速度,而不是把官方列表全部背下来,我会按下面的优先级:

第一梯队——每天都可能用

log
logvar
logwarn
logerr
sfield
cor
foreach
for
if
prop
ctor
try

第二梯队——Unity 项目中很有价值

sprop
reqcomp
menuitem
assetmenu
bsample
esample
forr
switch
lock
nguid

第三梯队——特定场景

logex
itar
ritar
itli
sfc
propg
#region
#if
baker
componentdata
jobentity

尤其是你做 Unity 的话,我会重点形成这样的肌肉记忆:

sfield   → [SerializeField]
sprop    → SerializeField + Property
cor      → Coroutine
log      → Debug.Log
logvar   → Debug.Log("xxx = " + xxx)
logwarn  → Debug.LogWarning
logerr   → Debug.LogError
bsample  → Profiler.BeginSample
esample  → Profiler.EndSample
reqcomp  → RequireComponent
menuitem → MenuItem
assetmenu → CreateAssetMenu

官方文档:Rider — Predefined Live Templates for C#。

上一篇