This is ok:
if (!something)
{
return;
}
This is not:
if (!something)
return;
This is ok:
if (!boolean)
{
// do something
}
This is not:
if (boolean == false)
{
// do something
}
Use for
or foreach
loops rather than LINQ statements where applicable, especially in Update()
or methods that run often.
They do not play nice with Unity.GameObject
.
This is ok:
if (myGameObject != null)
{
myGameObject.Shoot();
}
if (myGameObject == null)
{
myGameObject = MyGameObject.Create();
}
return myGameObject;
This is not:
myGameObject?.Shoot();
myGameObject ??= MyGameObject.Create();
return myGameObject;
Use Traverse
when getting fields, properties, etc. that are private. If you are modifying/getting several things on the same object
, save a reference to the Traverse
and re-use it.
Traverse playerTraverse = Traverse.Create(this);
IVaultingComponent vaultingComponent = playerTraverse.Field<IVaultingComponent>("_vaultingComponent").Value;
if (vaultingComponent != null)
{
UpdateEvent -= vaultingComponent.DoVaultingTick;
}
playerTraverse.Field("_vaultingComponent").SetValue(null);
playerTraverse.Field("_vaultingComponentDebug").SetValue(null);
playerTraverse.Field("_vaultingParameters").SetValue(null);
playerTraverse.Field("_vaultingGameplayRestrictions").SetValue(null);
playerTraverse.Field("_vaultAudioController").SetValue(null);
playerTraverse.Field("_sprintVaultAudioController").SetValue(null);
playerTraverse.Field("_climbAudioController").SetValue(null);