> For AI agents: the complete documentation index is available at /AchEngine/en/llms.txt, the full documentation bundle is available at /AchEngine/en/llms-full.txt.

# Module Integration

This guide combines DI, Table Loader, Localization, Addressables, and UI into one gameplay flow.

## Overall structure

```mermaid
graph TB
subgraph Bootstrap["Bootstrap scene"]
GI[GlobalInstaller]
GI --> TS[ITableService]
GI --> UI[IUIService]
GI --> AU[IAudioService]
GI --> NW[INetworkService]
UIR[UIRoot]
end
subgraph Lobby["Lobby scene (additive)"]
LI[LobbyInstaller]
LI --> SH[IShopService]
LI --> FR[IFriendService]
end
subgraph InGame["InGame scene (additive)"]
GAI[GameInstaller]
GAI --> GM[IGameService]
GAI --> ST[IStageService]
GAI --> ES[IEnemySpawner]
end
Bootstrap --> Lobby
Bootstrap --> InGame
```

## Table Loader + Localization

Store localization keys in the table instead of translated text:

```text
| Id  | NameKey           | DescKey           | Price |
|-----|-------------------|-------------------|-------|
| 101 | item.sword.name   | item.sword.desc   | 500   |
| 102 | item.wand.name    | item.wand.desc    | 1200  |
```

```csharp
public void SetItem(int itemId)
{
    var item = TableManager.Get<ItemTable>().Get(itemId);
    _nameText.text = LocalizationManager.Get(item.NameKey);
    _descText.text = LocalizationManager.Get(item.DescKey);
    _priceText.text = $"{item.Price:N0} G";
}
```

After key generation, use `L.Item.Sword.Name` for fixed keys or keep the table key for dynamic content.

## Table Loader + Addressables

Store `IconAddress` and `SfxAddress` in the table, load the asset when the view opens, and release it when the view closes.

```csharp
private string _loadedAddress;

public async void SetItem(int itemId)
{
    var item = TableManager.Get<ItemTable>().Get(itemId);
    if (_loadedAddress != null)
        AddressableManager.Release(_loadedAddress);

    _loadedAddress = item.IconAddress;
    _iconImage.sprite = await AddressableManager.LoadAsync<Sprite>(_loadedAddress);
}

protected override void OnClosed()
{
    if (_loadedAddress == null) return;
    AddressableManager.Release(_loadedAddress);
    _loadedAddress = null;
}
```

## Three-module example

When opening an item popup, read the table row, resolve localized text, and load the icon asynchronously:

```csharp
public async void SetItem(int itemId)
{
    var item = TableManager.Get<ItemTable>().Get(itemId);
    _nameText.text = LocalizationManager.Get(item.NameKey);
    _descText.text = LocalizationManager.Get(item.DescKey);
    _iconImage.sprite = await AddressableManager.LoadAsync<Sprite>(item.IconAddress);
}
```

## DI service layer

Wrap static managers behind an interface when a service needs to be unit-tested:

```csharp
public interface IItemService
{
    ItemData GetItem(int id);
    string GetItemName(int id);
}

public class ItemService : IItemService
{
    private readonly ITableService _tables;
    private readonly ILocalizationService _localization;

    public ItemService(ITableService tables, ILocalizationService localization)
    {
        _tables = tables;
        _localization = localization;
    }

    public ItemData GetItem(int id) => _tables.Get<ItemTable>().Get(id);
    public string GetItemName(int id) => _localization.Get(GetItem(id).NameKey);
}
```

Register `ITableService`, `ILocalizationService`, and `IItemService` in the global installer, then inject `IItemService` into views or game services.

## Scene transition + UI flow

```mermaid
sequenceDiagram
participant App as App start
participant Boot as Bootstrap scene
participant SL as ServiceLocator
participant SS as SceneService
participant GS as GameService
participant UI as IUIService
participant TBL as TableManager
participant LOC as LocalizationManager
participant ADDR as AddressableManager
App->>Boot: Load scene
Boot->>SL: Setup global services
SS->>UI: CloseAll()
SS->>Boot: Unload Lobby
SS->>Boot: Load InGame
SS->>GS: StartStage(stageId)
GS->>TBL: Get stage data
GS->>UI: Show<GameHUDView>()
UI->>TBL: Get item data
TBL-->>UI: ItemData
UI->>LOC: Get(NameKey)
UI->>ADDR: LoadAsync<Sprite>(IconAddress)
```

## Related docs

- [DI system](/AchEngine/en/usage/di/index.md)
- [Table Loader](/AchEngine/en/usage/table/index.md)
- [Localization](/AchEngine/en/usage/localization/index.md)
- [Addressables](/AchEngine/en/usage/addressables/index.md)
