Skip to content

Commit 9dacf6f

Browse files
committed
Enforce all Unity analyzers
1 parent 2d98ddc commit 9dacf6f

29 files changed

+129
-84
lines changed

Source/.editorconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,43 @@ dotnet_style_prefer_simplified_boolean_expressions = true:warning
391391
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
392392

393393
# Unity analyzers
394+
dotnet_diagnostic.UNT0001.severity = error
395+
dotnet_diagnostic.UNT0002.severity = error
396+
dotnet_diagnostic.UNT0003.severity = error
397+
dotnet_diagnostic.UNT0004.severity = error
398+
dotnet_diagnostic.UNT0005.severity = error
399+
dotnet_diagnostic.UNT0006.severity = error
400+
dotnet_diagnostic.UNT0007.severity = error
401+
dotnet_diagnostic.UNT0008.severity = error
402+
dotnet_diagnostic.UNT0009.severity = error
403+
dotnet_diagnostic.UNT0010.severity = error
404+
dotnet_diagnostic.UNT0011.severity = error
405+
dotnet_diagnostic.UNT0012.severity = error
406+
dotnet_diagnostic.UNT0013.severity = error
407+
dotnet_diagnostic.UNT0014.severity = error
408+
dotnet_diagnostic.UNT0015.severity = error
409+
dotnet_diagnostic.UNT0016.severity = error
410+
dotnet_diagnostic.UNT0017.severity = error
411+
dotnet_diagnostic.UNT0018.severity = error
412+
dotnet_diagnostic.UNT0019.severity = error
413+
dotnet_diagnostic.UNT0020.severity = error
414+
dotnet_diagnostic.UNT0021.severity = error
415+
dotnet_diagnostic.UNT0022.severity = error
416+
dotnet_diagnostic.UNT0023.severity = error
417+
dotnet_diagnostic.UNT0024.severity = error
418+
dotnet_diagnostic.UNT0025.severity = error
419+
dotnet_diagnostic.UNT0026.severity = error
420+
dotnet_diagnostic.UNT0027.severity = error
421+
dotnet_diagnostic.UNT0028.severity = error
422+
dotnet_diagnostic.UNT0029.severity = error
394423
dotnet_diagnostic.UNT0030.severity = error
424+
dotnet_diagnostic.UNT0031.severity = error
425+
dotnet_diagnostic.UNT0032.severity = error
426+
dotnet_diagnostic.UNT0033.severity = error
427+
dotnet_diagnostic.UNT0034.severity = error
428+
dotnet_diagnostic.UNT0035.severity = error
429+
dotnet_diagnostic.UNT0036.severity = error
430+
dotnet_diagnostic.UNT0037.severity = error
395431

396432
# TODO: re-enable this
397433
dotnet_diagnostic.CS1591.severity = suggestion

Source/CustomAvatar-Editor/CustomAvatar-Editor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<Compile Include="..\CustomAvatar\Logging\UnityDebugLogger.cs" Link="Logging\UnityDebugLogger.cs" />
6767
<Compile Include="..\CustomAvatar\Scripts\PoseManager.cs" Link="Scripts\PoseManager.cs" />
6868
<Compile Include="..\CustomAvatar\Utilities\IKHelper.cs" Link="Utilities\IKHelper.cs" />
69+
<Compile Include="..\CustomAvatar\Utilities\UnityUtilities.cs" Link="Utilities\UnityUtilities.cs" />
6970
<Compile Include="..\CustomAvatar\Scripts\VRIKManager.cs" Link="Scripts\VRIKManager.cs" />
7071
</ItemGroup>
7172
<ItemGroup>

Source/CustomAvatar-Editor/Editor/AvatarExporterWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public static void ShowWindow()
3232

3333
#region Behaviour Lifecycle
3434

35-
internal void OnFocus()
35+
protected void OnFocus()
3636
{
3737
_avatars = FindObjectsOfType<AvatarDescriptor>();
3838
Repaint();
3939
}
4040

