73 lines
1.1 KiB
C#
73 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Threading;
|
|
using UnityEngine;
|
|
|
|
namespace Mtree
|
|
{
|
|
public class ThreadHandleEditor
|
|
{
|
|
private Thread thread;
|
|
|
|
private readonly Action OnStartCallback;
|
|
|
|
private readonly Action ThreadedFunction;
|
|
|
|
private readonly Action OnEndCallback;
|
|
|
|
private Coroutine coroutine;
|
|
|
|
private bool begun;
|
|
|
|
private bool waited;
|
|
|
|
private bool ended;
|
|
|
|
private float time;
|
|
|
|
public ThreadHandleEditor(Action onStartCallback, Action threadedFunction, Action onEndCallback)
|
|
{
|
|
OnStartCallback = onStartCallback;
|
|
ThreadedFunction = threadedFunction;
|
|
OnEndCallback = onEndCallback;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
}
|
|
|
|
private void Run()
|
|
{
|
|
}
|
|
|
|
public void Abort()
|
|
{
|
|
if (thread != null)
|
|
{
|
|
thread.Abort();
|
|
}
|
|
}
|
|
|
|
private IEnumerator RunThread()
|
|
{
|
|
if (OnStartCallback != null)
|
|
{
|
|
OnStartCallback();
|
|
}
|
|
if (ThreadedFunction != null)
|
|
{
|
|
thread = new Thread(ThreadedFunction.Invoke);
|
|
thread.Start();
|
|
}
|
|
while (thread != null && thread.IsAlive)
|
|
{
|
|
yield return null;
|
|
}
|
|
if (OnEndCallback != null)
|
|
{
|
|
OnEndCallback();
|
|
}
|
|
}
|
|
}
|
|
}
|