示例#1
0
        /// <summary>
        /// Start the thread.
        /// </summary>
        /// <returns>True if not already running.</returns>
        public bool Start()
        {
            if (Running)
            {
                return(false);
            }
            WorkthreadBehaviour workBehaviour = WorkthreadObject.GetComponent <WorkthreadBehaviour>();

            if (workBehaviour == null)
            {
                workBehaviour = WorkthreadObject.AddComponent <WorkthreadBehaviour>();
            }
            Coroutine threadRoutine = workBehaviour.StartCoroutine(_threadFunction);

            _threadRoutine = new WeakReference(threadRoutine);
            return(true);
        }
示例#2
0
 /// <summary>
 /// Stop and join the thread.
 /// </summary>
 /// <remarks>
 /// Invokes the <see cref="QuitDelegate"/>, followed by the <see cref="StopDelegate"/>
 /// once the thread is joined.</remarks>
 /// <returns>True if the thread was running and has been stopped.</returns>
 public bool Stop()
 {
     if (_threadRoutine != null && _workthreadObject != null)
     {
         Coroutine           routine       = _threadRoutine.Target as Coroutine;
         WorkthreadBehaviour workBehaviour = _workthreadObject.GetComponent <WorkthreadBehaviour>();
         if (routine != null && workBehaviour != null)
         {
             if (_onQuit != null)
             {
                 _onQuit();
             }
             workBehaviour.StopCoroutine(routine);
             if (_onStop != null)
             {
                 _onStop();
             }
             return(true);
         }
     }
     return(false);
 }