找回密码
 立即注册
查看: 899|回复: 0

[热更] u3dchina_Unity_tolua基础教学2_lua调c#

[复制链接]
发表于 2020-3-16 11:59 | 显示全部楼层 |阅读模式
资源信息 Tutorial Information
教程名称: u3dchina_Unity_tolua基础教学2_lua调c#(发帖教程)
适用引擎: Unity3D  (适用引擎,为空默认为Unity)
教程语种: 中文
教程等级: 1
教程格式: 图文(请用IE9以上浏览器访问本版块)
教程作者: 转载自互联网 (如有问题请短消息联系作者或发表回复)
下载地址: (兑换积分)
点击查看原图
美丽分割线
创建一个c# 文件(代码如下):
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using LuaInterface;

  5. public class GameDebugTest : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     void Start()
  9.     {
  10. //创建lua虚拟机
  11.              LuaState  luaState = new LuaState();
  12.         
  13.               //绑定lua虚拟机
  14.               LuaBinder.Bind(luaState);
  15.               luaState.Start();
  16.         string fullPath = Application.dataPath + "\\ToLua/Test";
  17.         luaState.AddSearchPath(fullPath);
  18.               LuaTable lt = luaState.DoFile<LuaTable>( "TestLuaToC.lua");
  19.                //调用lua游戏入口
  20.                lt.Call("GameEnter", lt);
  21.                lt.Dispose();
  22.     }

  23.     // Update is called once per frame
  24.     void Update()
  25.     {

  26.     }

  27.     public static void LogError(object msg)
  28.     {
  29.         Debug.LogError("打印:" + msg.ToString());
  30.     }
  31. }
复制代码
建立一个lua脚本放到Asset/ToLua/Test 中,GameDebugTest.js
  1. local Main={};

  2. local c1,c2;

  3. function Main:GameEnter()
  4.      GameDebugTest.LogError("开始");
  5. end

  6. return  Main;
复制代码
在Assets/Editor/Custom/CustomSetting.js中增加lua对c#的绑定,在 _GT(typeof(SleepTimeout)),后面增加一行                 _GT(typeof(GameDebugTest)),


运行结果:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-26 03:34 , Processed in 0.524863 second(s), 31 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表