码迷,mamicode.com
首页 > 其他好文 > 详细

Ulua_toLua_基本案例(六)_LuaCoroutine2

时间:2017-08-15 15:13:29      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:amp   oca   his   com   track   script   log   dos   class   

Ulua_toLua_基本案例(六)_LuaCoroutine2


using UnityEngine;
using System.Collections;
using LuaInterface;

public class TestCoroutine2 : MonoBehaviour 
{
    LuaState luaState = null;    

    string script =
    @"
        function CoExample()            
            WaitForSeconds(2)
            print('WaitForSeconds end time: '.. UnityEngine.Time.time)
            WaitForFixedUpdate()
            print('WaitForFixedUpdate end frameCount: '..UnityEngine.Time.frameCount)
            WaitForEndOfFrame()
            print('WaitForEndOfFrame end frameCount: '..UnityEngine.Time.frameCount)
            Yield(null)
            print('yield null end frameCount: '..UnityEngine.Time.frameCount)
            Yield(0)
            print('yield(0) end frameCime: '..UnityEngine.Time.frameCount)
            local www = UnityEngine.WWW('http://www.baidu.com')
            Yield(www)
            print('yield(www) end time: '.. UnityEngine.Time.time)
            local s = tolua.tolstring(www.bytes)
            print(s:sub(1, 128))
            print('coroutine over')
        end

        function TestCo()
            print('TestCo')
            local co = coroutine.create(CoExample)
                        
            local flag, msg = coroutine.resume(co)
            
            if not flag then
                error(msg)
            end
        end
    ";

	void Awake () 
    {
        luaState = new LuaState();
        luaState.Start();
        LuaBinder.Bind(luaState);
        LuaCoroutine.Register(luaState, this);

        luaState.DoString(script);
        LuaFunction func = luaState.GetFunction("TestCo");
        func.Call();
        func.Dispose();
	}

    void OnDestroy()
    {
        luaState.Dispose();
        luaState = null;
    }
}


Ulua_toLua_基本案例(六)_LuaCoroutine2

标签:amp   oca   his   com   track   script   log   dos   class   

原文地址:http://www.cnblogs.com/blfbuaa/p/7364880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!