slua学习记录(一)
来源:互联网 发布:java split用法 编辑:程序博客网 时间:2024/05/22 01:40
1.导入插件后 Slua/LuaObject文件夹下的文件全部为生成文件,生成方式为菜单中Slua -> All -> Make(每次Make之前最好先Clear一次)
2.unity - lua交互过程中的文件有:unity C#脚本(自写),LuaObject文件夹下的Lua_C#文件名的脚本(生成),对应的lua脚本(自写)
3.若想在lua中调用C#类,需在C#类中加入[CustomLuaClass]或[CustomLuaClassAttribute]属性
如:
[CustomLuaClass]
public class Deleg : MonoBehaviour
4.lua与C#互调并简单交互
如:只需建立一个新场景在场景中添加一个Button(UGUI),随便给一个游戏对象绑定LzdTest脚本即可运行
(C#)
2.unity - lua交互过程中的文件有:unity C#脚本(自写),LuaObject文件夹下的Lua_C#文件名的脚本(生成),对应的lua脚本(自写)
3.若想在lua中调用C#类,需在C#类中加入[CustomLuaClass]或[CustomLuaClassAttribute]属性
如:
[CustomLuaClass]
public class Deleg : MonoBehaviour
4.lua与C#互调并简单交互
如:只需建立一个新场景在场景中添加一个Button(UGUI),随便给一个游戏对象绑定LzdTest脚本即可运行
(C#)
using UnityEngine;using System.Collections;using SLua;using System;using LuaInterface;[CustomLuaClass]public class LzdTest : MonoBehaviour {//this is a delegatepublic delegate void LzdTestDelegate(string path, GameObject g);static public LzdTestDelegate lzd;LuaSvr l;LuaTable self;LuaFunction update;void Start(){l = new LuaSvr();l.init(null,()=>{self = (LuaTable)l.start("lzdtest");update = (LuaFunction)self["update"];//C# call luastring str = (string)l.luaState.getFunction ("lzdFunc").call ("hello world");Debug.Log (str);});}void Update () {//call lua “update” function in Updateif(update!=null) update.call(self);}static public void callD(){//call delegate functionif (lzd != null)lzd("GameObject", new GameObject("SimpleDelegate"));Debug.Log ("callD");}//lua call C#public void luaCallCS(string wtf){Debug.Log (wtf);}}
(Lua)
import "UnityEngine"if not UnityEngine.GameObject thenerror("Click Make/All to generate lua wrap file")endlocal class={}function main()print("run lua main function")local cs = GameObject.Find("Main Camera")--If your class does not inheritance MonoBehaviour,you can write like this : --local h=LzdTest()--h.luaCallCS("wtf")local te = cs:GetComponent("LzdTest")te:luaCallCS("wtf")local g;--test delegateLzdTest.lzd=function(path,go)g = goprint(path,go.name)endLzdTest.callD()-- test gameobjectprint(g.name)print(cs.name)g.transform.parent = cs.transformg:AddComponent(UnityEngine.Rigidbody)g:AddComponent(UnityEngine.BoxCollider)local c=g:AddComponent(UnityEngine.MeshRenderer)c.probeAnchor = cs.transform-- test UIlocal obj = GameObject.Find("Canvas/Button")local btn = obj:GetComponent("Button")local num = 0btn.onClick:AddListener(function()num = num+1print(" click btn ,","num = ",num)end)--if you want to use update function,you need return class return classendfunction lzdFunc(a)HelloWorld.nullf(1)HelloWorld.nullf()print("run this function")local name = " lzd"a = a..namereturn aend-- use update on luafunction class:update()print(Time.deltaTime)end
0 0
- slua学习记录(一)
- mysql学习记录 一
- c 学习记录 一
- PhysX学习记录 一
- 学习记录一
- WCF学习记录一
- 学习记录(一)
- CoreData学习记录一
- StoryBoard学习记录一
- PhysX学习记录 一
- Ajax学习记录一
- NFC学习记录一
- netty 学习记录一
- 学习历程记录一
- Java4Android学习记录一
- Android学习记录 一
- 学习记录(一)
- turbogears学习记录(一)
- Android MediaPlayer
- POJ 2451 (半平面交 板子题)
- from表单传值到页面,并在iframe中显示该页面,通过form的target属性指定iframe
- el表达式获取url中文参数乱码
- http协议
- slua学习记录(一)
- ReboundScrollView 仿IOS 拖拽回弹
- vs2010编译最新live555
- Android代码混淆
- 文件系统的安全性
- 生活总结
- Ubuntu 14.04更新软件提示W: GPG error: http://archive.ubuntukylin.com:10006 xenial InRelease
- 环信集成流程说明
- Android Studio中学习Android Activity