/// <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> /// Sets bleed light references based on their data /// </summary> /// <param name="roomParent">Parent of all the rooms</param> /// <param name="bleedLightsParent">Parent of all the bleed lights</param> private static void LoadBleedLightReferences(Transform roomParent, Transform bleedLightsParent) { // Get the amount of bleed lights int amountBleedLights = bleedLightsParent.childCount; // Load each bleed light for (int i = 0; i < amountBleedLights; ++i) { // Get the data saved for the bleed light BleedLightData bleedLightData = SaveSystem.LoadBleedLight(i); // Get the actual bleed light BleedLight curBleedLight = bleedLightsParent.GetChild(i).GetComponent <BleedLight>(); // Set its references based on the data // Broadcast room int broadcastSiblingIndex = bleedLightData.GetBroadcastRoomSiblingIndex(); Room newBroadcastRoom = roomParent.GetChild(broadcastSiblingIndex).GetComponent <Room>(); curBleedLight.BroadcastRoom = newBroadcastRoom; // Receive room int receiveSiblingIndex = bleedLightData.GetReceiveRoomSiblingIndex(); Room newReceiveRoom = roomParent.GetChild(receiveSiblingIndex).GetComponent <Room>(); curBleedLight.ReceiveRoom = newReceiveRoom; } }