WhiteEngine-专注图形渲染与游戏引擎技术的网站

新浪微薄腾讯微薄

最新碎语:暂无碎语

您的位置:WhiteEngine-专注图形渲染与游戏引擎技术的网站 >C#与Lua> Slua常用方法

Slua常用方法

-- import
import "UnityEngine"

function main()

    -- create gameobject
    local cube = GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)

    -- find gameobject
    local go = GameObject.Find("Canvas/Button")

    -- get component by type name
    local btn = go:GetComponent("Button")

    -- get out parameter
    local ok,hitinfo = Physics.Raycast(Vector3(0,0,0),Vector3(0,0,1),Slua.out)
    print("Physics Hitinfo",ok,hitinfo)

    -- foreach enumeratable object
    for t in Slua.iter(Canvas.transform) do
        print("foreach transorm",t)
    end

    -- add event listener
    btn.onClick:AddListener(function()
        local go = GameObject.Find("Canvas/Text")
        local label = go:GetComponent("Text")
        label.text="hello world"
    end)

    -- use vector3
    local pos = Vector3(10,10,10)+Vector3(1,1,1)
    cube.transform.position = pos

    -- use coroutine
    local c=coroutine.create(function()
        print "coroutine start"

        Yield(WaitForSeconds(2))
        print "coroutine WaitForSeconds 2"

        local www = WWW("http://www.sineysoft.com")
        Yield(www)
        print(#Slua.ToString(www.bytes))
    end)
    coroutine.resume(c)

    -- add delegate
    Deleg.daction = {"+=",self.actionD} --it's ok for iOS

    -- remove delegate
    Deleg.daction = {"-=",self.actionD} --it's ok for iOS

    -- set delegate
    Deleg.daction = function() print("callback") end --it's ok for iOS

    -- remove all
    Deleg.daction = nil
end

---

转载请注明本文标题和链接:《Slua常用方法

分享到:

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交