Skip to content

Commit

Permalink
unify single and multiple scene tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoborks committed Dec 29, 2024
1 parent 076c82e commit b5cbfa6
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public ValueTask<SceneResult> UnloadAsync(SceneParameters sceneParameters, Cance
async ValueTask<SceneResult> LoadScenesAsync_Internal(SceneParameters sceneParameters, IProgress<float> progress, CancellationToken token)
{
ILoadSceneInfo[] sceneInfos = sceneParameters.GetLoadSceneInfos();
int setIndexActive = sceneParameters.GetIndexActive();
int setIndexActive = sceneParameters.GetIndexToActivate();
int scenesToLoad = sceneInfos.Length;

ISceneData[] sceneDataArray = new ISceneData[scenesToLoad];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace MyGameDevTools.SceneLoading
{
public readonly struct SceneParameters
{
public readonly int Length => _loadSceneInfoArray.Length;

readonly ILoadSceneInfo[] _loadSceneInfoArray;
readonly ILoadSceneInfo _singleLoadSceneInfo;
readonly int _setIndexActive;
Expand Down Expand Up @@ -35,7 +37,7 @@ public readonly bool ShouldSetActive()
return _setIndexActive == 0;
}

public readonly int GetIndexActive()
public readonly int GetIndexToActivate()
{
return _setIndexActive;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ public static ValueTask<SceneResult> TransitionAddressableAsync(this ISceneManag
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, string[] sceneNames, CancellationToken token = default)
{
var sceneInfos = sceneNames.Select(name => (ILoadSceneInfo)new LoadSceneInfoName(name)).ToArray();
var sceneParams = new SceneParameters(sceneInfos);
ILoadSceneInfo[] sceneInfos = sceneNames.Select(name => (ILoadSceneInfo)new LoadSceneInfoName(name)).ToArray();
SceneParameters sceneParams = new(sceneInfos);
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -492,8 +492,8 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, int[] buildIndices, CancellationToken token = default)
{
var sceneInfos = buildIndices.Select(index => (ILoadSceneInfo)new LoadSceneInfoIndex(index)).ToArray();
var sceneParams = new SceneParameters(sceneInfos);
ILoadSceneInfo[] sceneInfos = buildIndices.Select(index => (ILoadSceneInfo)new LoadSceneInfoIndex(index)).ToArray();
SceneParameters sceneParams = new(sceneInfos);
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -511,8 +511,8 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, Scene[] scenes, CancellationToken token = default)
{
var sceneInfos = scenes.Select(scene => (ILoadSceneInfo)new LoadSceneInfoScene(scene)).ToArray();
var sceneParams = new SceneParameters(sceneInfos);
ILoadSceneInfo[] sceneInfos = scenes.Select(scene => (ILoadSceneInfo)new LoadSceneInfoScene(scene)).ToArray();
SceneParameters sceneParams = new(sceneInfos);
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -530,7 +530,7 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, string sceneName, CancellationToken token = default)
{
var sceneParams = new SceneParameters(new LoadSceneInfoName(sceneName));
SceneParameters sceneParams = new(new LoadSceneInfoName(sceneName));
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -548,7 +548,7 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, int buildIndex, CancellationToken token = default)
{
var sceneParams = new SceneParameters(new LoadSceneInfoIndex(buildIndex));
SceneParameters sceneParams = new(new LoadSceneInfoIndex(buildIndex));
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -566,7 +566,7 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager, Scene scene, CancellationToken token = default)
{
var sceneParams = new SceneParameters(new LoadSceneInfoScene(scene));
SceneParameters sceneParams = new(new LoadSceneInfoScene(scene));
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -585,8 +585,8 @@ public static ValueTask<SceneResult> UnloadAsync(this ISceneManager sceneManager
/// </returns>
public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager sceneManager, AssetReference[] assetReferences, CancellationToken token = default)
{
var sceneInfos = assetReferences.Select(asset => (ILoadSceneInfo)new LoadSceneInfoAssetReference(asset)).ToArray();
var sceneParams = new SceneParameters(sceneInfos);
ILoadSceneInfo[] sceneInfos = assetReferences.Select(asset => (ILoadSceneInfo)new LoadSceneInfoAssetReference(asset)).ToArray();
SceneParameters sceneParams = new(sceneInfos);
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -604,8 +604,8 @@ public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager s
/// </returns>
public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager sceneManager, string[] addresses, CancellationToken token = default)
{
var sceneInfos = addresses.Select(address => (ILoadSceneInfo)new LoadSceneInfoAddress(address)).ToArray();
var sceneParams = new SceneParameters(sceneInfos);
ILoadSceneInfo[] sceneInfos = addresses.Select(address => (ILoadSceneInfo)new LoadSceneInfoAddress(address)).ToArray();
SceneParameters sceneParams = new(sceneInfos);
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -623,7 +623,7 @@ public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager s
/// </returns>
public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager sceneManager, AssetReference assetReference, CancellationToken token = default)
{
var sceneParams = new SceneParameters(new LoadSceneInfoAssetReference(assetReference));
SceneParameters sceneParams = new(new LoadSceneInfoAssetReference(assetReference));
return sceneManager.UnloadAsync(sceneParams, token);
}

Expand All @@ -641,7 +641,7 @@ public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager s
/// </returns>
public static ValueTask<SceneResult> UnloadAddressableAsync(this ISceneManager sceneManager, string address, CancellationToken token = default)
{
var sceneParams = new SceneParameters(new LoadSceneInfoAddress(address));
SceneParameters sceneParams = new(new LoadSceneInfoAddress(address));
return sceneManager.UnloadAsync(sceneParams, token);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,4 @@ public bool MoveNext()

public void Reset() { }
}

public readonly struct WaitValueTask<T> : IEnumerator
{
public object Current => null;

public readonly ValueTask<T> ValueTask;

public WaitValueTask(ValueTask<T> valueTask)
{
ValueTask = valueTask;
}

public bool MoveNext()
{
return !ValueTask.IsCompleted && !ValueTask.IsCanceled && !ValueTask.IsFaulted;
}

public void Reset() { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using System.Threading.Tasks;

namespace MyGameDevTools.SceneLoading
{
public readonly struct WaitValueTask<T> : IEnumerator
{
public object Current => null;

public readonly ValueTask<T> ValueTask;

public WaitValueTask(ValueTask<T> valueTask)
{
ValueTask = valueTask;
}

public bool MoveNext()
{
return !ValueTask.IsCompleted && !ValueTask.IsCanceled && !ValueTask.IsFaulted;
}

public void Reset() { }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5cbfa6

Please sign in to comment.