diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e85d888..79bbac5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,8 @@ jobs: id: tests env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} with: projectPath: ${{ matrix.project-path }} testMode: ${{ matrix.testMode }} diff --git a/.releaserc.json b/.releaserc.json index 39c2de7..2aed5ab 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,14 +1,16 @@ -{ - "tagFormat": "${version}", - "plugins": [ - ["@semantic-release/commit-analyzer", { "preset": "angular" }], - "@semantic-release/release-notes-generator", - ["@semantic-release/changelog", { "preset": "angular" }], - ["@semantic-release/npm", { "npmPublish": false, "pkgRoot": "Packages/mygamedevtools-scene-loader" }], - ["@semantic-release/git", { - "assets": ["Packages/mygamedevtools-scene-loader/package.json", "CHANGELOG.md"], - "message": "ci(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" - }], - "@semantic-release/github" - ] +{ + "tagFormat": "${version}", + "plugins": [ + ["@semantic-release/commit-analyzer", { "preset": "angular" }], + "@semantic-release/release-notes-generator", + ["@semantic-release/changelog", { + "changelogTitle": "# Changelog" + }], + ["@semantic-release/npm", { "npmPublish": false, "pkgRoot": "Packages/mygamedevtools-scene-loader" }], + ["@semantic-release/git", { + "assets": ["Packages/mygamedevtools-scene-loader/package.json", "CHANGELOG.md"], + "message": "ci(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + }], + "@semantic-release/github" + ] } \ No newline at end of file diff --git a/Packages/mygamedevtools-scene-loader/Runtime/Managers/SceneManagerAddressable.cs b/Packages/mygamedevtools-scene-loader/Runtime/Managers/SceneManagerAddressable.cs index 322504a..d4a4441 100644 --- a/Packages/mygamedevtools-scene-loader/Runtime/Managers/SceneManagerAddressable.cs +++ b/Packages/mygamedevtools-scene-loader/Runtime/Managers/SceneManagerAddressable.cs @@ -78,7 +78,7 @@ public async ValueTask LoadScenesAsync(ILoadSceneInfo[] sceneInfos, int if (setIndexActive >= sceneInfos.Length) throw new ArgumentException(nameof(setIndexActive), $"[{GetType().Name}] Provided index to set active is bigger than the provided scene group size."); - var operationGroup = GetLoadSceneOperations(sceneInfos, ref setIndexActive); + var operationGroup = await GetLoadSceneOperations(sceneInfos, setIndexActive); if (operationGroup.Operations.Count == 0) return Array.Empty(); @@ -98,8 +98,8 @@ public async ValueTask LoadScenesAsync(ILoadSceneInfo[] sceneInfos, int foreach (var sceneInstance in loadedScenes) SceneLoaded?.Invoke(sceneInstance.Scene); - if (setIndexActive >= 0) - SetActiveScene(loadedScenes[setIndexActive].Scene); + if (operationGroup.SetIndexActive >= 0) + SetActiveScene(loadedScenes[operationGroup.SetIndexActive].Scene); return ToSceneArray(loadedScenes); } @@ -131,14 +131,16 @@ public async ValueTask UnloadScenesAsync(ILoadSceneInfo[] sceneInfos) for (i = 0; i < unloadingLength; i++) loadedScenes.Remove(unloadingScenes[i]); - var operationGroup = new AsyncOperationHandleGroup(loadedScenes.Count); + var operationList = new List>(loadedScenes.Count); foreach (var sceneInstance in loadedScenes) { - operationGroup.Operations.Add(Addressables.UnloadSceneAsync(sceneInstance)); + operationList.Add(Addressables.UnloadSceneAsync(sceneInstance)); _loadedScenes.Remove(sceneInstance); _unloadingScenes.Add(sceneInstance); } + var operationGroup = new AsyncOperationHandleGroup(operationList); + while (!operationGroup.IsDone) #if USE_UNITASK await UniTask.Yield(); @@ -187,18 +189,19 @@ async ValueTask WaitForSceneUnload(SceneInstance sceneInstance) return sceneInstance.Scene; } - AsyncOperationHandleGroup GetLoadSceneOperations(ILoadSceneInfo[] sceneInfos, ref int setIndexActive) + async ValueTask GetLoadSceneOperations(ILoadSceneInfo[] sceneInfos, int setIndexActive) { var sceneLength = sceneInfos.Length; - var operationGroup = new AsyncOperationHandleGroup(sceneLength); + var operationList = new List>(sceneLength); for (int i = 0; i < sceneLength; i++) { - if (TryGetLoadSceneOperation(sceneInfos[i], out var operation)) - operationGroup.Operations.Add(operation); + var operation = await GetLoadSceneOperation(sceneInfos[i]); + if (operation.IsValid()) + operationList.Add(operation); else if (i == setIndexActive) setIndexActive = -1; } - return operationGroup; + return new AsyncOperationHandleGroup(operationList, setIndexActive); } IList GetLastLoadedScenesByInfos(ILoadSceneInfo[] sceneInfos, out int[] unloadingIndexes) @@ -256,26 +259,23 @@ Scene[] ToSceneArray(IList sceneInstances) return sceneArray; } - bool TryGetLoadSceneOperation(ILoadSceneInfo sceneInfo, out AsyncOperationHandle operationHandle) + async ValueTask> GetLoadSceneOperation(ILoadSceneInfo sceneInfo) { - operationHandle = default; if (sceneInfo.Reference is AssetReference assetReference) - operationHandle = assetReference.LoadSceneAsync(LoadSceneMode.Additive); + return assetReference.LoadSceneAsync(LoadSceneMode.Additive); else if (sceneInfo.Reference is string name) { - if (ValidateAssetReference(name)) - operationHandle = Addressables.LoadSceneAsync(name, LoadSceneMode.Additive); + if (await ValidateAssetReference(name)) + return Addressables.LoadSceneAsync(name, LoadSceneMode.Additive); else { Debug.LogWarning($"[{GetType().Name}] Scene '{name}' couldn't be loaded because its address found no Addressable Assets."); - return false; + return default; } } - bool isValid = operationHandle.IsValid(); - if (!isValid) - Debug.LogWarning($"[{GetType().Name}] Unexpected {nameof(ILoadSceneInfo.Reference)} type: {sceneInfo.Reference}"); - return isValid; + Debug.LogWarning($"[{GetType().Name}] Unexpected {nameof(ILoadSceneInfo.Reference)} type: {sceneInfo.Reference}"); + return default; } bool TryGetInstanceFromScene(Scene scene, out SceneInstance sceneInstance) @@ -291,10 +291,15 @@ bool TryGetInstanceFromScene(Scene scene, out SceneInstance sceneInstance) return false; } - bool ValidateAssetReference(object reference) + async ValueTask ValidateAssetReference(object reference) { var operation = Addressables.LoadResourceLocationsAsync(reference); - operation.WaitForCompletion(); +#if USE_UNITASK + await operation; +#else + while (!operation.IsDone) + await Task.Yield(); +#endif return operation.Result.Count > 0; } diff --git a/Packages/mygamedevtools-scene-loader/Runtime/Utilities/AsyncOperationHandleGroup.cs b/Packages/mygamedevtools-scene-loader/Runtime/Utilities/AsyncOperationHandleGroup.cs index 9cc471f..6058181 100644 --- a/Packages/mygamedevtools-scene-loader/Runtime/Utilities/AsyncOperationHandleGroup.cs +++ b/Packages/mygamedevtools-scene-loader/Runtime/Utilities/AsyncOperationHandleGroup.cs @@ -41,9 +41,12 @@ public bool IsDone } } - public AsyncOperationHandleGroup(int initialCapacity) + public readonly int SetIndexActive; + + public AsyncOperationHandleGroup(List> operationList, int setIndexActive = -1) { - Operations = new List>(initialCapacity); + Operations = operationList; + SetIndexActive = setIndexActive; } public IList GetResult() diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 5773716..50e2701 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2023.2.1f1 -m_EditorVersionWithRevision: 2023.2.1f1 (a6dd9a634651) +m_EditorVersion: 2023.2.3f1 +m_EditorVersionWithRevision: 2023.2.3f1 (21747dafc6ee)