Esempio n. 1
0
    public LuaTable GetScriptEnv(MonoBehaviour view, string luaScript, out string monoName)
    {
        if (string.IsNullOrEmpty(luaScript))
        {
            monoName = string.Empty;
            return(null);
        }
        var      _scriptEnv = luaEnv.NewTable();
        LuaTable meta       = luaEnv.NewTable();

        meta.Set("__index", luaEnv.Global);
        _scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        _scriptEnv.Set("mono", view);
        _scriptEnv.Set("gameObject", view.gameObject);
        _scriptEnv.Set("transform", view.transform);

        monoName = Path.GetFileNameWithoutExtension(luaScript);

        _watch.Restart();
        var luaAsset = CustomLoader(ref luaScript);

        _watch.Stop();
        Logger.Log(string.Format("[lua]{0} LoadLuaSync:{1}ms", monoName, _watch.ElapsedMS()));

        if (luaAsset == null)
        {
            Logger.LogError(string.Format("lua not found:{0}", luaScript));
            return(null);
        }
        luaEnv.DoString(luaAsset, monoName, _scriptEnv); //返回luatable
        return(_scriptEnv);
    }