# crazychucky/xlua_pro_forked architecture

> Architecture diagram of the GitHub repository crazychucky/xlua_pro_forked, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/crazychucky/xlua_pro_forked
- Repository: https://github.com/crazychucky/xlua_pro_forked

## Overview

##### Project type and purpose
- This is a Unity3D game framework (“UnityXLuaPro”) that uses XLua to drive all game-application logic in Lua, while retaining a stable C# “engine layer.”
- It targets single-player ARPGs and provides editor extensions and build tools for asset-bundle workflows.

##### Main components
a. Editor-time / Build pipeline
- Unity Editor + Editor Extensions (Assets/Editor)
– BuildOneTexturePacker.cs, BuildTexturePacker.cs, SpritesPacker.cs: automate texture atlas creation
– LuaFileToTxt.cs: convert .lua → .lua.txt so scripts can be packaged as AssetBundles
- External Tools (tools/TexturePacker, tools/Lua-Simple-XML-Parser, code/XLuaGame/Tools)
– TexturePacker.exe: generate sprite atlases
– XLuaGenerate.exe, XLuaHotfixInject.exe, FilesSignature.exe: generate glue code, inject hotfixes, sign files
- Asset Package Sources
– Assets/AssetPackage: local art assets, prefabs, models, audio, GUI
– code/XLuaGame/AssetBundles: output of AB build, later can be migrated to a remote asset server

