Skip to content

Commit

Permalink
added load scene by name method
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddio0141 committed Sep 10, 2024
1 parent 390ab45 commit 5daa01a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion UniTAS/Patcher.Tests/KernelUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public void LoadScene(int buildIndex)
{
}

public void LoadScene(string name)
{
}

public int TotalSceneCount => 0;
public int ActiveSceneIndex => 0;
public string ActiveSceneName => "";
Expand Down Expand Up @@ -365,4 +369,4 @@ public static Container Init()

return kernel;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class SceneManagerWrapper : ISceneWrapper
private readonly Func<string, int, bool, bool, AsyncOperation> _applicationLoadLevelAsync;

// non-async load level
private readonly MethodInfo _loadScene;
private readonly MethodInfo _loadSceneByIndex;
private readonly MethodInfo _loadSceneByName;

private readonly MethodInfo _getActiveScene;

Expand All @@ -58,7 +59,8 @@ public SceneManagerWrapper(IUnityInstanceWrapFactory unityInstanceWrapFactory)
[typeof(string), typeof(int), _loadSceneParametersType, typeof(bool)], null);
}

_loadScene = _sceneManager?.GetMethod("LoadScene", AccessTools.all, null, [typeof(int)], null);
_loadSceneByIndex = _sceneManager?.GetMethod("LoadScene", AccessTools.all, null, [typeof(int)], null);
_loadSceneByName = _sceneManager?.GetMethod("LoadScene", AccessTools.all, null, [typeof(string)], null);

var loadLevelAsync = AccessTools.Method(typeof(Application), "LoadLevelAsync",
[typeof(string), typeof(int), typeof(bool), typeof(bool)]);
Expand Down Expand Up @@ -119,15 +121,26 @@ public void LoadSceneAsync(string sceneName, int sceneBuildIndex, LoadSceneMode

public void LoadScene(int buildIndex)
{
if (_loadScene != null)
if (_loadSceneByIndex != null)
{
_loadScene.Invoke(null, [buildIndex]);
_loadSceneByIndex.Invoke(null, [buildIndex]);
return;
}

Application.LoadLevel(buildIndex);
}

public void LoadScene(string name)
{
if (_loadSceneByName != null)
{
_loadSceneByName.Invoke(null, [name]);
return;
}

Application.LoadLevel(name);
}

public int TotalSceneCount => _totalSceneCount?.Invoke() ?? Application.levelCount;

public int ActiveSceneIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void LoadSceneAsync(string sceneName, int sceneBuildIndex, LoadSceneMode loadSce
LocalPhysicsMode localPhysicsMode, bool mustCompleteNextFrame);

void LoadScene(int buildIndex);
void LoadScene(string name);

int TotalSceneCount { get; }

Expand Down

0 comments on commit 5daa01a

Please sign in to comment.