Unity 热跟新 simpleframework 学习 ,与Unity的交互,例子1 创建游戏对象

邹山
2023-12-01

simpleframework是 基于unity5.X系列的 热更新 框架。

 

LuaState是 对Lua的一层封装,省去了 加载Lua文件,运行lua文件的步骤。


 luanet.load_assembly('UnityEngine')  加载UnityEngine程序集

GameObject = luanet.import_type('UnityEngine.GameObject')     导入类

local newGameObj = GameObject('NewObj')  实例化对象

 newGameObj:AddComponent(luanet.ctype(ParticleSystem))  调用GameObject里面的AddComponent方法。

上面的步骤  是lua对 UnityEngine的反射。通过lua 取得UnityEngine里的类

lua.DoString(script);   把lua中的代码 在c#里 运行。
 

public class CreateGameObject01 : MonoBehaviour {

    private string script = @"
            luanet.load_assembly('UnityEngine')
            GameObject = luanet.import_type('UnityEngine.GameObject')        
	        ParticleSystem = luanet.import_type('UnityEngine.ParticleSystem')            
            local newGameObj = GameObject('NewObj')
            newGameObj:AddComponent(luanet.ctype(ParticleSystem))
        ";

	//反射调用
	void Start () {
        LuaState lua = new LuaState();
        lua.DoString(script);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

 

 类似资料: