// called in another thread
 private void OnDonePlan(ReGoapPlannerThread <T, W> plannerThread, ReGoapPlanWork <T, W> work, IReGoapGoal <T, W> newGoal)
 {
     work.NewGoal = newGoal;
     lock (doneWorks)
     {
         doneWorks.Add(work);
     }
     if (work.NewGoal != null && ReGoapLogger.Level == ReGoapLogger.DebugLevel.Full)
     {
         ReGoapLogger.Log("[GoapPlannerManager] Done calculating plan, actions list:");
         var i = 0;
         foreach (var action in work.NewGoal.GetPlan())
         {
             ReGoapLogger.Log(string.Format("{0}: {1}", i++, action.Action));
         }
     }
 }
        protected virtual void Awake()
        {
            ReGoapNode <T, W> .Warmup(NodeWarmupCount);

            ReGoapState <T, W> .Warmup(StatesWarmupCount);

            ReGoapLogger.Level = LogLevel;
            if (Instance != null)
            {
                Destroy(this);
                var errorString =
                    "[GoapPlannerManager] Trying to instantiate a new manager but there can be only one per scene.";
                ReGoapLogger.LogError(errorString);
                throw new UnityException(errorString);
            }
            Instance = this;

            doneWorks = new List <ReGoapPlanWork <T, W> >();
            ReGoapPlannerThread <T, W> .WorksQueue = new Queue <ReGoapPlanWork <T, W> >();
            planners = new ReGoapPlannerThread <T, W> [ThreadsCount];
            threads  = new Thread[ThreadsCount];

            if (MultiThread)
            {
                ReGoapLogger.Log(String.Format("[GoapPlannerManager] Running in multi-thread mode ({0} threads).", ThreadsCount));
                for (int i = 0; i < ThreadsCount; i++)
                {
                    planners[i] = new ReGoapPlannerThread <T, W>(PlannerSettings, OnDonePlan);
                    var thread = new Thread(planners[i].MainLoop);
                    thread.Start();
                    threads[i] = thread;
                }
            } // no threads run
            else
            {
                ReGoapLogger.Log("[GoapPlannerManager] Running in single-thread mode.");
                planners[0] = new ReGoapPlannerThread <T, W>(PlannerSettings, OnDonePlan);
            }
        }