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 @@ -24,7 +24,7 @@ public override void Setup()
base.Setup();
_keyboard = InputSystem.AddDevice<Keyboard>();
_gamepad = InputSystem.AddDevice<Gamepad>();
_service = new InputSystemService();
_service = new InputSystemService(new LocalizationService());
}

public override void TearDown()
Expand Down Expand Up @@ -56,7 +56,7 @@ public IEnumerator SaveLoadBindingOverrides_RoundTrip_RestoresOverride()
Assert.That(json, Is.Not.Null.And.Not.Empty);

// 別インスタンスへロードして再現
var service2 = new InputSystemService();
var service2 = new InputSystemService(new LocalizationService());
service2.Startup();
yield return null;
service2.LoadBindingOverrides(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ public interface IInputSystemService : IGameService
/// </summary>
InputActionAsset InputActionAsset { get; }

/// <summary>
/// 操作スキーマ変更イベント
/// </summary>
Observable<string> OnControlSchemeChanged { get; }

/// <summary>
/// 操作デバイス切替イベント
/// </summary>
Observable<(InputDevice device, InputDeviceChange deviceChange)> OnDeviceChanged { get; }

/// <summary>
/// キーバインド変更イベント
/// </summary>
Observable<InputAction> OnBindingChanged { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,45 @@
using Game.Shared.Bootstrap;
using Game.Shared.Constants;
using Game.Shared.Input;
using Game.Shared.Localization;
using Game.Shared.Services.Interfaces;
using R3;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.UI;

namespace Game.Core.Services
{
public class InputSystemService : IInputSystemService, IDisposable
{
private readonly ILocalizationService _localizationService;

private ProjectDefaultInputSystem _inputSystem;
private bool _isInitialized;
private string _controlScheme = InputControlSchemes.DefaultControlScheme;
private GameObject _selectedGameObject;

public ProjectDefaultInputSystem.PlayerActions Player => _inputSystem.Player;
public ProjectDefaultInputSystem.UIActions UI => _inputSystem.UI;

public InputActionAsset InputActionAsset => _inputSystem?.asset;

private string _controlScheme = InputControlSchemes.DefaultControlScheme;
private GameObject _selectedGameObject;

private readonly Subject<string> _onControlSchemeChanged = new();
public Observable<string> OnControlSchemeChanged => _onControlSchemeChanged;

public Observable<(InputDevice device, InputDeviceChange deviceChange)> OnDeviceChanged
=> Observable.FromEvent<Action<InputDevice, InputDeviceChange>, (InputDevice, InputDeviceChange)>(
h => (a, b) => h((a, b)),
h => InputSystem.onDeviceChange += h,
h => InputSystem.onDeviceChange -= h);

private readonly Subject<InputAction> _onBindingChanged = new();
public Observable<InputAction> OnBindingChanged => _onBindingChanged;

#region Setup

public InputSystemService()
public InputSystemService(ILocalizationService localizationService)
{
_localizationService = localizationService;
}

public void Startup()
Expand Down Expand Up @@ -112,9 +120,9 @@ public IDisposable BlockInputActions(params InputAction[] actions)

#endregion

public void ResolveSelectable(GameObject selectedGameObject = null)
private void ResolveSelectable(GameObject selectedGameObject = null)
{
var allSelectables = InputSystemHelper.GetAllSelectables();
var allSelectables = GetAllSelectables();
if (allSelectables.Length > 0)
{
GameObject go = null;
Expand Down Expand Up @@ -149,6 +157,22 @@ public void ResolveSelectable(GameObject selectedGameObject = null)
Debug.Log("[InputService] No Selectables found");
}

private static Selectable[] GetAllSelectables()
{
Selectable[] allSelectables = Array.Empty<Selectable>();
int allCount = Selectable.allSelectableCount;
if (allCount > 0)
allSelectables = new Selectable[allCount];
else
return allSelectables;

int count = Selectable.AllSelectablesNoAlloc(allSelectables);
if (count > 0) return allSelectables;

allSelectables = Selectable.allSelectablesArray;
return allSelectables;
}

public GameObject GetSelectedGameObject()
{
return EventSystem.current.currentSelectedGameObject;
Expand Down Expand Up @@ -218,7 +242,7 @@ public string GetBindingDisplayString(string scheme, string actionName, string p
{
// 既定の英語表示・デバイスレイアウト・controlPath を取得し、family 別ローカライズ名へ変換(未登録は英語へフォールバック)
var raw = action.GetBindingDisplayString(index, out var deviceLayoutName, out var controlPath);
parts.Add(InputControlsLocalizer.Localize(deviceLayoutName, controlPath, raw));
parts.Add(_localizationService.GetStringByInputControls(deviceLayoutName, controlPath, raw));
}
return string.Join("/", parts);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Game.Shared.Services;

namespace Game.Core.Services
{
public class LocalizationService : LocalizationServiceBase, IGameService
{
}
}

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
Expand Up @@ -10,7 +10,7 @@ namespace Game.Core.UI
/// 現在のバインド表示と「変更」ボタンを持ち、押下を Observable で通知する。
/// リバインド実行・重複判定などの入力ロジックは持たず、表示更新のみを担う。
/// </summary>
public class InputActionRebindView : MonoBehaviour
public class InputActionRebindingView : MonoBehaviour
{
[Header("Identity")]
[SerializeField] private string _scheme; // コントロールスキーム(Keyboard&Mouse / Gamepad)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SliderIndexSelector : MonoBehaviour
private bool _initialized;

private readonly Subject<int> _onValueChanged = new();
public Observable<int> OnValueChanged => _onValueChanged.AsObservable();
public Observable<int> OnValueChanged => _onValueChanged;

/// <summary>選択中の index。</summary>
public int Index => Mathf.RoundToInt(_slider.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
using Cysharp.Threading.Tasks;
using Game.Core.Services;
using Game.Horror.SaveData;
using Game.Horror.Services;
using Game.Horror.Services.Interfaces;
using Game.MVC.Core.Enums;
using Game.MVC.Core.Scenes;
using Game.Shared.Constants;
using Game.Shared.Extensions;
using Game.Shared.Input;
using Game.Shared.Localization;
using Game.Shared.Services;
using Game.Shared.Services.Interfaces;
using R3;
using UnityEngine;

Expand All @@ -22,6 +20,7 @@ public class HorrorOptionDialog : GameDialogScene<HorrorOptionDialog, HorrorOpti

private IInputSystemService _inputService;
private IAudioService _audioService;
private ILocalizationService _localizationService;

private IHorrorOptionSaveRepository _optionSaveRepository;
private IHorrorOptionService _optionService;
Expand All @@ -43,6 +42,7 @@ public override UniTask PreInitialize()
{
_inputService = GameServiceManager.Resolve<IInputSystemService>();
_audioService = GameServiceManager.Resolve<IAudioService>();
_localizationService = GameServiceManager.Resolve<ILocalizationService>();
_optionSaveRepository = GameServiceManager.Resolve<IHorrorOptionSaveRepository>();
_optionService = GameServiceManager.Resolve<IHorrorOptionService>();
return base.PreInitialize();
Expand Down Expand Up @@ -240,10 +240,10 @@ public override UniTask Startup()
.AddTo(Disposables);

// ロケール変更でバインド表示名を再ローカライズ
LocalizationEvents.OnLocaleChanged.Subscribe(_ => RefreshBindingDisplays()).AddTo(Disposables);
_localizationService.OnLocaleChanged.Subscribe(_ => RefreshBindingDisplays()).AddTo(Disposables);

// コントローラー接続/切替に追従して family 別表示を更新する
InputSystemEvents.OnDeviceChanged.Subscribe(_ => RefreshBindingDisplays()).AddTo(Disposables);
_inputService.OnDeviceChanged.Subscribe(_ => RefreshBindingDisplays()).AddTo(Disposables);

return base.Startup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HorrorOptionDialogComponent : GameSceneComponent
[SerializeField] private SliderBooleanSelector _crouchMode;

[Header("Options - Control")]
[SerializeField] private InputActionRebindView[] _rebindViews;
[SerializeField] private InputActionRebindingView[] _rebindViews;
[SerializeField] private Button _resetKeyboardBindingsButton;
[SerializeField] private Button _resetGamepadBindingsButton;

Expand Down Expand Up @@ -85,7 +85,7 @@ public class HorrorOptionDialogComponent : GameSceneComponent
#region Controls

/// <summary>キーリバインド行(アクション×スキーム単位)。Dialog 側が購読・表示更新する。</summary>
public IReadOnlyList<InputActionRebindView> RebindViews => _rebindViews;
public IReadOnlyList<InputActionRebindingView> RebindViews => _rebindViews;

/// <summary>スキーム別リセットボタン押下。値は対象スキーム(KBM / Gamepad)。</summary>
public Observable<string> OnResetSchemeBindingsRequested => Observable.Merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Game.Core.Services;
using Game.Horror.SaveData;
using Game.MVC.Core.Scenes;
using Game.Shared.Localization;
using Game.Shared.Services;
using Game.Shared.Services.Interfaces;
using R3;
using UnityEngine;

Expand All @@ -27,6 +27,7 @@ public Observable<int> OnSlotSelected
public void SetSlotInfos(IReadOnlyList<HorrorSaveSlotInfo> slots)
{
var database = GameServiceManager.Resolve<IScriptableDatabaseService>().Database;
var localization = GameServiceManager.Resolve<ILocalizationService>();

foreach (var slot in slots)
{
Expand All @@ -42,7 +43,7 @@ public void SetSlotInfos(IReadOnlyList<HorrorSaveSlotInfo> slots)
if (slot.HasData)
{
if (database.HorrorInteractionMasterTable.TryFindById(slot.SavepointId, out var master))
savepointName = InteractionsLocalizer.Localize(master.InteractionLocalizeKey);
savepointName = localization.GetStringByInteractions(master.InteractionLocalizeKey);
else
Debug.LogError($"[{GetType().Name}] HorrorInteractionMaster not found: SavepointId={slot.SavepointId}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Game.Shared.Enums;
using Game.Shared.SaveData;
using Game.Shared.Services;
using Game.Shared.Services.Interfaces;

namespace Game.Horror
{
Expand All @@ -27,6 +28,8 @@ public async UniTask StartupAsync()
// 各種サービス取得・初期化
var assetService = new AddressableAssetService();
GameServiceManager.Register<IAddressableAssetService, AddressableAssetService>(assetService);
var localizationService = new LocalizationService();
GameServiceManager.Register<ILocalizationService, LocalizationService>(localizationService);

var dbService = new ScriptableDatabaseService(assetService);
GameServiceManager.Register<IScriptableDatabaseService, ScriptableDatabaseService>(dbService);
Expand Down Expand Up @@ -58,7 +61,7 @@ public async UniTask StartupAsync()
HorrorOptionHelper.ApplySaveData(optionSaveRepository.Data);

// キーリバインドのオーバーライドを起動時に適用
var inputSystemService = new InputSystemService();
var inputSystemService = new InputSystemService(localizationService);
GameServiceManager.Register<IInputSystemService, InputSystemService>(inputSystemService);
inputSystemService.LoadBindingOverrides(optionSaveRepository.Data.InputBindingOverridesJson);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Game.Shared.Scriptable.Database;
using Game.Shared.Scriptable.Database.Tables;
using Game.Shared.Services;
using Game.Shared.Services.Interfaces;
using UnityEngine;

namespace Game.Horror.Interaction
Expand Down Expand Up @@ -36,6 +37,7 @@ public abstract class InteractableBase : MonoBehaviour, IInteractable
protected IHorrorInteractionService InteractionService { get; private set; }
protected IHorrorInventoryService InventoryService { get; private set; }

private ILocalizationService _localizationService;
private IScriptableDatabaseService _databaseService;
protected ScriptableDatabase Database => _databaseService.Database;

Expand All @@ -54,6 +56,7 @@ protected virtual void Start()
InteractionService = GameServiceManager.Resolve<IHorrorInteractionService>();
InventoryService = GameServiceManager.Resolve<IHorrorInventoryService>();

_localizationService = GameServiceManager.Resolve<ILocalizationService>();
_databaseService = GameServiceManager.Resolve<IScriptableDatabaseService>();
if (_databaseService.Database.HorrorInteractionMasterTable.TryFindById(_interactionId, out var master))
{
Expand Down Expand Up @@ -132,7 +135,7 @@ public UniTask<bool> TryShowRejectionMessage()
if (Master == null || string.IsNullOrEmpty(Master.RejectionMessageLocalizeKey))
return UniTask.FromResult(false);

var message = InteractionMessagesLocalizer.Localize(Master.RejectionMessageLocalizeKey);
var message = _localizationService.GetStringByInteractionMessages(Master.RejectionMessageLocalizeKey);
return HorrorMessageDialog.RunAsync(message);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Game.Core.Services;
using Game.Shared.Enums;
using Game.Shared.Input;
using Game.Shared.Localization;
using Game.Shared.Scriptable.Database.Tables;
using Game.Shared.Services.Interfaces;
using R3;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -44,6 +43,7 @@ public class InteractionPromptView : MonoBehaviour

private HorrorInteractionMaster _master;
private IInputSystemService _inputService;
private ILocalizationService _localizationService;

private Camera _viewCamera;
private bool _interactionToggle;
Expand All @@ -52,15 +52,17 @@ public void Initialize(HorrorInteractionMaster master)
{
_master = master;
_inputService = GameServiceManager.Resolve<IInputSystemService>();
_localizationService = GameServiceManager.Resolve<ILocalizationService>();

LocalizationEvents.OnLocaleChanged.Subscribe(_ => SetInteractionText()).AddTo(this);
_localizationService.OnLocaleChanged.Subscribe(_ => SetInteractionText()).AddTo(this);
SetInteractionText();

_inputService.OnControlSchemeChanged.Subscribe(_ => SetInputBindingText()).AddTo(this);
_inputService.OnDeviceChanged.Subscribe(_ => SetInputBindingText()).AddTo(this);
_inputService.OnBindingChanged
.Where(x => x == _inputService.Player.Interact)
.Subscribe(_ => SetInputBindingText()).AddTo(this);
InputSystemEvents.OnDeviceChanged.Subscribe(_ => SetInputBindingText()).AddTo(this);
.Subscribe(_ => SetInputBindingText())
.AddTo(this);
SetInputBindingText();

_inputTypeRoot.SetActive(master.InputType == InteractionInputType.Hold);
Expand All @@ -71,8 +73,8 @@ public void Initialize(HorrorInteractionMaster master)
private void SetInteractionText()
{
_interactionText.text = !_interactionToggle
? ContextActionsLocalizer.Localize(_master.InteractionVerbLocalizeKey)
: ContextActionsLocalizer.Localize(_master.ReinteractionVerbLocalizeKey);
? _localizationService.GetStringByContextActions(_master.InteractionVerbLocalizeKey)
: _localizationService.GetStringByContextActions(_master.ReinteractionVerbLocalizeKey);
}

private void SetInputBindingText()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Game.Core.Services;
using Game.Shared.Enums;
using Game.Shared.Localization;
using Game.Shared.Services.Interfaces;
using R3;
using TMPro;
using UnityEngine;
Expand All @@ -24,7 +26,10 @@ public class HorrorInventoryContextActionView : MonoBehaviour
public void Initialize(InventoryContextActionType contextAction)
{
if (_label != null)
_label.text = ContextActionsLocalizer.Localize(contextAction.ToString());
{
var localization = GameServiceManager.Resolve<ILocalizationService>();
_label.text = localization.GetStringByContextActions(contextAction.ToString());
}

_button.OnClickAsObservable()
.Subscribe(_ => _onClicked.OnNext(contextAction))
Expand Down
Loading
Loading