Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Game.Shared.Exceptions;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

namespace Game.App.Title
{
Expand All @@ -13,6 +14,7 @@ namespace Game.App.Title
public class AppSceneLoader
{
private GameObject _currentInstance;
private AsyncOperationHandle<GameObject> _currentHandle;

public async UniTask<T> LoadAsync<T>(string address) where T : Component
{
Expand All @@ -27,8 +29,8 @@ public async UniTask<T> LoadAsync<T>(string address) where T : Component
try
{
// Addressablesから読み込み
var handle = Addressables.LoadAssetAsync<GameObject>(address);
var prefab = await handle.ToUniTask();
_currentHandle = Addressables.LoadAssetAsync<GameObject>(address);
var prefab = await _currentHandle.ToUniTask();

if (prefab == null)
{
Expand All @@ -46,6 +48,8 @@ public async UniTask<T> LoadAsync<T>(string address) where T : Component
{
UnityEngine.Object.Destroy(_currentInstance);
_currentInstance = null;
Addressables.Release(_currentHandle);
_currentHandle = default;
throw new GameAssetLoadException(address, typeof(T), $"Component {typeof(T).Name} not found on prefab: {address}");
}

Expand All @@ -57,6 +61,11 @@ public async UniTask<T> LoadAsync<T>(string address) where T : Component
}
catch (Exception ex)
{
if (_currentHandle.IsValid())
{
Addressables.Release(_currentHandle);
_currentHandle = default;
}
Debug.LogError($"[AppSceneLoader] Failed to load {address}: {ex.Message}");
throw new GameAssetLoadException(address, typeof(T), $"Failed to load prefab: {address}", ex);
}
Expand All @@ -69,6 +78,12 @@ public void Unload()
UnityEngine.Object.Destroy(_currentInstance);
_currentInstance = null;
}

if (_currentHandle.IsValid())
{
Addressables.Release(_currentHandle);
_currentHandle = default;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ private void BindButtons()
_scoreTimeAttackButton?.RegisterCallback<ClickEvent>(_ =>
{
SetModeButtonsEnabled(false);
SelectGameModeAsync(GameMode.MvcScoreTimeAttack).Forget();
SelectGameModeAsync(GameMode.MvcScoreTimeAttack).ForgetWithHandler("AppTitleSceneComponent.SelectGameMode");
});

_survivorButton?.RegisterCallback<ClickEvent>(_ =>
{
SetModeButtonsEnabled(false);
SelectGameModeAsync(GameMode.MvpSurvivor).Forget();
SelectGameModeAsync(GameMode.MvpSurvivor).ForgetWithHandler("AppTitleSceneComponent.SelectGameMode");
});

_quitButton?.RegisterCallback<ClickEvent>(_ =>
{
SetModeButtonsEnabled(false);
QuitGameAsync().Forget();
QuitGameAsync().ForgetWithHandler("AppTitleSceneComponent.QuitGame");
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Cysharp.Threading.Tasks;
using Game.Shared.Extensions;
using Game.Shared.Scenes;
using Game.Core.Services;
using Game.MVC.Core.Enums;
using UnityEngine;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Game.ScoreTimeAttack.Enemy;
using Game.ScoreTimeAttack.Item;
using Game.ScoreTimeAttack.Player;
using Game.MVC.Core.Scenes;
using Game.Shared.Scenes;
using UnityEngine;
using UnityEngine.SceneManagement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ namespace Game.MVP.Core.Constants
{
public static class GameSceneConstants
{
// プレハブを所属させる常駐UnitySceneName
public const string GameRootScene = "GameRootScene";

public const GameSceneOperations DefaultOperations = GameSceneOperations.CurrentSceneTerminate |
GameSceneOperations.CurrentSceneClearHistory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Game.MVP.Core.DI;
using Game.MVP.Core.Enums;
using Game.Shared.Extensions;
using Game.Shared.Scenes;
using Game.Shared.Services;
using R3;
using UnityEngine;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Game.MVP.Core.Scenes;
using Game.Shared.Scenes;
using Game.MVP.Survivor.Player;
using UnityEngine;
using UnityEngine.SceneManagement;
Expand Down
8 changes: 8 additions & 0 deletions src/Game.Client/Assets/Programs/Runtime/Shared/Scenes.meta

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

Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
using System;
using System.Collections.Generic;
using Game.MVP.Core.Constants;
using Game.Shared.Constants;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Game.MVP.Core.Scenes
namespace Game.Shared.Scenes
{
public static class GameSceneHelper
{
public static void MoveToGameRootScene(GameObject scene)
{
var activeScene = SceneManager.GetActiveScene();
if (activeScene.IsValid() && activeScene.name == GameSceneConstants.GameRootScene)
if (activeScene.IsValid() && activeScene.name == AppConstants.GameRootScene)
{
SceneManager.MoveGameObjectToScene(scene, activeScene);
}
else
{
var rootScene = SceneManager.GetSceneByName(GameSceneConstants.GameRootScene);
var rootScene = SceneManager.GetSceneByName(AppConstants.GameRootScene);
if (rootScene.IsValid())
{
SceneManager.MoveGameObjectToScene(scene, rootScene);
}
}
}

public static T GetComponent<T>(GameObject gameObject) where T : Behaviour
{
if (gameObject.TryGetComponent<T>(out var component))
{
return component;
}

return gameObject.GetComponentInChildren<T>();
}

public static T GetSceneComponent<T>(GameObject scene) where T : IGameSceneComponent
public static T GetSceneComponent<T>(GameObject scene)
{
if (scene.TryGetComponent<T>(out var sceneComponent))
{
Expand All @@ -45,7 +34,7 @@ public static T GetSceneComponent<T>(GameObject scene) where T : IGameSceneCompo
return scene.GetComponentInChildren<T>();
}

public static T GetSceneComponent<T>(Scene scene) where T : IGameSceneComponent
public static T GetSceneComponent<T>(Scene scene)
{
var rootGameObjects = scene.GetRootGameObjects();

Expand Down Expand Up @@ -101,4 +90,4 @@ public static T[] GetComponentsInChildren<T>(Scene scene) where T : Behaviour
return list.ToArray();
}
}
}
}

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

Loading