How crazychucky/xlua_pro_forked works
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)