Skip to content

Commit

Permalink
Merge pull request #184 from crashkonijn/fix/node-viewer-not-working-…
Browse files Browse the repository at this point in the history
…with-multiple-goap-runners

Fixed node viewer not working when using multiple goap runners
  • Loading branch information
crashkonijn authored Jul 2, 2024
2 parents 4f6993b + 2e2d471 commit d35d19d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ private void RenderGraph()
{
this.rightPanel.Clear();

if (this.runner == null)
return;

if (this.agent == null)
return;

this.runner = this.agent.GoapSet.Runner;

if (!this.runner.Knows(this.goapSet))
return;
Expand Down
2 changes: 1 addition & 1 deletion Package/Runtime/CrashKonijn.Goap/Classes/GoapSet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using CrashKonijn.Goap.Behaviours;
using CrashKonijn.Goap.Classes.Runners;
using CrashKonijn.Goap.Interfaces;
using CrashKonijn.Goap.Resolver.Interfaces;

Expand All @@ -14,6 +13,7 @@ public class GoapSet : IGoapSet
public IGoapConfig GoapConfig { get; }
public ISensorRunner SensorRunner { get; }
public IAgentDebugger Debugger { get; }
public IGoapRunner Runner { get; set; }

private List<IGoalBase> goals;
private List<IActionBase> actions;
Expand Down
10 changes: 9 additions & 1 deletion Package/Runtime/CrashKonijn.Goap/Classes/Runners/GoapRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ public class GoapRunner : IGoapRunner
public float RunTime { get; private set; }
public float CompleteTime { get; private set; }

public void Register(IGoapSet goapSet) => this.goapSets.Add(goapSet, new GoapSetJobRunner(goapSet, new GraphResolver(goapSet.GetAllNodes().ToArray(), goapSet.GoapConfig.KeyResolver)));
public void Register(IGoapSet goapSet)
{
goapSet.Runner = this;

var graphResolver = new GraphResolver(goapSet.GetAllNodes().ToArray(), goapSet.GoapConfig.KeyResolver);
var jobRunner = new GoapSetJobRunner(goapSet, graphResolver);

this.goapSets.Add(goapSet, jobRunner);
}

public void Run()
{
Expand Down
1 change: 1 addition & 0 deletions Package/Runtime/CrashKonijn.Goap/Interfaces/IGoapSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IGoapSet
IAgentCollection Agents { get; }
ISensorRunner SensorRunner { get; }
IAgentDebugger Debugger { get; }
IGoapRunner Runner { get; set; }
void Register(IMonoAgent agent);
void Unregister(IMonoAgent agent);
List<IAction> GetAllNodes();
Expand Down

0 comments on commit d35d19d

Please sign in to comment.