Skip to content

Commit

Permalink
changed DestroyOnLoad to EnumerateDestroyOnLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgill28 committed Nov 27, 2020
1 parent c19a36d commit f866f45
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion WurstMod/Runtime/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static IEnumerator LoadCustomScene(LevelInfo level)

// Step 3: Destroy all unused objects
foreach (var gameObject in objects.SelectMany(o => o.GetComponentsInChildren<Transform>()))
foreach (var filter in sceneLoader.DestroyOnLoad)
foreach (var filter in sceneLoader.EnumerateDestroyOnLoad())
if (gameObject.name.Contains(filter))
Object.Destroy(gameObject.gameObject);

Expand Down
7 changes: 4 additions & 3 deletions WurstMod/Runtime/SceneLoaders/CustomSceneLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using WurstMod.MappingComponents.Generic;
Expand All @@ -20,12 +21,12 @@ public abstract class CustomSceneLoader
/// This is implemented by the deriving class and tells the loader which scene to use as the base for the game mode
/// </summary>
public abstract string BaseScene { get; }

/// <summary>
/// This list contains the names of all objects that should be removed from the scene when loading a new level
/// </summary>
public abstract string[] DestroyOnLoad { get; }
public virtual IEnumerable<string> EnumerateDestroyOnLoad() => new[] {"!ftraceLightmaps"}.AsEnumerable();

public CustomScene LevelRoot { get; set; }

/// <summary>
Expand Down
24 changes: 15 additions & 9 deletions WurstMod/Runtime/SceneLoaders/SandboxSceneLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using WurstMod.Runtime;
using System.Collections.Generic;
using System.Linq;
using WurstMod.Runtime;
using WurstMod.Shared;

namespace WurstMod.SceneLoaders
Expand All @@ -8,14 +10,18 @@ public class SandboxSceneLoader : CustomSceneLoader
public override string GamemodeId => Constants.GamemodeSandbox;
public override string BaseScene => "ProvingGround";

public override string[] DestroyOnLoad => new[]
public override IEnumerable<string> EnumerateDestroyOnLoad()
{
"_Animator_Spawning_",
"_Boards",
"_Env",
"AILadderTest1",
// TODO: Should probably remove all the Anvil Prefabs, but it causes errors...
//"__SpawnOnLoad",
};

return base.EnumerateDestroyOnLoad().Concat(new[]
{
"_Animator_Spawning_",
"_Boards",
"_Env",
"AILadderTest1",
// TODO: Should probably remove all the Anvil Prefabs, but it causes errors...
//"__SpawnOnLoad",
});
}
}
}
25 changes: 14 additions & 11 deletions WurstMod/Runtime/SceneLoaders/TakeAndHoldSceneLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ public class TakeAndHoldSceneLoader : CustomSceneLoader
public override string GamemodeId => Constants.GamemodeTakeAndHold;
public override string BaseScene => "TakeAndHoldClassic";

public override string[] DestroyOnLoad => new[]
public override IEnumerable<string> EnumerateDestroyOnLoad()
{
// Take and Hold objects
"HoldPoint_",
"Ladders",
"Lighting",
"OpenArea",
"RampHelperCubes",
"ReflectionProbes",
"SupplyPoint_",
"Tiles"
};
return base.EnumerateDestroyOnLoad().Concat(new[]
{
// Take and Hold objects
"HoldPoint_",
"Ladders",
"Lighting",
"OpenArea",
"RampHelperCubes",
"ReflectionProbes",
"SupplyPoint_",
"Tiles"
});
}

/// <summary>
/// Base function for setting up the TNH Manager object to handle a custom level.
Expand Down

0 comments on commit f866f45

Please sign in to comment.