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 @@ -4,7 +4,6 @@
using Game.App.Services;
using Game.Library.Shared.Enums;
using Game.Shared.Enums;
using Game.Shared.Extensions;
using Game.Shared.Services;
using Game.Shared.Services.RemoteAsset;
using R3;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void Initialize(IAppServiceProvider serviceProvider)
ShowPanel(_initialPanel);
UpdateVersionText();

PlayGameReadySoundAsync().ForgetWithHandler("AppTitleSceneComponent.PlayGameReadySound");
PlayGameReadySoundAsync().Forget();
}

private void SetupUIElements()
Expand Down Expand Up @@ -102,26 +101,26 @@ private void BindButtons()
_scoreTimeAttackButton?.RegisterCallback<ClickEvent>(_ =>
{
SetModeButtonsEnabled(false);
SelectGameModeAsync(GameMode.MvcScoreTimeAttack).ForgetWithHandler("AppTitleSceneComponent.SelectGameMode");
SelectGameModeAsync(GameMode.MvcScoreTimeAttack).Forget();
});

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

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

private void OnGameStartClicked()
{
_gameStartButton.SetEnabled(false);
HandleGameStartAsync().ForgetWithHandler("AppTitleSceneComponent.HandleGameStart");
HandleGameStartAsync().Forget();
}

private async UniTask HandleGameStartAsync()
Expand Down Expand Up @@ -201,7 +200,7 @@ private void OnDownloadProgress(DownloadProgress progress)
private void OnRetryClicked()
{
_retryButton.SetEnabled(false);
StartDownloadAsync().ForgetWithHandler("AppTitleSceneComponent.RetryDownload");
StartDownloadAsync().Forget();
}

