Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion docker/unity-ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FROM unityci/editor:ubuntu-${UNITY_VERSION}-${UNITY_MODULE}-${IMAGE_VERSION}
# Build arguments
ARG UNITY_VERSION
ARG UNITY_MODULE
ARG RUNNER_VERSION=2.334.0
ARG RUNNER_VERSION=2.335.1
ARG DEBIAN_FRONTEND=noninteractive

# Labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ public UniTask Ready()
return UniTask.CompletedTask;
}

public UniTask Sleep()
public UniTask Sleep(bool visible)
{
SleepCalled = true;
return UniTask.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task SetLastSavepoint_SameId_DoesNotMarkDirty()
{
await LoadDefaultData();
_service.SetLastSavepoint(10);
await _repository.SaveAsync();
await _repository.SaveBySlotAsync(0);
Assert.That(_repository.IsDirty, Is.False);

_service.SetLastSavepoint(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Game.Tests.MVC.Horror
[TestFixture]
public class HorrorSaveRepositoryTests
{
private const string SaveKey = "horror_save_slot1";
private const string SaveKey = "horror_save_slot0";

private ISaveDataStorage _mockStorage;
private IScriptableDatabaseService _mockDatabase;
Expand Down Expand Up @@ -186,7 +186,7 @@ public async Task SaveToSlotAsync_WithValidSlot_SavesToSlotKeyAndWritesMeta()
.Returns(UniTask.CompletedTask);
_repository.Data.Player.LastSavepointId = 42;

await _repository.SaveToSlotAsync(3);
await _repository.SaveBySlotAsync(3);

Assert.That(_repository.CurrentSlot, Is.EqualTo(3));
Assert.That(_repository.Data.SlotNo, Is.EqualTo(3));
Expand All @@ -197,16 +197,16 @@ await _mockStorage.Received(1).SaveAsync(
Arg.Is<HorrorSaveData>(d => d.SlotNo == 3 && d.SavepointId == 42));
}

[TestCase(0)]
[TestCase(11)]
[TestCase(-1)]
[TestCase(10)]
public async Task SaveToSlotAsync_WithSlotOutOfRange_DoesNotSave(int slotNumber)
{
await LoadDefaultData();
LogAssert.Expect(LogType.Error, new Regex("Invalid slot number"));

await _repository.SaveToSlotAsync(slotNumber);
await _repository.SaveBySlotAsync(slotNumber);

Assert.That(_repository.CurrentSlot, Is.EqualTo(1));
Assert.That(_repository.CurrentSlot, Is.EqualTo(-1));
await _mockStorage.DidNotReceive().SaveAsync(Arg.Any<string>(), Arg.Any<HorrorSaveData>());
}

Expand All @@ -218,8 +218,8 @@ public async Task LoadSlotInfosAsync_WhenSlotEmpty_ReturnsHasDataFalse()

var infos = await _repository.LoadSlotInfosAsync();

Assert.That(infos.Count, Is.EqualTo(HorrorSaveConstants.MaxSaveSlotCount));
Assert.That(infos[0].SlotNo, Is.EqualTo(1));
Assert.That(infos.Length, Is.EqualTo(HorrorSaveConstants.MaxSaveSlotCount));
Assert.That(infos[0].SlotNo, Is.EqualTo(0));
Assert.That(infos[0].HasData, Is.False);
}

Expand All @@ -234,7 +234,7 @@ public async Task LoadSlotInfosAsync_WhenSlotHasData_ReturnsMeta()

var infos = await _repository.LoadSlotInfosAsync();

var info = infos[2];
var info = infos[3];
Assert.That(info.SlotNo, Is.EqualTo(3));
Assert.That(info.HasData, Is.True);
Assert.That(info.SavedAtUtc, Is.EqualTo(savedAt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public async UniTask TransitionPrevAsync()
// モックではフォールバック遷移は行わない
}

public async UniTask<TResult> TransitionDialogAsync<TScene, TResult>() where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
public async UniTask<TResult> TransitionDialogAsync<TScene, TResult>(bool visibleLastScene) where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
{
var type = typeof(TScene);
if (IsProcessing(type))
Expand All @@ -172,7 +172,7 @@ public async UniTask TransitionPrevAsync()
return await ResultAsync(gameScene, tcs);
}

public async UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg) where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
public async UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg, bool visibleLastScene) where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
{
var type = typeof(TScene);
if (IsProcessing(type))
Expand Down Expand Up @@ -248,7 +248,7 @@ private async UniTask CurrentSceneOperationAsync(GameSceneOperations operations)
{
if (operations.HasFlag(GameSceneOperations.Sleep))
{
await SleepAsync();
await SleepAsync(false);
}
else if (operations.HasFlag(GameSceneOperations.Restart))
{
Expand Down Expand Up @@ -330,13 +330,13 @@ private async UniTask TerminateAsync(IGameScene gameScene, bool clearHistory = f
}
}

private UniTask SleepAsync()
private UniTask SleepAsync(bool visible)
{
if (_gameScenes.Count == 0) return UniTask.CompletedTask;

var gameScene = _gameScenes[^1];
gameScene.State = GameSceneState.Sleep;
return gameScene.Sleep();
return gameScene.Sleep(visible);
}

private UniTask RestartAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IGameScene : IGameSceneState, IGameSceneArgHandler, ICompositeD
// シーン起動後に演出など
UniTask Ready() => UniTask.CompletedTask;

UniTask Sleep() => UniTask.CompletedTask;
UniTask Sleep(bool visible) => UniTask.CompletedTask;

UniTask Restart() => UniTask.CompletedTask;

Expand All @@ -53,7 +53,7 @@ public abstract class GameScene : IGameScene

public virtual UniTask Startup() => UniTask.CompletedTask;

public virtual UniTask Sleep() => UniTask.CompletedTask;
public virtual UniTask Sleep(bool visible) => UniTask.CompletedTask;

public virtual UniTask Restart() => UniTask.CompletedTask;

Expand Down Expand Up @@ -146,10 +146,10 @@ public override async UniTask Ready()
await base.Ready();
}

public override async UniTask Sleep()
public override async UniTask Sleep(bool visible)
{
await SceneComponent.Sleep();
await base.Sleep();
await SceneComponent.Sleep(visible);
await base.Sleep(visible);
}

public override async UniTask Restart()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using Cysharp.Threading.Tasks;
using Game.Core.Services;
using Game.Shared.Services;
using R3;
using UnityEngine;
using UnityEngine.UI;

namespace Game.MVC.Core.Scenes
{
Expand All @@ -14,7 +12,7 @@ public interface IGameSceneComponent : ICompositeDisposable

UniTask Ready() => UniTask.CompletedTask;

UniTask Sleep() => UniTask.CompletedTask;
UniTask Sleep(bool visible) => UniTask.CompletedTask;

UniTask Restart() => UniTask.CompletedTask;

Expand All @@ -24,9 +22,7 @@ public interface IGameSceneComponent : ICompositeDisposable
[RequireComponent(typeof(CanvasGroup))]
public abstract class GameSceneComponent : MonoBehaviour, IGameSceneComponent
{
private IInputSystemService _inputService;
private IInputSystemService InputService => _inputService ??= GameServiceManager.Resolve<IInputSystemService>();

private readonly IInputSystemService _inputService = GameServiceManager.Resolve<IInputSystemService>();
private GameObject _selectedGameObject;

public CompositeDisposable Disposables { get; } = new();
Expand All @@ -36,9 +32,9 @@ public virtual UniTask Startup()
return UniTask.CompletedTask;
}

public virtual UniTask Sleep()
public virtual UniTask Sleep(bool visible)
{
return Unfocus();
return Unfocus(visible);
}

public virtual UniTask Restart()
Expand All @@ -62,17 +58,20 @@ private async UniTask Focus()
{
SetInteractable(true);
await UniTask.Yield();
InputService.ResolveControlScheme(_selectedGameObject);
ResolveSelectable();
}

private async UniTask Unfocus()
private async UniTask Unfocus(bool visible)
{
_selectedGameObject = InputService.GetSelectedGameObject();
_selectedGameObject = _inputService.GetSelectedGameObject();
await UniTask.Yield();
SetInteractable(false);
SetInteractable(false, visible);
}

public virtual void SetInteractable(bool interactable)
protected void ResolveSelectable()
=> _inputService.ResolveControlScheme(_selectedGameObject);

public virtual void SetInteractable(bool interactable, bool visible = false)
{
if (TryGetComponent<CanvasGroup>(out var canvasGroup))
{
Expand All @@ -84,17 +83,17 @@ public virtual void SetInteractable(bool interactable)
}
else
{
canvasGroup.alpha = 0f;
canvasGroup.alpha = visible ? 1f : 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
}
}
}

// public IDisposable BlockInteractable()
// public IDisposable BlockInteractable(bool visible = false)
// {
// SetInteractable(false);
// return Disposable.Create(() => SetInteractable(true));
// SetInteractable(false, visible);
// return Disposable.Create(() => SetInteractable(true, visible));
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ UniTask<TResult> TransitionAsync<TScene, TArg, TResult>(TArg arg, GameSceneOpera
/// <typeparam name="TScene">ダイアログシーン型</typeparam>
/// <typeparam name="TResult">戻り値の型</typeparam>
/// <returns>ダイアログの結果</returns>
UniTask<TResult> TransitionDialogAsync<TScene, TResult>()
UniTask<TResult> TransitionDialogAsync<TScene, TResult>(bool visibleLastScene = false)
where TScene : class, IGameScene, IGameSceneResult<TResult>, new();

/// <summary>
Expand All @@ -73,8 +73,9 @@ UniTask<TResult> TransitionDialogAsync<TScene, TResult>()
/// <typeparam name="TArg">引数型</typeparam>
/// <typeparam name="TResult">戻り値の型</typeparam>
/// <param name="arg">引数</param>
/// <param name="visibleLastScene">前のシーンを隠すか</param>
/// <returns>ダイアログの結果</returns>
UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg)
UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg, bool visibleLastScene = false)
where TScene : class, IGameScene, IGameSceneResult<TResult>, new();

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public async UniTask TransitionPrevAsync()
}
}

