Skip to content
高凯 edited this page Dec 31, 2017 · 1 revision

Editor tool

Initialization
Window -> Lua设置编辑器(Lua Settings Editor) -> Lua项目初始化(Lua project initialization)

Initialization of what to do:

  • Create an export list file to declare which classes will be called by Lua and located in Assets / Script / UI / Editor / Lua / LuaExportList.cs
  • Create a blank LuaBinder file, the file is automatically generated
  • Copy the framework's native Lua library to Resources / LuaLib
  1. LuaDataHelper
  2. LuaStatusManager
  3. LuaUIManager
  4. LuaUpdater
  5. LuaEventDispatcher
  6. LuaJson
  7. LuaPrintTable
  • Lua automatically generated configuration file, which is used to record the Lua file
  • Create a Lua startup file, including a Lua main function, which is called at the beginning of the game
  • Add the precompiled directive USE_LUA
  • Warp initialization

Generate LuaWarp file
Lua设置编辑器 (Lua Settings Editor) -> 重新生成Lua Warp脚本 (Regenerate Lua Warp Script)

Clear LuaWarp file
Lua设置编辑器 (Lua Settings Editor) -> 清除Lua Warp脚本(Clear Lua Warp script)

Rebuild Package Configuration
Lua设置编辑器(Lua Settings Editor) -> 自动生成Lua配置文件(Lua automatically generated configuration file)

API

LuaManager
static void Init () LuaManager initialization (will be automatically called in ApplicatioManager)
static void LoadLua () Load Lua file
static void DoLuaFile (string fileName) Loads the specified Lua file
static void LaunchLua () Launches Lua

LuaStatus
LuaFunction GetFunction (string name, bool beLogMiss = true) Get a Lua function for calling

Example

public class LuaTestStstus: IApplicationStatus
{
    public override void OnEnterStatus ()
    {
        LuaManager.LoadLua ();
        LuaManager.LaunchLua ();
    }
}

public static void LaunchLua ()
{
    //Debug.Log("LaunchLua ");
     try
    {
       s_state.GetFunction ("Main"). Call ();
        s_isUpdate = true;
       s_updateFunction = s_state.GetFunction ("LuaUpdate");
    }
    catch (Exception e)
   {
       Debug.LogError ("Lua Lunch Execption" + e.ToString ());
   }
}

Use Lua to write the UI

  • Toggle 使用Lua(use Lua) in the UI设置编辑器(UI Settings Editor)
  • Override method in automatically generated Lua file, under Resources / Lua / UI /, format is "Lua" + UIWindowName + ".txt"
  1. OnInit
  2. OnOpen
  3. OnClose
  4. EnterAnim
  5. ...

Common cause of Lua startup failure

  1. The USE_LUA macro is not set
  2. No warp or warp file error
  3. No Lua configuration files have been regenerated

Tip

  • The ToLua integration in the framework removes some of the optimizations for Vector3 in ToLua
  • Each time you add a Lua file, remember to regenerate the Lua settings file and update the package settings
  • Warp error code can be emptied Warp rebuild after modifying the code
  • C # and Lua call each other do not directly use the LuaTable class, it is recommended to use Json to pass the message
  • All Lua files use .txt for suffixes in the framework
Clone this wiki locally