private void ShowError(string message)
Expand Down Expand Up @@ -271,7 +270,7 @@ private async UniTask PlayGameStartSoundAsync(CancellationToken token)
if (AudioService != null)
{
AudioService.PlayRandomOneAsync(AudioCategory.SoundEffect, AudioPlayTag.UIButton, token)
.ForgetWithHandler("AppTitleSceneComponent.PlayUIButtonSound");
.Forget();
await AudioService.PlayRandomOneAsync(AudioPlayTag.GameStart, token);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ public void Initialize(IGameSceneResult<PauseDialogResult> result)
SetInteractables(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void SpawnItem(int itemId, Vector3 position)
// プールがなければ動的に作成
if (!_pools.ContainsKey(itemId))
{
PreloadItemAsync(itemId).ForgetWithHandler("SurvivorItemSpawner.PreloadItem");
PreloadItemAsync(itemId).Forget();
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using Cysharp.Threading.Tasks;
using Game.MVP.Core.Scenes;
using Game.MVP.Survivor.Item;
using Game.MVP.Survivor.Scenes.Models;
using Game.MVP.Survivor.SaveData;
using Game.MVP.Survivor.Services;
using Game.Shared.Bootstrap;
using Game.Shared.Constants;
using Game.Shared.Extensions;
using Game.Shared.Services;
using R3;
using R3.Triggers;
Expand Down Expand Up @@ -259,7 +257,7 @@ private void SaveCurrentSession()
totalKills: _stageModel.TotalKills.Value
);

SaveCurrentSessionAsync().ForgetWithHandler("SurvivorStageScene.SaveCurrentSession");
SaveCurrentSessionAsync().Forget();
}

private async UniTask SaveCurrentSessionAsync()
Expand Down Expand Up @@ -411,4 +409,4 @@ private int GetCappedKills()
return Math.Min(_stageModel.TotalKills.Value, _waveManager.TotalTargetKills);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Game.Shared.Extensions;

using Game.Shared.Services;
using Unity.Profiling;
using UnityEngine;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void SpawnEffect(string assetName, Vector3 position, float scale = 1f)
// プールがなければ動的に作成開始
if (!_pools.ContainsKey(assetName))
{
PreloadEffectAsync(assetName).ForgetWithHandler("SurvivorVfxSpawner.PreloadEffect");
PreloadEffectAsync(assetName).Forget();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ public override async UniTask InitializeAsync(

protected override void OnAssetNameChanged(string oldAssetName, string newAssetName)
{
SwitchPoolAsync(oldAssetName, newAssetName)
.ForgetWithHandler($"{GetType().Name}.SwitchPool");
SwitchPoolAsync(oldAssetName, newAssetName).Forget();
}

private async UniTask SwitchPoolAsync(string oldAssetName, string newAssetName)
Expand All @@ -490,8 +489,7 @@ private async UniTask SwitchPoolAsync(string oldAssetName, string newAssetName)
if (!string.IsNullOrEmpty(oldAssetName) &&
_poolsByAssetName.TryGetValue(oldAssetName, out var oldPool))
{
DisposeOldPoolAsync(oldAssetName, oldPool)
.ForgetWithHandler($"{GetType().Name}.DisposeOldPool");
DisposeOldPoolAsync(oldAssetName, oldPool).Forget();
}

Debug.Log($"[{GetType().Name}] Switched to pool: {newAssetName}");
Expand Down Expand Up @@ -595,4 +593,4 @@ public override void Dispose()
base.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,98 +5,12 @@
namespace Game.Shared.Extensions
{
/// <summary>
/// UniTaskの例外処理拡張メソッド
/// .Forget()呼び出し時の例外ロストを防ぐためのユーティリティ
/// UniTaskの例外処理・リトライ拡張メソッド
/// NOTE: .Forget() の例外は UniTaskScheduler.UnobservedTaskException 経由で
/// GameBootstrap.OnUnobservedTaskException がスタックトレース付きでログ出力する
/// </summary>
public static class UniTaskExceptionExtensions
{
/// <summary>
/// 例外をログ出力しながらForgetする
/// .Forget()の代わりに使用することで、非同期処理の例外を追跡可能にする
/// </summary>
/// <param name="task">対象のUniTask</param>
/// <param name="context">ログに出力するコンテキスト情報(クラス名やメソッド名など)</param>
public static async void ForgetWithHandler(this UniTask task, string context)
{
try
{
await task;
}
catch (OperationCanceledException)
{
// キャンセルは正常系として無視
}
catch (Exception ex)
{
Debug.LogError($"[{context}] Unhandled exception in async operation: {ex.Message}\n{ex.StackTrace}");
}
}

/// <summary>
/// 例外をログ出力しながらForgetする(戻り値あり版)
/// </summary>
/// <typeparam name="T">戻り値の型</typeparam>
/// <param name="task">対象のUniTask</param>
/// <param name="context">ログに出力するコンテキスト情報</param>
public static async void ForgetWithHandler<T>(this UniTask<T> task, string context)
{
try
{
await task;
}
catch (OperationCanceledException)
{
// キャンセルは正常系として無視
}
catch (Exception ex)
{
Debug.LogError($"[{context}] Unhandled exception in async operation: {ex.Message}\n{ex.StackTrace}");
}
}

/// <summary>
/// 例外をカスタムハンドラーで処理しながらForgetする
/// </summary>
/// <param name="task">対象のUniTask</param>
/// <param name="onException">例外発生時のコールバック</param>
public static async void ForgetWithHandler(this UniTask task, Action<Exception> onException)
{
try
{
await task;
}
catch (OperationCanceledException)
{
// キャンセルは正常系として無視
}
catch (Exception ex)
{
onException?.Invoke(ex);
}
}

/// <summary>
/// 例外をカスタムハンドラーで処理しながらForgetする(戻り値あり版)
/// </summary>
/// <typeparam name="T">戻り値の型</typeparam>
/// <param name="task">対象のUniTask</param>
/// <param name="onException">例外発生時のコールバック</param>
public static async void ForgetWithHandler<T>(this UniTask<T> task, Action<Exception> onException)
{
try
{
await task;
}
catch (OperationCanceledException)
{
// キャンセルは正常系として無視
}
catch (Exception ex)
{
onException?.Invoke(ex);
}
}

/// <summary>
/// 例外発生時にフォールバック処理を実行しながらForgetする
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,4 @@ public void Dispose()
}
}
}
}
}
Loading