b. Runtime components
- Unity Core Engine (C#)
– Assets/EngineScripts/Core
- GameEngine.cs: core update loop, initialization
- GameApplication.cs: entry point for the Lua “application”
- ResMgr.cs: AssetBundle/Resource loader
- CameraFollow.cs: generic camera behavior
– Assets/EngineScripts/GameDriver.cs: bootstraps GameEngine & GameApplication
– Assets/EngineScripts/GameView & UI: ActorBase.cs, UIBase.cs, UIManager.cs, UIComponentInput.cs
– Assets/EngineScripts/Common & Utils: LuaHelper, LuaResHelper, LuaUIHelper, Singleton, Timer, etc.
- XLua Plugin
– Native libraries under Assets/Plugins (iOS, Android, WebGL, WSA, MacOS, Windows)
– C# bindings in Assets/XLua/Src & Gen (LuaEnv, LuaFunction, DelegateBridge, ObjectTranslator, generated wrappers)
- Lua Application Layer
– Assets/LuaScripts/Main.lua: entry script
– Assets/LuaScripts/Common: OOP base class, Constants, DataCenter, Define, Event, SettingCfg, Helpers
– Assets/LuaScripts/GameLogic: pure-Lua game logic modules (battle, entities, skills, scene manager, FSM)
– Assets/LuaScripts/GameView: Lua-side view controllers for actors and UI panels, driven by C# lifecycles
– Assets/LuaScripts/Utils: JSON, general utilities

##### Relationships and data flows
- Build tools → generate AssetBundles under code/XLuaGame/AssetBundles → Unity’s StreamingAssets/AssetBundles at build output.
- Unity Editor uses Editor Extensions + TexturePacker → populate code/XLuaGame/AssetBundles; developer tests in Editor.
- At runtime: GameDriver → GameEngine → GameApplication initializes LuaEnv → executes Main.lua.
- Lua “requires” modules (Common, GameLogic, GameView, Utils), uses XLua to call C# functions (via LuaHelper, bound functions).
- C# ResMgr loads assets from StreamingAssets or from remote server if configured.
- Lua logic updates game state, issues commands to C# view classes (ActorBase, UIBase) to display entities/UI.

##### Architectural patterns and design principles
- Layered architecture:
1. Editor/Tooling
2. Engine layer (C#) = Services + View + Utilities
3. Scripting layer (Lua) = Application logic + Model + Controller
- Plugin pattern: XLua integrates the scripting engine, generates glue code, and exposes C# APIs to Lua.
- MVC-style separation:
– Model & Controller in Lua (GameLogic, DataCenter, Event)
– View in C# (ActorBase, UIBase) with Lua view controllers

##### Technologies and frameworks
- Unity 2021.3 LTS
- XLua (C# & native libs)
- AssetBundles & StreamingAssets
- TexturePacker for sprite atlas generation
- DOTween (tweening), AssetBundle Browser (editor plugin)
- Custom build tools: XLuaGenerate, XLuaHotfixInject

##### Detail level
- Subcomponents for clarity (e.g., under LuaScripts split into Common, GameLogic, GameView)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build-time Pipeline
    subgraph "Build-time Pipeline"
        classDef build fill:#AED6F1,stroke:#000;

        EditorExt["Unity Editor + Editor Extensions\n(Assets/Editor)"]:::build
        ExternalTools["XLua code-gen & signing\n(code/XLuaGame/Tools)"]:::build
        TextureP["TexturePacker.exe\n(tools/TexturePacker/bin)"]:::build
        AssetSrc["Local Assets\n(Assets/AssetPackage)"]:::build
        ABOut["AssetBundle Output\n(code/XLuaGame/AssetBundles)"]:::build

        EditorExt --> ABOut
        ExternalTools --> ABOut
        TextureP --> ABOut
        AssetSrc --> ABOut
    end

    %% Runtime Architecture
    subgraph "Runtime Architecture"
        classDef engine fill:#ABEBC6,stroke:#000;
        classDef lua fill:#F9E79F,stroke:#000;
        classDef external fill:#D5D8DC,stroke:#000;

        subgraph "Engine Layer (C#)"
            GameDriver["GameDriver\n(Assets/EngineScripts/GameDriver.cs)"]:::engine
            GameEngine["GameEngine\n(Assets/EngineScripts/Core/GameEngine.cs)"]:::engine
            GameApp["GameApplication\n(Assets/EngineScripts/Core/GameApplication.cs)"]:::engine
            ResMgr["ResMgr\n(Assets/EngineScripts/Core/ResMgr.cs)"]:::engine
            Camera["CameraFollow\n(Assets/EngineScripts/Core/CameraFollow.cs)"]:::engine
            ActorBase["ActorBase, UIBase, UIManager, UIInput\n(Assets/EngineScripts/GameView)"]:::engine
            Utils["Utilities & Helpers\n(Assets/EngineScripts/Utils & Common)"]:::engine

            GameDriver --> GameEngine --> GameApp
            GameEngine --> ResMgr
            GameEngine --> Camera
            GameEngine --> ActorBase
            GameEngine --> Utils
        end

        subgraph "XLua Plugin"
            Native["Native Libs\n(Assets/Plugins/*)"]:::external
            Bindings["C# Bindings & Generated Code\n(Assets/XLua/Src & Gen)"]:::external

            Native --> Bindings
            GameApp --> Bindings
        end

        subgraph "Lua Scripting Layer"
            MainLua["Main.lua\n(Assets/LuaScripts/Main.lua)"]:::lua
            LuaCommon["Common Modules\n(Assets/LuaScripts/Common)"]:::lua
            LuaLogic["GameLogic Modules\n(Assets/LuaScripts/GameLogic)"]:::lua
            LuaView["Lua View Controllers\n(Assets/LuaScripts/GameView)"]:::lua
            LuaUtils["Lua Utilities\n(Assets/LuaScripts/Utils)"]:::lua

            GameApp --> MainLua
            MainLua --> LuaCommon
            MainLua --> LuaLogic
            MainLua --> LuaView
            MainLua --> LuaUtils
        end

        Streaming["StreamingAssets\n(Assets/StreamingAssets)"]:::engine
        ABOut --> Streaming
        ResMgr --> Streaming
    end

    %% Click Events
    click EditorExt "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/Editor"
    click ExternalTools "https://github.com/crazychucky/xlua_pro_forked/tree/master/code/XLuaGame/Tools"
    click TextureP "https://github.com/crazychucky/xlua_pro_forked/blob/master/tools/TexturePacker/bin/TexturePacker.exe"
    click AssetSrc "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/AssetPackage"
    click ABOut "https://github.com/crazychucky/xlua_pro_forked/tree/master/code/XLuaGame/AssetBundles"
    click GameDriver "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/GameDriver.cs"
    click GameEngine "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Core/GameEngine.cs"
    click GameApp "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Core/GameApplication.cs"
    click ResMgr "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Core/ResMgr.cs"
    click Camera "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Core/CameraFollow.cs"
    click ActorBase "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/GameView/ActorBase.cs"
    click ActorBase "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/GameView/UIBase.cs"
    click ActorBase "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/GameView/UIManager.cs"
    click ActorBase "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/GameView/UIComponentInput.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Utils/Singleton.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Utils/Timer.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Utils/UtilTools.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Common/LuaHelper/LuaHelper.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Common/LuaHelper/LuaResHelper.cs"
    click Utils "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/EngineScripts/Common/LuaHelper/LuaUIHelper.cs"
    click Native "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/Plugins"
    click Bindings "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/XLua/Src/LuaEnv.cs"
    click Bindings "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/XLua/Src/LuaFunction.cs"
    click Bindings "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/XLua/Src/DelegateBridge.cs"
    click Bindings "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/XLua/Src/ObjectTranslator.cs"
    click Bindings "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/XLua/Gen/XLuaGenAutoRegister.cs"
    click MainLua "https://github.com/crazychucky/xlua_pro_forked/blob/master/Assets/LuaScripts/Main.lua"
    click LuaCommon "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/LuaScripts/Common"
    click LuaLogic "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/LuaScripts/GameLogic"
    click LuaView "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/LuaScripts/GameView"
    click LuaUtils "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/LuaScripts/Utils"
    click Streaming "https://github.com/crazychucky/xlua_pro_forked/tree/master/Assets/StreamingAssets"
```
