From 6103b8f81e110a2e36026937eb40ed4dc14a9ee7 Mon Sep 17 00:00:00 2001 From: Misfiy <85962933+Misfiy@users.noreply.github.com> Date: Sat, 20 Dec 2025 23:40:01 +0100 Subject: [PATCH] Use ``field`` keyword --- SecretAPI/Features/PrefabManager.cs | 17 +++++++---------- SecretAPI/Features/PrefabStore.cs | 19 ++++++++----------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/SecretAPI/Features/PrefabManager.cs b/SecretAPI/Features/PrefabManager.cs index 098efa3..a5d3c7a 100644 --- a/SecretAPI/Features/PrefabManager.cs +++ b/SecretAPI/Features/PrefabManager.cs @@ -1,5 +1,6 @@ namespace SecretAPI.Features { + using System; using System.Linq; using Interactables.Interobjects; using MapGeneration; @@ -14,11 +15,6 @@ public static class PrefabManager private const string HczBulkDoorName = "HCZ BulkDoor"; private const string EzDoorName = "EZ BreakableDoor"; - private static BasicDoor? lczDoor; - private static BasicDoor? hczDoor; - private static BasicDoor? hczBulkDoor; - private static BasicDoor? ezDoor; - /// /// Gets the prefab. /// @@ -27,24 +23,25 @@ public static class PrefabManager /// /// Gets the found in . /// - public static BasicDoor LczDoorPrefab => lczDoor ??= GetDoor(LczDoorName); + public static BasicDoor LczDoorPrefab => field ??= GetDoor(LczDoorName); /// /// Gets the found in . /// - public static BasicDoor HczDoorPrefab => hczDoor ??= GetDoor(HczDoorName); + public static BasicDoor HczDoorPrefab => field ??= GetDoor(HczDoorName); /// /// Gets the found in . /// - public static BasicDoor HczBulkDoorPrefab => hczBulkDoor ??= GetDoor(HczBulkDoorName); + public static BasicDoor HczBulkDoorPrefab => field ??= GetDoor(HczBulkDoorName); /// /// Gets the found in . /// - public static BasicDoor EzDoorPrefab => ezDoor ??= GetDoor(EzDoorName); + public static BasicDoor EzDoorPrefab => field ??= GetDoor(EzDoorName); private static BasicDoor GetDoor(string name) - => PrefabStore.AllComponentPrefabs.FirstOrDefault(d => d.name == name)!; + => PrefabStore.AllComponentPrefabs.FirstOrDefault(d => d.name == name) + ?? throw new InvalidOperationException($"[PrefabManager] Failed to get door named {name} | Report this as a bug!"); } } \ No newline at end of file diff --git a/SecretAPI/Features/PrefabStore.cs b/SecretAPI/Features/PrefabStore.cs index 22d6959..3c0b675 100644 --- a/SecretAPI/Features/PrefabStore.cs +++ b/SecretAPI/Features/PrefabStore.cs @@ -15,9 +15,6 @@ public static class PrefabStore where TPrefab : NetworkBehaviour { - private static TPrefab[]? collection; - private static TPrefab? savedPrefab; - /// /// Gets the first prefab found of the specified type. /// @@ -25,13 +22,13 @@ public static TPrefab Prefab { get { - if (savedPrefab) - return savedPrefab; + if (field) + return field; if (typeof(TPrefab) == typeof(ReferenceHub)) - return savedPrefab = NetworkManager.singleton.playerPrefab.GetComponent(); + return field = NetworkManager.singleton.playerPrefab.GetComponent(); - return savedPrefab = AllComponentPrefabs.FirstOrDefault()!; + return field = AllComponentPrefabs.FirstOrDefault()!; } } @@ -43,8 +40,8 @@ public static TPrefab[] AllComponentPrefabs { get { - if (collection != null) - return collection; + if (field != null) + return field; List allPrefabs = ListPool.Shared.Rent(); @@ -54,10 +51,10 @@ public static TPrefab[] AllComponentPrefabs allPrefabs.Add(prefab); } - collection = allPrefabs.ToArray(); + field = allPrefabs.ToArray(); ListPool.Shared.Return(allPrefabs); - return collection; + return field; } } }