How zhangyxxyz/hotfixdemo works
Project type and purpose
• This is a Unity3D client application showcasing hot‑update capabilities via XLua (Lua scripts) and AssetBundles.
• It simulates a server by pulling resources from a local directory (C:/LuaServer).
File structure
• “Assets/Plugins” and “Assets/Extend/XLua” contain the XLua native integration, code-gen, examples, and editor tooling.
• “Assets/Scripts” houses the game’s C# modules:
• AssetBundle loading (AssetBundleLoader, Manager, ManifestLoader)
• Scene management (SceneManager)
• Hotfix orchestration (GameInit.cs, LuaManager.cs)
• “Assets/Src/Lua” holds the game’s hotfix scripts (event.lua, main.lua).
• “StreamingAssets/Windows” contains platform‑specific AssetBundles (models, UI, characters).
README for insights
• Confirms a “small hot‑update demo” based on XLua.
• Runtime fetches resources/scripts from a “local simulated server” folder.
Components
a. Unity Client
• Unity Engine runtime (mono/IL2CPP)
• C# application layer (GameInit, LuaManager)
• AssetBundle system (AssetBundleManager, loader classes)
b. XLua Plugin
• Native libs per platform (Android .so, iOS .a, macOS bundle)
• C# bindings (LuaEnv, LuaFunction, LuaTable, generated Wrap classes)
• Editor codegen tools (Generator, LinkXmlGen)
c. Lua Scripts
• Hotfix entrypoint (main.lua → event.lua → game logic)
d. Resource Server (simulated)
• Local filesystem (C:/LuaServer)
• Hosts AssetBundles & Lua scripts
e. StreamingAssets Cache
• Bundles deployed alongside client
Relationships and data flow
• On startup, GameInit → LuaManager initializes LuaEnv.
• AssetBundleManager retrieves manifests from StreamingAssets or remote folder.
• AssetBundleLoader requests bundles, Unity’s WWW/API fetches from “server” path.
• LuaManager loads main.lua via a custom loader, registers C# APIs.
• Lua scripts call into C# via registered functions (e.g., AssetBundleManager, SceneManager).
• Game logic runs in Lua, drawing Unity objects loaded from bundles.
Architectural patterns and principles
• Layered separation:
• Engine layer (Unity core & Mono runtime)
• Plugin layer (XLua native + binding)
• Application layer (C# managers & hotfix orchestrator)
• Scripting layer (Lua hotfix scripts)
• Resource layer (AssetBundles)
• Plugin/Adapter pattern: XLua bridges C# ↔ Lua.
• Hot‑swap pattern: Lua scripts loaded at runtime can override C# behaviour.
• AssetBundle caching & manifest-driven loading.
Essential elements in detail
• File‑based resource sources (StreamingAssets/, C:/LuaServer) as external services.
• Codegen step (XLua Editor → Wrap classes → C# compilation).
• Runtime components: AssetBundleManager, LuaManager, LuaEnv, main.lua.