纳金网

标题: Unity3D多线程写法 [打印本页]

作者: 狂风大尉    时间: 2014-9-28 07:58
标题: Unity3D多线程写法

[color=rgb(85, 85, 85) !important]unity3d
多线程写法

与大家分享下:
MicrosoftInternetExplorer402DocumentNotSpecified7.8Normal0

using UnityEngine;
using System.Collections;
using System.Threading;
public class MyThread
{
public int count;
string thrdName;
public MyThread(string nam)
{
count = 0;
thrdName = nam;
}
public void run()
{
Debug.Log("start run a thread"+Time.time);
do{
Thread.Sleep(1000);
Debug.Log("in child thread"+Time.time+"count="+count);
count++;
}while(count <20);
Debug.Log("end thread"+Time.time);
}
}
public class testThread : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("start main"+Time.time);
MyThread mt = new MyThread("CHILE ");
Thread newThrd = new Thread(new ThreadStart(mt.run));
newThrd.Start();
}
// Update is called once per frame
void Update () {
Debug.Log(Time.time);
}
}


作者: oelongeo    时间: 2014-9-28 15:56
谢谢狂风大尉指导  虽然还是不明白
作者: HIDEOKOJIMA    时间: 2014-9-28 19:26
Thanks for sharing this !
作者: leanchen89    时间: 2014-9-29 23:26
Unity的子线程里面是无法获取组件的吧,只能对一些数据进行操作。
作者: hyui    时间: 2014-10-2 22:43
Thanks for this !
作者: jiaokeye    时间: 2017-1-16 11:41
实施看呢




欢迎光临 纳金网 (http://rs.narkii.com/club/) Powered by Discuz! X2.5