/// <summary> /// Creates bleed light objects based on the stored bleed light data. /// Does not set references to any other game objects for the bleed lights /// </summary> /// <param name="bleedLightParent">Transform that will serve as the parent of the new bleed lights</param> /// <param name="bleedLightPrefab">Prefab of a bleed light</param> public static void LoadBleedLights(Transform bleedLightParent, GameObject bleedLightPrefab) { // Get the amount of bleed lights ChildAmountData bleedLightAmData = SaveSystem.LoadBleedLightAmount(); int amountBleedLights = bleedLightAmData.GetChildAmount(); // Load each bleed light for (int i = 0; i < amountBleedLights; ++i) { // Get the data saved for the bleed light BleedLightData bleedLightData = SaveSystem.LoadBleedLight(i); // Create the new bleed light as a child of the bleed light parent GameObject bleedLightObj = Object.Instantiate(bleedLightPrefab, bleedLightParent); // Set its transform components bleedLightObj.transform.position = bleedLightData.GetPosition(); bleedLightObj.transform.rotation = bleedLightData.GetRotation(); // Get its SpriteRenderer SpriteRenderer sprRendRef = bleedLightObj.GetComponent <SpriteRenderer>(); if (sprRendRef == null) { Debug.LogError("No SpriteRenderer attached to " + bleedLightObj.name); return; } // Set the color of the sprite renderer sprRendRef.color = bleedLightData.GetSpriteRendererColor(); } }
/// <summary> /// Creates interactable objects based on the stored interactable data /// </summary> /// <param name="interactableParent">Transform that will serve as the parent for the loaded interactables</param> public static void LoadInteractables(Transform interactableParent) { // Get the amount of interactables ChildAmountData interactAmData = SaveSystem.LoadInteractableAmount(); int amountInteractables = interactAmData.GetChildAmount(); // Load each interactable for (int i = 0; i < amountInteractables; ++i) { // Get the data for the interactable InteractableData interactData = SaveSystem.LoadInteractable(i); // Get the key to which prefab to spawn off the interactData int key = interactData.GetPrefabKey(); // Use the key to get the prefab to load GameObject interactPref = SaveInteractablesController.GetInteractablePrefab(key); // Spawn the prefab as a child of the interactable parent GameObject interactObj = Object.Instantiate(interactPref, interactableParent); // Set its transform components interactObj.transform.position = interactData.GetPosition(); // Get its Interact script Interactable interactScriptRef = interactObj.GetComponent <Interactable>(); if (interactScriptRef == null) { Debug.LogError("No Interactable script was attached to " + interactObj.name); return; } // Set all the saved variables from that script interactScriptRef.SetCanInteractWith(interactData.GetCanInteractWith()); } }
/// <summary> /// Creates allies based on the stored ally data /// </summary> /// <param name="allyParent">Transform that will serve as the parent for the loaded allies</param> public static void LoadAllies(Transform allyParent) { // Get the amount of allies ChildAmountData allyAmData = SaveSystem.LoadAllyAmount(); int allyAmount = allyAmData.GetChildAmount(); // Load each ally for (int i = 0; i < allyAmount; ++i) { // Get the data for the ally AllyData allyData = SaveSystem.LoadAlly(i); // Get the key of which prefab to spawn int key = allyData.GetPrefabKey(); // Use the key to get the prefab to spawn GameObject allyPrefab = SaveAlliesController.GetAllyPrefab(key); // Spawn the prefab as a child of the ally Parent GameObject allyObj = Object.Instantiate(allyPrefab, allyParent); // Set its transform components allyObj.transform.position = allyData.GetPosition(); // Get its AllyStats script AllyStats allyStatsScriptRef = allyObj.GetComponent <AllyStats>(); if (allyStatsScriptRef != null) { allyStatsScriptRef.SetExperience(allyData.GetExperience()); allyStatsScriptRef.SetOneLevelExperience(allyData.GetOneLevelExperience()); allyStatsScriptRef.SetLevel(allyData.GetLevel()); allyStatsScriptRef.SetNextLevelThreshold(allyData.GetNextLevelThreshold()); allyStatsScriptRef.SetOneLevelNextLevelThreshold(allyData.GetOneLevelNextLevelThreshold()); allyStatsScriptRef.AmountStatIncreases = allyData.GetAmountStatIncreases(); allyStatsScriptRef.SetStrength(allyData.GetStrength()); allyStatsScriptRef.SetMagic(allyData.GetMagic()); allyStatsScriptRef.SetSpeed(allyData.GetSpeed()); allyStatsScriptRef.SetVitality(allyData.GetVitality()); allyStatsScriptRef.StrBubblesFilled = allyData.GetStrengthBubblesFilled(); allyStatsScriptRef.MagicBubblesFilled = allyData.GetMagicBubblesFilled(); allyStatsScriptRef.SpeedBubblesFilled = allyData.GetSpeedBubblesFilled(); allyStatsScriptRef.VitalityBubblesFilled = allyData.GetVitalityBubblesFilled(); } else { Debug.LogError("There was no AllyStats script attached to " + allyObj.name); } // Get its AllyHealth script AllyHealth allyHealthScriptRef = allyObj.GetComponent <AllyHealth>(); if (allyHealthScriptRef != null) { allyHealthScriptRef.MaxHP = allyData.GetMaxHP(); allyHealthScriptRef.CurHP = allyData.GetCurHP(); } else { Debug.LogError("There was no AllyHealth script attached to " + allyObj.name); } } }
/// <summary> /// Creates enemies based on the stored enemy data /// </summary> /// <param name="enemyParent">Transform that will serve as the parent for the loaded enemies</param> public static void LoadEnemies(Transform enemyParent) { // Get the amount of enemies ChildAmountData enemyAmData = SaveSystem.LoadEnemyAmount(); int amountEnemies = enemyAmData.GetChildAmount(); // Load each enemy for (int i = 0; i < amountEnemies; ++i) { // Get the data for the enemy EnemyData enemyData = SaveSystem.LoadEnemy(i); // Get the key of which prefab to spawn int key = enemyData.GetPrefabKey(); // Use the key to get the prefab to spawn GameObject enemyPrefab = SaveEnemiesController.GetEnemyPrefab(key); // Spawn the prefab as a child of the enemy Parent GameObject enemyObj = Object.Instantiate(enemyPrefab, enemyParent); // Set its transform components enemyObj.transform.position = enemyData.GetPosition(); // Get its EnemyStats script EnemyStats enemyStatsRef = enemyObj.GetComponent <EnemyStats>(); if (enemyStatsRef != null) { enemyStatsRef.SetStrength(enemyData.GetStrength()); enemyStatsRef.SetMagic(enemyData.GetMagic()); enemyStatsRef.SetSpeed(enemyData.GetSpeed()); enemyStatsRef.SetVitality(enemyData.GetVitality()); enemyStatsRef.SetBaseXpToGive(enemyData.GetBaseXpToGive()); enemyStatsRef.SetDifficulty(enemyData.GetDifficulty()); } else { Debug.LogError("There is no EnemyStats script attached to " + enemyObj.name); } // Get its EnemyHealth script EnemyHealth enemyHealthRef = enemyObj.GetComponent <EnemyHealth>(); if (enemyHealthRef != null) { enemyHealthRef.MaxHP = enemyData.GetMaxHealth(); enemyHealthRef.CurHP = enemyData.GetCurrentHealth(); } else { Debug.LogError("There is no EnemyHealth script attached to " + enemyObj.name); } // If it is rainbow attach a Rainbow script to it if (enemyData.GetIsRainbow()) { enemyObj.AddComponent <Rainbow>(); } } }
/// <summary> /// Creates wall objects based on the stored data /// </summary> /// <param name="wallsParent">Transform that will serve as the parent for the new walls</param> /// <param name="wallPrefab">Prefab of a wall</param> public static void LoadWalls(Transform wallsParent, GameObject wallPrefab) { // Get the amount of walls ChildAmountData wallAmData = SaveSystem.LoadWallAmount(); int amountWalls = wallAmData.GetChildAmount(); // Load each wall for (int i = 0; i < amountWalls; ++i) { // Get the data for the wall WallData wallData = SaveSystem.LoadWall(i); // Create the new wall as a child of the wall parent GameObject wallObj = Object.Instantiate(wallPrefab, wallsParent); // Set its transform components wallObj.transform.position = wallData.GetPosition(); } }
/// <summary> /// Creates room objects based on the stored room data. /// Does not set references to any other game objects for the rooms /// </summary> /// <param name="roomsParent">Transform that will serve as the parent of the new rooms</param> /// <param name="roomPrefab">Prefab of a room</param> public static void LoadRooms(Transform roomsParent, GameObject roomPrefab) { // Get the amount of rooms ChildAmountData roomAmData = SaveSystem.LoadRoomAmount(); int amountRooms = roomAmData.GetChildAmount(); // Load each room for (int i = 0; i < amountRooms; ++i) { // Get the data for the room RoomData roomData = SaveSystem.LoadRoom(i); // Create the new room as a child of the rooms parent GameObject roomObj = Object.Instantiate(roomPrefab, roomsParent); // Set its transform components roomObj.transform.position = roomData.GetPosition(); roomObj.transform.localScale = roomData.GetScale(); // Get its Room script Room roomScrRef = roomObj.GetComponent <Room>(); if (roomScrRef == null) { Debug.LogError("No Room script attached to " + roomObj.name); return; } // Set all the room script variables roomScrRef.SetIsRoomActive(roomData.GetIsRoomActive()); roomScrRef.SetCurrentLightIntensity(roomData.GetCurrentLightIntensity()); roomScrRef.SetClear(roomData.GetClear()); roomScrRef.RoomWeight = roomData.GetRoomWeight(); roomScrRef.MyRoomType = roomData.GetMyRoomType(); roomScrRef.RoomDifficulty = roomData.GetRoomDifficulty(); // Get its SpriteRenderer SpriteRenderer sprRendRef = roomObj.GetComponent <SpriteRenderer>(); if (sprRendRef == null) { Debug.LogError("No SpriteRenderer attached to " + roomObj.name); return; } // Set the color of the sprite renderer sprRendRef.color = roomData.GetSpriteRendererColor(); } }