For AI agents: the complete documentation index is available at /AchEngine/zh/llms.txt, the full documentation bundle is available at /AchEngine/zh/llms-full.txt, and this page is available as Markdown at /AchEngine/zh/getting-started.md.
  • 简体中文
  • 快速开始

    5 分钟体验 AchEngine 核心功能的指南。

    1. 设置 DI 作用域

    在场景中创建一个空 GameObject,并添加 AchEngineScope 组件。

    Hierarchy
    └── [AchEngineScope]   ← 添加 AchEngineScope 组件

    2. 编写 Installer

    using AchEngine.DI;
    using UnityEngine;
    
    public class GameInstaller : AchEngineInstaller
    {
        public override void Install(IServiceBuilder builder)
        {
            builder
                .Register<IGameService, GameService>()
                .Register<IPlayerService, PlayerService>(ServiceLifetime.Transient);
        }
    }

    把 GameInstaller 拖到 AchEngineScope Inspector 的 Installers 数组中。

    3. 创建 UI Root

    在 Project Settings › AchEngine › UI Workspace 中点击 创建 UI Root 按钮,或在场景中放置 UIRoot 预制体。

    4. 定义 UIView

    using AchEngine.UI;
    
    public class MainMenuView : UIView
    {
        protected override void OnInitialize()
        {
            // 首次创建时调用一次
        }
    
        protected override void OnOpened()
        {
            // Show() 后过渡完成时调用
        }
    
        protected override void OnClosed()
        {
            // Close() 后返回对象池
        }
    }

    5. 显示 View

    // 使用 [Inject](需要 VContainer)
    [Inject] readonly IUIService _ui;
    _ui.Show<MainMenuView>();
    
    // 使用 ServiceLocator(MonoBehaviour 等)
    ServiceLocator.Resolve<IUIService>().Show("MainMenu");
    
    // 关闭
    _ui.Close<MainMenuView>();

    6. 加载表数据

    // 通过 TableManager 类型安全地访问
    var itemTable = TableManager.Get<ItemTable>();
    var sword = itemTable.Get(101);
    Debug.Log(sword.Name); // "Iron Sword"

    后续步骤

    各模块的详细说明请通过左侧边栏查看。