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

    安装

    在 Unity Package Manager 中选择 Add package from git URL,然后输入以下地址。

    https://github.com/achieveonepark/AchReactive.git

    或者直接添加到 Packages/manifest.json 中。

    {
      "dependencies": {
        "com.achieve.reactive": "https://github.com/achieveonepark/AchReactive.git"
      }
    }

    环境要求为 Unity 2021.3 以上。依赖只有 com.unity.nuget.newtonsoft-json 一个, 并会自动一起安装。

    1. 实现集成边界

    AchReactive 不会强制你采用特定的游戏结构。只需实现两个接口即可。

    • IEntity — 响应的主体/目标(角色、怪物等)
    • IWorld — 生成/范围查询等世界边界
    using AchReactive;
    using UnityEngine;
    
    public sealed class Character : MonoBehaviour, IEntity
    {
        public StatSheet Stats { get; } = new StatSheet();   // 包提供,直接使用
        public string Id => name;
        public Vector3 Position { get => transform.position; set => transform.position = value; }
        public bool IsAlive => Stats.GetBase(StatKeys.Hp) > 0f;
    
        void Awake()
        {
            Stats.SetBase(StatKeys.Hp, 100f);
            Stats.SetBase(StatKeys.HpMax, 100f);
            Stats.SetBase(StatKeys.Atk, 10f);
            Stats.SetBase(StatKeys.Def, 2f);
        }
    }

    2. 编写数据

    以 reactions 格式的 JSON 来定义技能。(也可以不直接手写,而是用 Data Editor 来制作。)

    [
      {
        "id": "fire_slash",
        "cooldown": 5.0,
        "reactions": [
          {
            "trigger": "on_use",
            "conditions": [{ "type": "alive" }],
            "effects": [
              { "type": "damage", "params": { "power": 1.8 } },
              { "type": "log", "params": { "message": "fire_slash 명중!" } }
            ]
          }
        ]
      }
    ]

    3. 组装与执行

    using AchReactive;
    
    var skills = new DataBase<SkillData>();
    var engine = new ReactionEngine();
    
    void Start()
    {
        // 自动收集动作池(包含默认的 damage/heal/…)
        EffectRegistry.AutoRegister();
        ConditionRegistry.AutoRegister();
        TriggerRegistry.AutoRegister();
    
        // 加载数据 —— 来源自由
        skills.Load(new JsonDataLoader<SkillData>(() => skillsJson.text));
    }
    
    void UseSkill(IEntity caster, IEntity target)
    {
        var ctx = new ReactionContext { Source = caster, Target = target };
        engine.Run("on_use", skills.Get("fire_slash"), ctx);
    }

    damage、heal、add_modifier 等基础 effect 由包提供,因此无需额外代码。 可以在 Samples 的 Basic 示例中直接查看可运行的场景。

    下一步