41-
internal void OnGUI()
41+
protected void OnGUI()
4242
{
4343
var titleLabelStyle = new GUIStyle(EditorStyles.largeLabel)
4444
{

Source/CustomAvatar/Avatar/AvatarFingerTracking.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ private void Inject(IAvatarInput input)
3535
_input = input;
3636
}
3737

38-
private void Start()
38+
protected void Start()
3939
{
4040
_poseManager = GetComponentInChildren<PoseManager>();
4141
}
4242

43-
private void LateUpdate()
43+
protected void LateUpdate()
4444
{
4545
ApplyFingerTracking();
4646
}

Source/CustomAvatar/Avatar/AvatarIK.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public bool isLocomotionEnabled
6161

6262
#region Behaviour Lifecycle
6363

64-
private void Awake()
64+
protected void Awake()
6565
{
6666
foreach (BeatSaberDynamicBone::DynamicBone dynamicBone in GetComponentsInChildren<BeatSaberDynamicBone::DynamicBone>())
6767
{
@@ -76,7 +76,7 @@ private void Awake()
7676
_twistRelaxersV2 = GetComponentsInChildren<TwistRelaxerV2>();
7777
}
7878

79-
private void OnEnable()
79+
protected void OnEnable()
8080
{
8181
if (_vrik != null)
8282
{
@@ -99,7 +99,7 @@ private void Construct(IAvatarInput input, SpawnedAvatar avatar, ILoggerFactory
9999
_ikHelper = ikHelper;
100100
}
101101

102-
private void Start()
102+
protected void Start()
103103
{
104104
vrikManager = GetComponentInChildren<VRIKManager>();
105105
_defaultRootPose = new Pose(vrikManager.references_root.localPosition, vrikManager.references_root.localRotation);
@@ -148,11 +148,10 @@ private void Start()
148148
}
149149
}
150150

151-
private void OnDisable()
151+
protected void OnDisable()
152152
{
153153
_vrik.enabled = false;
154-
_vrik.references.root.localPosition = _defaultRootPose.position;
155-
_vrik.references.root.localRotation = _defaultRootPose.rotation;
154+
_vrik.references.root.SetLocalPositionAndRotation(_defaultRootPose.position, _defaultRootPose.rotation);
156155
_vrik.solver.FixTransforms();
157156

158157
foreach (TwistRelaxerV2 twistRelaxer in _twistRelaxersV2)
@@ -166,7 +165,7 @@ private void OnDisable()
166165
}
167166
}
168167

169-
private void OnDestroy()
168+
protected void OnDestroy()
170169
{
171170
IKSolver solver = _vrik.GetIKSolver();
172171
solver.OnPostUpdate -= OnPostUpdate;
@@ -189,7 +188,7 @@ private void ApplyPlatformMotion()
189188
_previousParentPose = new Pose(parent.position, parent.rotation);
190189
}
191190

192-
private void Update()
191+
protected void Update()
193192
{
194193
foreach (BeatSaberDynamicBone::DynamicBone dynamicBone in _dynamicBones)
195194
{

Source/CustomAvatar/Avatar/AvatarPrefab.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ public class AvatarPrefab : MonoBehaviour
102102
internal void Construct(string fullPath, ILoggerFactory loggerFactory, DiContainer container)
103103
{
104104
this.fullPath = fullPath ?? throw new ArgumentNullException(nameof(fullPath));
105-
descriptor = GetComponent<AvatarDescriptor>() ?? throw new AvatarLoadException($"Avatar at '{fullPath}' does not have an AvatarDescriptor");
105+
descriptor = GetComponent<AvatarDescriptor>();
106106

107+
if (descriptor == null)
108+
{
109+
throw new AvatarLoadException($"Avatar at '{fullPath}' does not have an AvatarDescriptor");
110+
}
111+
112+
// TODO: don't do all of this in Construct
107113
fileName = Path.GetFileName(fullPath);
108114

109115
_logger = loggerFactory.CreateLogger<AvatarPrefab>(descriptor.name);
@@ -310,8 +316,8 @@ private void FixTrackingReferences(VRIKManager vrikManager)
310316
FixTrackingReference("Left Hand", leftHand, vrikManager.references_leftHand, vrikManager.solver_leftArm_target);
311317
FixTrackingReference("Right Hand", rightHand, vrikManager.references_rightHand, vrikManager.solver_rightArm_target);
312318
FixTrackingReference("Waist", pelvis, vrikManager.references_pelvis, vrikManager.solver_spine_pelvisTarget);
313-
FixTrackingReference("Left Foot", leftLeg, vrikManager.references_leftToes ?? vrikManager.references_leftFoot, vrikManager.solver_leftLeg_target);
314-
FixTrackingReference("Right Foot", rightLeg, vrikManager.references_rightToes ?? vrikManager.references_rightFoot, vrikManager.solver_rightLeg_target);
319+
FixTrackingReference("Left Foot", leftLeg, UnityUtilities.FirstNonNullUnityObject(vrikManager.references_leftToes, vrikManager.references_leftFoot), vrikManager.solver_leftLeg_target);
320+
FixTrackingReference("Right Foot", rightLeg, UnityUtilities.FirstNonNullUnityObject(vrikManager.references_rightToes, vrikManager.references_rightFoot), vrikManager.solver_rightLeg_target);
315321
}
316322

317323
private void FixTrackingReference(string name, Transform tracker, Transform reference, Transform target)

Source/CustomAvatar/Avatar/AvatarTransformTracking.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class AvatarTransformTracking : MonoBehaviour
4040

4141
private Vector3 _prevBodyLocalPosition;
4242

43-
private void OnEnable()
43+
protected void OnEnable()
4444
{
4545
if (_avatarInput != null)
4646
{
@@ -65,7 +65,7 @@ private void Construct(SpawnedAvatar spawnedAvatar, IAvatarInput avatarInput)
6565
_avatarInput = avatarInput;
6666
}
6767

68-
private void Start()
68+
protected void Start()
6969
{
7070
if (_avatarInput != null)
7171
{
@@ -82,7 +82,7 @@ private void Start()
8282
UpdateConstraints();
8383
}
8484

85-
private void Update()
85+
protected void Update()
8686
{
8787
if (_spawnedAvatar.body)
8888
{
@@ -102,7 +102,7 @@ private void Update()
102102
}
103103
}
104104

105-
private void OnDisable()
105+
protected void OnDisable()
106106
{
107107
if (_head != null) _head.constraintActive = false;
108108
if (_leftHand != null) _leftHand.constraintActive = false;

Source/CustomAvatar/Avatar/SpawnedAvatar.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void SetFirstPersonVisibility(FirstPersonVisibility visibility)
109109
#region Behaviour Lifecycle
110110
#pragma warning disable IDE0051
111111

112-
private void Awake()
112+
protected void Awake()
113113
{
114114
_initialLocalPosition = transform.localPosition;
115115
_initialLocalScale = transform.localScale;
@@ -141,7 +141,7 @@ private void Construct(ILoggerFactory loggerFactory, AvatarPrefab avatarPrefab,
141141
_logger = loggerFactory.CreateLogger<SpawnedAvatar>(prefab.descriptor.name);
142142
}
143143

144-
private void Start()
144+
protected void Start()
145145
{
146146
name = $"SpawnedAvatar({prefab.descriptor.name})";
147147

@@ -151,7 +151,7 @@ private void Start()
151151
}
152152
}
153153

154-
private void OnDestroy()
154+
protected void OnDestroy()
155155
{
156156
Destroy(gameObject);
157157
}

Source/CustomAvatar/Player/EnvironmentObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class EnvironmentObject : MonoBehaviour
4242

4343
protected BeatSaberUtilities beatSaberUtilities { get; private set; }
4444

45-
internal void Awake()
45+
protected void Awake()
4646
{
4747
_originalY = transform.position.y;
4848

@@ -64,7 +64,7 @@ internal void Construct(ILogger<EnvironmentObject> logger, PlayerAvatarManager p
6464
this.beatSaberUtilities = beatSaberUtilities;
6565
}
6666

67-
internal virtual void Start()
67+
protected virtual void Start()
6868
{
6969
playerAvatarManager.avatarChanged += OnAvatarChanged;
7070
playerAvatarManager.avatarScaleChanged += OnAvatarScaleChanged;
@@ -74,7 +74,7 @@ internal virtual void Start()
7474
CreateMirrors();
7575
}
7676

77-
internal virtual void OnDestroy()
77+
protected virtual void OnDestroy()
7878
{
7979
playerAvatarManager.avatarChanged -= OnAvatarChanged;
8080
playerAvatarManager.avatarScaleChanged -= OnAvatarScaleChanged;

Source/CustomAvatar/Player/MenuEnvironmentEventManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void Init(PlayerAvatarManager playerAvatarManager, GameScenesManager game
8383
}
8484
}
8585

86-
private void OnEnable()
86+
protected void OnEnable()
8787
{
8888
StartCoroutine(TriggerEventCoroutine());
8989
}

0 commit comments

Comments
 (0)