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);
}
}
Unity3d多线程
最新推荐文章于 2023-10-17 14:35:05 发布