diff --git a/BoneLib/BoneLib/BoneMenu/DefaultMenu.cs b/BoneLib/BoneLib/BoneMenu/DefaultMenu.cs index 88da62a..9d82796 100644 --- a/BoneLib/BoneLib/BoneMenu/DefaultMenu.cs +++ b/BoneLib/BoneLib/BoneMenu/DefaultMenu.cs @@ -160,8 +160,8 @@ internal static void LoadRandomLevel() int index = Random.RandomRangeInt(0, CommonBarcodes.Maps.All.Count); string barcode = CommonBarcodes.Maps.All[index]; - - SceneStreamer.Load(new(barcode), new Barcode(CommonBarcodes.Maps.LoadDefault)); + + HelperMethods.FadeLoadLevel(barcode); } internal static void ChangeIntoRandomAvatar() diff --git a/BoneLib/BoneLib/CommonBarcodes.cs b/BoneLib/BoneLib/CommonBarcodes.cs index c607261..3bac778 100644 --- a/BoneLib/BoneLib/CommonBarcodes.cs +++ b/BoneLib/BoneLib/CommonBarcodes.cs @@ -431,8 +431,10 @@ public static class Misc public const string DevManipulator = "c1534c5a-c6a8-45d0-aaa2-2c954465764d"; public const string GravityCup = "c1534c5a-87ce-436d-b00c-ef9547726176"; public const string GravityPlate = "c1534c5a-a1c3-437b-85ac-e09547726176"; - public const string PowerPuncher = "c1534c5a-cebf-42cc-be3a-4595506f7765"; + public const string PowerPuncher = " c1534c5a-cebf-42cc-be3a-4595506f7765"; public const string BoxTurret = "SLZ.BONELAB.Content.Spawnable.BoxTurret"; + public const string LoadFade = "c1534c5a-dac0-44a1-b656-6c235646584c"; + public const string LoadFadeFast = "c1534c5a-84f0-4d2b-b4d7-64405646584c"; } } -} \ No newline at end of file +} diff --git a/BoneLib/BoneLib/HelperMethods.cs b/BoneLib/BoneLib/HelperMethods.cs index 4008bec..09f8290 100644 --- a/BoneLib/BoneLib/HelperMethods.cs +++ b/BoneLib/BoneLib/HelperMethods.cs @@ -66,6 +66,101 @@ public static void SpawnCrate(SpawnableCrateReference crateReference, Vector3 po AssetSpawner.Spawn(spawnable, position, rotation, new Il2CppSystem.Nullable(scale), null, ignorePolicy, new Il2CppSystem.Nullable(), spawnAction, despawnAction); } + /// + /// Loads a level from a crate reference + /// + /// The crate reference to load + public static void LoadLevel(LevelCrateReference level) + { + LoadLevel(level.Barcode.ID, CommonBarcodes.Maps.LoadDefault); + } + + /// + /// Loads a level from a barcode + /// + /// The barcode of the level + public static void LoadLevel(string barcode) + { + LoadLevel(barcode, CommonBarcodes.Maps.LoadDefault); + } + + /// + /// Loads a level from a crate reference + /// + /// The crate reference to load + /// The crate reference for the loading scene + public static void LoadLevel(LevelCrateReference level, LevelCrateReference loadLevel) + { + LoadLevel(level.Barcode.ID, loadLevel.Barcode.ID); + } + + /// + /// Loads a level from a barcode + /// + /// The barcode of the level + /// The barcode of the loading scene + public static void LoadLevel(string levelBarcode, string loadLevelBarcode) + { + SceneStreamer.Load(new Barcode(levelBarcode), new Barcode(loadLevelBarcode)); + } + + /// + /// Loads a level from a crate reference with load fade + /// + /// The crate reference to load + /// When true, loads with a faster fade + public static void FadeLoadLevel(LevelCrateReference level, bool fastFade = false) + { + FadeLoadLevel(level.Barcode.ID, CommonBarcodes.Maps.LoadDefault, fastFade); + } + + /// + /// Loads a level from a barcode with load fade + /// + /// The barcode of the level + /// When true, loads with a faster fade + public static void FadeLoadLevel(string barcode, bool fastFade = false) + { + FadeLoadLevel(barcode, CommonBarcodes.Maps.LoadDefault, fastFade); + } + + /// + /// Loads a level from a crate reference with load fade + /// + /// The crate reference to load + /// The crate reference for the loading scene + /// When true, loads with a faster fade + public static void FadeLoadLevel(LevelCrateReference level, LevelCrateReference loadLevel, bool fastFade = false) + { + FadeLoadLevel(level.Barcode.ID, loadLevel.Barcode.ID, fastFade); + } + + /// + /// Loads a level from a barcode with load fade + /// + /// The barcode of the level + /// The barcode of the loading scene + /// When true, loads with a faster fade + public static void FadeLoadLevel(string levelBarcode, string loadLevelBarcode, bool fastFade = false) + { + MelonCoroutines.Start(FadeIntoLevel(levelBarcode, loadLevelBarcode, fastFade)); + } + + private static System.Collections.IEnumerator FadeIntoLevel(string levelBarcode, string loadSceneBarcode, bool fastFade = false) + { + if(fastFade) + { + SpawnCrate(CommonBarcodes.Misc.LoadFadeFast, Vector3.zero); + yield return new WaitForSeconds(0.5f); + } + else + { + SpawnCrate(CommonBarcodes.Misc.LoadFade, Vector3.zero); + yield return new WaitForSeconds(2); + } + LoadLevel(levelBarcode, loadSceneBarcode); + } + /// /// Checks if the player is in a loading screen or not ///