Unity3d多线程

来源:互联网 发布:淘宝达人怎么申请入口 编辑:程序博客网 时间:2024/05/21 15:44
using UnityEngine;using System.Collections;using System.Threading;public class MultipleThread : MonoBehaviour {private MyThread mt;private Thread thread;void Start () {Debug.LogWarning("Start Main : " + Time.time);mt = new MyThread("child_0");thread = new Thread(new ThreadStart(mt.run));thread.Start();}void Update () {Debug.Log("Main : " + Time.time);if(mt.Count == 10 && thread.IsAlive) thread.Abort();}}public class MyThread{private int count = 0;private string name;public int Count{get{return this.count;}}public MyThread(string name){this.name = name;}public void run(){Debug.Log("********************************************** Start Run a Thread : " + this.name);do{Thread.Sleep(1000);Debug.Log("======================================== In Child Thread Time : " + this.name);count++;}while(this.count < 20);Debug.Log("************************************************ Stop Run a Thread : " + this.name);}}

0 0
原创粉丝点击