// Try to add a job to current queue. If the job is already presented, the existing job will be returned; If the job is already finished, null will be returned; otherwise the job itself will be returned. public static CustomJob TryAddJob(CustomJob job, OnFinishCallback finishCallback = null) { #if PROFILE UnityEngine.Profiling.Profiler.BeginSample("CustomJob.TryAddJob"); #endif if (job.isUnique) { if (queuedUniqueJobs.ContainsKey(job)) { //Debug.Log($"{job.ToString()} has already been queued."); queuedUniqueJobs[job].finishCallback += finishCallback; #if PROFILE Profiler.EndSample(); #endif return(queuedUniqueJobs[job]); } // Check if job is already finished job.finishCallback = finishCallback; if (job.AlreadyFinished()) { job.OnFinish(); #if PROFILE Profiler.EndSample(); #endif return(null); } job.InitJob(); queuedUniqueJobs.Add(job, job); Count += 1; job.Schedule(); } else { job.InitJob(); Count += 1; job.Schedule(); } #if PROFILE Profiler.EndSample(); #endif return(job); }