diff --git a/QSB/Animation/NPC/CharacterAnimManager.cs b/QSB/Animation/NPC/CharacterAnimManager.cs index c690fbdd..830469f3 100644 --- a/QSB/Animation/NPC/CharacterAnimManager.cs +++ b/QSB/Animation/NPC/CharacterAnimManager.cs @@ -16,7 +16,7 @@ namespace QSB.Animation.NPC //MOVE : this is the wrong place to put this... move it to Conversations? QSBWorldSync.OldDialogueTrees.Clear(); - QSBWorldSync.OldDialogueTrees = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldDialogueTrees = QSBWorldSync.GetUnityObjects().ToList(); } } } diff --git a/QSB/DeathSync/RespawnOnDeath.cs b/QSB/DeathSync/RespawnOnDeath.cs index df5bc325..6f1c917f 100644 --- a/QSB/DeathSync/RespawnOnDeath.cs +++ b/QSB/DeathSync/RespawnOnDeath.cs @@ -3,6 +3,7 @@ using OWML.Utils; using QSB.Events; using QSB.Player; using QSB.Player.TransformSync; +using QSB.WorldSync; using QSB.Utility; using System.Linq; using UnityEngine; @@ -75,7 +76,7 @@ namespace QSB.DeathSync } else { - var allAstroobjects = Resources.FindObjectsOfTypeAll().Where(x => x.GetAstroObjectName() != AstroObject.Name.None && x.GetAstroObjectType() != AstroObject.Type.Satellite); + var allAstroobjects = QSBWorldSync.GetUnityObjects().Where(x => x.GetAstroObjectName() != AstroObject.Name.None && x.GetAstroObjectType() != AstroObject.Type.Satellite); var ordered = allAstroobjects.OrderBy(x => Vector3.SqrMagnitude(x.transform.position)); DeathClosestAstroObject = ordered.First().transform; } @@ -138,4 +139,4 @@ namespace QSB.DeathSync && spawnPoint.IsShipSpawn() == false); } } -} \ No newline at end of file +} diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs index b7151e23..dc1efccf 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteor.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteor.cs @@ -4,30 +4,14 @@ namespace QSB.MeteorSync.WorldObjects { public class QSBMeteor : WorldObject { - private bool _initialized; - public override void Init(MeteorController attachedObject, int id) { ObjectId = id; AttachedObject = attachedObject; - - // remove WorldObject if prefab - if (AttachedObject.gameObject.scene.name == null) - { - QSBWorldSync.RemoveWorldObject(this); - return; - } - - _initialized = true; } public override void OnRemoval() { - if (!_initialized) - { - return; - } - MeteorManager.MeteorsReady = false; } diff --git a/QSB/OrbSync/OrbManager.cs b/QSB/OrbSync/OrbManager.cs index 50c842fb..e04584fc 100644 --- a/QSB/OrbSync/OrbManager.cs +++ b/QSB/OrbSync/OrbManager.cs @@ -25,7 +25,7 @@ namespace QSB.OrbSync { QSBWorldSync.OldOrbList.Clear(); NomaiOrbTransformSync.OrbTransformSyncs.Clear(); - QSBWorldSync.OldOrbList = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldOrbList = QSBWorldSync.GetUnityObjects().ToList(); if (QSBCore.IsHost) { _orbs.ForEach(x => QNetworkServer.Destroy(x)); @@ -41,4 +41,4 @@ namespace QSB.OrbSync DebugLog.DebugWrite($"Finished orb build with {QSBWorldSync.OldOrbList.Count} orbs.", MessageType.Success); } } -} \ No newline at end of file +} diff --git a/QSB/Player/TransformSync/PlayerTransformSync.cs b/QSB/Player/TransformSync/PlayerTransformSync.cs index 8d117c4e..6dbd20dc 100644 --- a/QSB/Player/TransformSync/PlayerTransformSync.cs +++ b/QSB/Player/TransformSync/PlayerTransformSync.cs @@ -40,7 +40,7 @@ namespace QSB.Player.TransformSync protected Quaternion _roastingRotationVelocity; private Transform GetStickPivot() - => Resources.FindObjectsOfTypeAll().First().transform.Find("Stick_Root/Stick_Pivot"); + => QSBWorldSync.GetUnityObjects().First().transform.Find("Stick_Root/Stick_Pivot"); public override void OnStartLocalPlayer() => LocalInstance = this; @@ -275,4 +275,4 @@ namespace QSB.Player.TransformSync public override bool UseInterpolation => true; } -} \ No newline at end of file +} diff --git a/QSB/PoolSync/PoolManager.cs b/QSB/PoolSync/PoolManager.cs index d5b93fe5..25c9f4de 100644 --- a/QSB/PoolSync/PoolManager.cs +++ b/QSB/PoolSync/PoolManager.cs @@ -7,17 +7,17 @@ namespace QSB.PoolSync { protected override void RebuildWorldObjects(OWScene scene) { - foreach (var streaming in Resources.FindObjectsOfTypeAll()) + foreach (var streaming in QSBWorldSync.GetUnityObjects()) { streaming.gameObject.AddComponent(); } - foreach (var camera in Resources.FindObjectsOfTypeAll()) + foreach (var camera in QSBWorldSync.GetUnityObjects()) { camera.gameObject.AddComponent(); } - foreach (var platform in Resources.FindObjectsOfTypeAll()) + foreach (var platform in QSBWorldSync.GetUnityObjects()) { platform.gameObject.AddComponent(); } diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 4438416a..a76910d3 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -153,7 +153,7 @@ namespace QSB DebugLog.DebugWrite("OnStartServer", MessageType.Info); if (QSBWorldSync.OldDialogueTrees.Count == 0 && QSBSceneManager.IsInUniverse) { - QSBWorldSync.OldDialogueTrees = Resources.FindObjectsOfTypeAll().ToList(); + QSBWorldSync.OldDialogueTrees = QSBWorldSync.GetUnityObjects().ToList(); } } @@ -283,17 +283,17 @@ namespace QSB { QSBWorldSync.RemoveWorldObjects(); QSBWorldSync.RemoveWorldObjects(); - foreach (var platform in Resources.FindObjectsOfTypeAll()) + foreach (var platform in QSBWorldSync.GetUnityObjects()) { Destroy(platform); } - foreach (var camera in Resources.FindObjectsOfTypeAll()) + foreach (var camera in QSBWorldSync.GetUnityObjects()) { Destroy(camera); } - foreach (var streaming in Resources.FindObjectsOfTypeAll()) + foreach (var streaming in QSBWorldSync.GetUnityObjects()) { Destroy(streaming); } diff --git a/QSB/QuantumSync/QuantumManager.cs b/QSB/QuantumSync/QuantumManager.cs index b8f5fcf4..97aed940 100644 --- a/QSB/QuantumSync/QuantumManager.cs +++ b/QSB/QuantumSync/QuantumManager.cs @@ -42,7 +42,7 @@ namespace QSB.QuantumSync QSBWorldSync.Init(); if (scene == OWScene.SolarSystem) { - Shrine = Resources.FindObjectsOfTypeAll().First(); + Shrine = QSBWorldSync.GetUnityObjects().First(); } } @@ -148,4 +148,4 @@ namespace QSB.QuantumSync return QSBPlayerManager.PlayerList.Where(x => x.EntangledObject == worldObj); } } -} \ No newline at end of file +} diff --git a/QSB/RoastingSync/Events/MarshmallowEventEvent.cs b/QSB/RoastingSync/Events/MarshmallowEventEvent.cs index d9ce46f0..75d78e31 100644 --- a/QSB/RoastingSync/Events/MarshmallowEventEvent.cs +++ b/QSB/RoastingSync/Events/MarshmallowEventEvent.cs @@ -3,6 +3,7 @@ using QSB.Events; using QSB.Messaging; using QSB.Player; using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -66,7 +67,7 @@ namespace QSB.RoastingSync.Events var stick = player.RoastingStick; var stickTip = stick.transform.GetChild(0); - var mallowPrefab = Resources.FindObjectsOfTypeAll().First().GetValue("_mallowBodyPrefab"); + var mallowPrefab = QSBWorldSync.GetUnityObjects().First().GetValue("_mallowBodyPrefab"); var tossedMallow = Object.Instantiate(mallowPrefab, stickTip.position, stickTip.rotation); var rigidbody = tossedMallow.GetComponent(); diff --git a/QSB/SatelliteSync/SatelliteProjectorManager.cs b/QSB/SatelliteSync/SatelliteProjectorManager.cs index dd90d4ad..3affdff9 100644 --- a/QSB/SatelliteSync/SatelliteProjectorManager.cs +++ b/QSB/SatelliteSync/SatelliteProjectorManager.cs @@ -1,4 +1,5 @@ using System.Linq; +using QSB.WorldSync; using UnityEngine; namespace QSB.SatelliteSync @@ -21,7 +22,7 @@ namespace QSB.SatelliteSync { if (newScene == OWScene.SolarSystem) { - Projector = Resources.FindObjectsOfTypeAll().First(); + Projector = QSBWorldSync.GetUnityObjects().First(); Projector._loopingSource.spatialBlend = 1f; Projector._oneShotSource.spatialBlend = 1f; } diff --git a/QSB/SectorSync/WorldObjects/QSBSector.cs b/QSB/SectorSync/WorldObjects/QSBSector.cs index dbd76ccf..63b3ae51 100644 --- a/QSB/SectorSync/WorldObjects/QSBSector.cs +++ b/QSB/SectorSync/WorldObjects/QSBSector.cs @@ -81,7 +81,7 @@ namespace QSB.SectorSync.WorldObjects } else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse) { - var shuttleController = Resources.FindObjectsOfTypeAll().First(); + var shuttleController = QSBWorldSync.GetUnityObjects().First(); if (shuttleController == null) { DebugLog.ToConsole($"Warning - Expected to find a EyeShuttleController for {AttachedObject.name}!", MessageType.Warning); @@ -98,4 +98,4 @@ namespace QSB.SectorSync.WorldObjects return true; } } -} \ No newline at end of file +} diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index d2b55251..9d008d31 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -61,9 +61,9 @@ namespace QSB.ShipSync } HatchInteractZone = HatchController.GetComponent(); - ShipTractorBeam = Resources.FindObjectsOfTypeAll().First(); - CockpitController = Resources.FindObjectsOfTypeAll().First(); - ShipElectricalComponent = Resources.FindObjectsOfTypeAll().First(); + ShipTractorBeam = QSBWorldSync.GetUnityObjects().First(); + CockpitController = QSBWorldSync.GetUnityObjects().First(); + ShipElectricalComponent = QSBWorldSync.GetUnityObjects().First(); var sphereShape = HatchController.GetComponent(); sphereShape.radius = 2.5f; diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs index 3f67544d..b991ea2f 100644 --- a/QSB/Syncs/SyncBase.cs +++ b/QSB/Syncs/SyncBase.cs @@ -28,7 +28,7 @@ namespace QSB.Syncs if (wantedSync == default) { DebugLog.ToConsole($"Error - _storedTransformSyncs does not contain type:{typeof(T)} under player {player.PlayerId}. Attempting to find manually...", MessageType.Error); - var allSyncs = Resources.FindObjectsOfTypeAll(); + var allSyncs = QSBWorldSync.GetUnityObjects(); wantedSync = allSyncs.First(x => x.Player == player); if (wantedSync == default) { @@ -100,7 +100,7 @@ namespace QSB.Syncs public virtual void Start() { - var lowestBound = Resources.FindObjectsOfTypeAll() + var lowestBound = QSBWorldSync.GetUnityObjects() .Where(x => x.NetId.Value <= NetId.Value).OrderBy(x => x.NetId.Value).Last(); NetIdentity.SetRootIdentity(lowestBound.NetIdentity); diff --git a/QSB/TimeSync/TimeSyncUI.cs b/QSB/TimeSync/TimeSyncUI.cs index ba0d0ac2..75e6981e 100644 --- a/QSB/TimeSync/TimeSyncUI.cs +++ b/QSB/TimeSync/TimeSyncUI.cs @@ -1,6 +1,8 @@ using OWML.Utils; using QSB.Utility; +using QSB.WorldSync; using System; +using System.Linq; using UnityEngine; using UnityEngine.UI; @@ -30,7 +32,7 @@ namespace QSB.TimeSync private void OnUniverseSceneLoad(OWScene oldScene, OWScene newScene) { _isSetUp = true; - var obj = Resources.FindObjectsOfTypeAll()[0]; + var obj = QSBWorldSync.GetUnityObjects().First(); _canvas = obj.GetValue("_canvas"); _text = obj.GetValue("_text"); _canvas.enabled = false; @@ -126,4 +128,4 @@ namespace QSB.TimeSync _text.text = text; } } -} \ No newline at end of file +} diff --git a/QSB/Tools/ProbeTool/QSBProbeEffects.cs b/QSB/Tools/ProbeTool/QSBProbeEffects.cs index 2992a17a..2d549084 100644 --- a/QSB/Tools/ProbeTool/QSBProbeEffects.cs +++ b/QSB/Tools/ProbeTool/QSBProbeEffects.cs @@ -1,4 +1,5 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -14,7 +15,7 @@ namespace QSB.Tools.ProbeTool private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/Tools/ProbeTool/QSBProbeLantern.cs b/QSB/Tools/ProbeTool/QSBProbeLantern.cs index ec94ff2b..a76275a6 100644 --- a/QSB/Tools/ProbeTool/QSBProbeLantern.cs +++ b/QSB/Tools/ProbeTool/QSBProbeLantern.cs @@ -1,4 +1,5 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -22,7 +23,7 @@ namespace QSB.Tools.ProbeTool private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs b/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs index 4e9a17cc..013b74fd 100644 --- a/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs +++ b/QSB/Tools/ProbeTool/QSBProbeSpotlight.cs @@ -1,4 +1,5 @@ using QSB.Utility; +using QSB.WorldSync; using System.Linq; using UnityEngine; @@ -16,7 +17,7 @@ namespace QSB.Tools.ProbeTool private void Awake() { - _probe = Resources.FindObjectsOfTypeAll().First(x => gameObject.transform.IsChildOf(x.transform)); + _probe = QSBWorldSync.GetUnityObjects().First(x => gameObject.transform.IsChildOf(x.transform)); if (_probe == null) { DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error); diff --git a/QSB/WorldSync/QSBWorldSync.cs b/QSB/WorldSync/QSBWorldSync.cs index 5a38ec87..fc4ffbbf 100644 --- a/QSB/WorldSync/QSBWorldSync.cs +++ b/QSB/WorldSync/QSBWorldSync.cs @@ -152,34 +152,17 @@ namespace QSB.WorldSync WorldObjects.RemoveAll(x => x is TWorldObject); } - public static void RemoveWorldObject(TWorldObject item) - where TWorldObject : IWorldObject - { + public static IEnumerable GetUnityObjects() + where TUnityObject : MonoBehaviour + => Resources.FindObjectsOfTypeAll() + .Where(x => x.gameObject.scene.name != null); - if (item == null) - { - DebugLog.ToConsole($"Error - Trying to remove a null WorldObject of type {typeof(TWorldObject).Name}.", MessageType.Error); - return; - } - - try - { - WorldObjects.Remove(item); - WorldObjectsToUnityObjects.Remove(item.ReturnObject()); - item.OnRemoval(); - } - catch (Exception e) - { - DebugLog.ToConsole($"Error - Exception in OnRemoval() for {item.GetType()}. Message : {e.Message}, Stack trace : {e.StackTrace}", MessageType.Error); - } - } - - public static List Init() + public static void Init() where TWorldObject : WorldObject where TUnityObject : MonoBehaviour { RemoveWorldObjects(); - var list = Resources.FindObjectsOfTypeAll().ToList(); + var list = GetUnityObjects().ToList(); //DebugLog.DebugWrite($"{typeof(TWorldObject).Name} init : {list.Count} instances.", MessageType.Info); for (var id = 0; id < list.Count; id++) { @@ -187,8 +170,6 @@ namespace QSB.WorldSync obj.Init(list[id], id); WorldObjectsToUnityObjects.Add(list[id], obj); } - - return list; } private static TWorldObject CreateWorldObject()