Skip to content

Repository files navigation

Hex Auto-Battler — Strategy Auto-Battle Demo

一个基于六边形棋盘的策略自走战斗 Demo:在格子上摆放建筑、经营布局,靠策略取胜,战斗全自动进行。

A Unity prototype of a hex-grid strategy auto-battler — place structures on a hexagonal board, build up your layout, and let AI-driven units fight it out automatically. You win by strategy and positioning, not by clicking.

Created Unity Language Status


🎮 What it is

This is a personal game-programming prototype exploring the "deploy → strategize → auto-battle" loop popularized by auto-battlers and roguelike tower-defense games:

  1. Deploy structures (e.g. a cannon tower) onto a hexagonal battlefield.
  2. Strategize — positioning on the hex grid decides who gets attacked, who gets in range, and how fights resolve.
  3. Auto-battle — every unit runs its own AI "brain" (a behavior tree) and fights without player micro-management.

The battle flows through distinct phases:

PreBattle → Strategy → Battle → AfterBattle

✨ Engineering highlights

The interesting part of this project is the from-scratch gameplay framework behind the demo. Everything below is hand-written game code (see Assets/Scripts/):

System What it does Where
Hexagonal grid & coordinates Axial hex coordinate system, hex distance, logic↔view projection (with camera yaw), point-in-cell lookup, and a circular (distance-bounded) map. Battle/BattleField.cs
Behavior-Tree AI ("Brain") A custom behavior tree driving each unit: Action / Controller (Sequence & Selector) / Decorator / Service nodes, a blackboard-style BrainContext, and priority-based interruption so higher-priority behaviors preempt running ones. Tools/BehaviorEditor/ · BrainComp.cs
Game Ability System (GAS-like) A node-graph ability pipeline — Find Target → Damage / Effect / Projectile — authored visually and executed at runtime. Tools/AbilityEditor/
Custom Unity editors Graph editor windows for authoring behavior trees and abilities as node graphs (built on xNode). */Editor/
Component-based units Units composed from AvatarComp, BrainComp, MovementComp; split into CreatureUnit (mobile) and StructureUnit (buildings). Battle/Units/
Attribute system Data-driven stats (MaxHp, Attack, Shield, Speed) with Pure / Value / Rate modifier layering, configured via ScriptableObject. Components/UnitAttrCfg.cs
A* navigation on hex A* pathfinding across the hex grid with per-unit walkability. Systems/NavigationSystem.cs
Core systems Generic Singleton / MonoSingleton, resource loading, camera control, and an event/trigger system. Systems/

🗂️ Project structure

Assets/
├── Scripts/                 ← ★ Hand-written game code
│   ├── GameLogic/
│   │   ├── Battle/          Battlefield, hex map, units & components
│   │   ├── Demo/            Demo bootstrap (spawns the sample battle)
│   │   ├── UI/              HUD / head widgets
│   │   └── Utils/           Logging, hex math, debug drawing
│   ├── Systems/             Singletons, navigation, camera, resources, abilities
│   └── Tools/               ★ Behavior-tree & ability node-graph frameworks + editors
├── Resources/               Prefabs, unit/ability configs, sprites
├── Scenes/                  SampleScene
├── XLua/  xNode/  TextMesh Pro/   ← third-party libraries (see Credits)
└── Plugins/                 native plugins

🚀 Getting started

Requirements: Unity 2022.3 LTS (developed on 2022.3.51f1).

  1. Clone the repo and open the folder as a project in Unity Hub.
  2. Open Assets/Scenes/SampleScene.unity.
  3. Press Play. DemoInstance.StartNewDemoGame() builds the hex field, places a player cannon at the center, and spawns enemy creatures that path in and are engaged automatically.

The first import will take a while as Unity regenerates the Library/ folder (not committed).

🧩 A peek at the demo setup

// Assets/Scripts/GameLogic/Demo/DemoInstance.cs
FieldMapData field = new FieldMapData { mapSize = new Vector2Int(6, 6), mapDistance = 6 };
BattleSession.Instance.battleField.InitField(field);

// Player structure at the center of the hex board
CreateUnit("Structure.S_DemoCannon", new UnitData(CampEnum.Player, new HexCoord(0, 0)));

// Enemy creatures spawn around the rim and path inward
CreateUnit("Creature.M_DemoEnemy", new UnitData(CampEnum.Enemy, new HexCoord(3, 3)));

🛣️ Status & roadmap

This is an early prototype / learning project, not a finished game. Natural next steps:

  • Economy & resource loop for the strategy phase
  • More structure and creature types + a richer ability library
  • Win/lose conditions and wave progression
  • Visual polish and UX for building placement

📜 Credits & licenses

This project bundles third-party libraries so it opens and runs out of the box. All credit to their authors:

  • xLua — Lua scripting / hotfix for Unity (Tencent, MIT). Original license kept as LICENSE.TXT.
  • xNode — node-graph framework the editors are built on (MIT).
  • TextMesh Pro — Unity text rendering.

Original game code under Assets/Scripts/ (excluding the third-party folders above) is authored by me for portfolio purposes.

About

Unity hex-grid strategy auto-battler demo — deploy structures, strategize, and let behavior-tree AI fight it out. Custom BT + node-graph ability system + A* hex pathfinding.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages