Пример #1
0
    public IGoap dataProvider; // this is the implementing class that provides our world data and listens to feedback on planning

    void Start()
    {
        findDataProvider();

        goapPlannerManager = new GoapPlannerManager(this);
        stateMachine       = new FSM(this);

        stateMachine.pushState(FSMStateEnum.Idle);
    }
Пример #2
0
    protected virtual void Awake()
    {
        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 <PlanWork>();
        worksQueue   = new Queue <PlanWork>();
        planners     = new GoapPlannerThread[ThreadsCount];
        threads      = new Thread[ThreadsCount];
        threadEvents = new AutoResetEvent(false);
        if (ThreadsCount > 1)
        {
            ReGoapLogger.Log("[GoapPlannerManager] Running in multi-thread mode.");
            for (int i = 0; i < ThreadsCount; i++)
            {
                planners[i] = new GoapPlannerThread(threadEvents, PlannerSettings, worksQueue, OnDonePlan);
                var thread = new Thread(planners[i].MainLoop)
                {
                    IsBackground = true
                };
                thread.Start();
                threads[i] = thread;
            }
        } // no threads run
        else
        {
            ReGoapLogger.Log("[GoapPlannerManager] Running in single-thread mode.");
            planners[0] = new GoapPlannerThread(threadEvents, PlannerSettings, worksQueue, OnDonePlan);
        }
    }