美文网首页
ToLua的Example示例学习笔记12_TestGameOb

ToLua的Example示例学习笔记12_TestGameOb

作者: 凌枫望星月 | 来源:发表于2020-05-12 22:46 被阅读0次

展示了Lua对GameObject的操作。

1」代码

操作代码如下:

            local Color = UnityEngine.Color
            local GameObject = UnityEngine.GameObject
            local ParticleSystem = UnityEngine.ParticleSystem 

            function OnComplete()
                print('OnComplete CallBack')
            end                       
            
            local go = GameObject('go')
            go:AddComponent(typeof(ParticleSystem))
            local node = go.transform
            node.position = Vector3.one                  
            print('gameObject is: '..tostring(go))                 
            --go.transform:DOPath({Vector3.zero, Vector3.one * 10}, 1, DG.Tweening.PathType.Linear, DG.Tweening.PathMode.Full3D, 10, nil)
            --go.transform:DORotate(Vector3(0,0,360), 2, DG.Tweening.RotateMode.FastBeyond360):OnComplete(OnComplete)            
            GameObject.Destroy(go, 2)                  
            go.name = '123'
            --print('delay destroy gameobject is: '..go.name)   

c#代码如下:

        new LuaResLoader();
        lua = new LuaState();
        lua.LogGC = true;
        lua.Start();
        LuaBinder.Bind(lua);
        lua.DoString(script, "TestGameObject.cs");

2」需要了解的部分

  • 主要的方法如下:

GameObject:AddComponent(typeof(Component)) 在lua中给游戏物体添加组件

GameObject("游戏物体名") 在lua中创建新的游戏物体

GameObject.Destroy(游戏对象, 延迟时间) 延时销毁的指定的游戏物体

luabinder.bind(lua)将当前luastate的虚拟机中绑定C#中的一些类、全局类、委托等

相关文章

网友评论

      本文标题:ToLua的Example示例学习笔记12_TestGameOb

      本文链接:https://www.haomeiwen.com/subject/ukzinhtx.html