public async UniTask<TResult> TransitionDialogAsync<TScene, TResult>()
public async UniTask<TResult> TransitionDialogAsync<TScene, TResult>(bool visibleLastScene = false)
where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
{
if (IsProcessing(typeof(TScene))) return default;

await using (await ScopedSleepAsync())
await using (await BlockLastSceneAsync(visibleLastScene))
{
var gameScene = new TScene();
var tcs = CreateResultTcs<TResult>(gameScene);
Expand All @@ -123,15 +123,15 @@ public async UniTask<TResult> TransitionDialogAsync<TScene, TResult>()
}
}

public async UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg)
public async UniTask<TResult> TransitionDialogAsync<TScene, TArg, TResult>(TArg arg, bool visibleLastScene = false)
where TScene : class, IGameScene, IGameSceneResult<TResult>, new()
{
// ダイアログは複数開く事ができる
// Memo: ダイアログはプロセス中に同一ダイアログを再度要求されたら無視する
if (IsProcessing(typeof(TScene))) return default;

// WARN: MonoBehaviourをnewしない方向で実装する必要がある…
await using (await ScopedSleepAsync())
await using (await BlockLastSceneAsync(visibleLastScene))
{
var gameScene = new TScene();
CreateArgHandler(gameScene, arg);
Expand All @@ -150,7 +150,7 @@ private async UniTask ResolveOperationAsync(GameSceneOperations operations = Def

if (operations.HasFlag(GameSceneOperations.Sleep))
{
await SleepAsync();
await SleepAsync(false);
}
else if (operations.HasFlag(GameSceneOperations.Restart))
{
Expand Down Expand Up @@ -234,13 +234,13 @@ public bool IsProcessing(Type type)
return gameScene.GetType() == type && gameScene.State is GameSceneState.Processing;
}

private UniTask SleepAsync()
private UniTask SleepAsync(bool visible)
{
if (_gameScenes.Count == 0) return UniTask.CompletedTask;

var gameScene = _gameScenes[^1];
gameScene.State = GameSceneState.Sleep;
return gameScene.Sleep();
return gameScene.Sleep(visible);
}

private UniTask RestartAsync()
Expand Down Expand Up @@ -340,7 +340,7 @@ private int FindLastIndexByType(Type type)
return -1;
}

private async UniTask<IAsyncDisposable> ScopedSleepAsync()
private async UniTask<IAsyncDisposable> BlockLastSceneAsync(bool visibleLastScene = false)
{
if (_gameScenes.Count == 0)
return new EmptyAsyncDisposable();
Expand All @@ -349,7 +349,7 @@ private async UniTask<IAsyncDisposable> ScopedSleepAsync()
if (lastScene.State is GameSceneState.Processing)
{
lastScene.State = GameSceneState.Sleep;
await lastScene.Sleep();
await lastScene.Sleep(visibleLastScene);
}

return AsyncDisposable.Create(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void ResolveSelectable(GameObject selectedGameObject = null)
GameObject go = null;
bool found = false;

if (selectedGameObject != null)
if (selectedGameObject != null && selectedGameObject.activeSelf)
{
foreach (var selectable in allSelectables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class PointerEventReceiver : MonoBehaviour
[SerializeField] private Selectable _selectable;

private IInputSystemService _inputService;
private IInputSystemService InputService => _inputService ??= GameServiceManager.Resolve<IInputSystemService>();

public void OnPointerEnter(PointerEventData eventData) => OnSelect();

Expand All @@ -31,7 +30,11 @@ private void OnPress(PointerEventData eventData)
OnSelect();
}

private void OnSelect() => InputService.SetSelectedGameObject(_selectable.gameObject);
private void OnSelect()
{
_inputService ??= GameServiceManager.Resolve<IInputSystemService>();
_inputService.SetSelectedGameObject(_selectable.gameObject);
}

#if UNITY_EDITOR
private void OnValidate()
Expand Down
Loading
Loading