-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed Update methods from ReGoapGoal, ReGoapAgent and ReGoapMemory
Added two new classes: - ReGoapGoalAdvanced: with update method, needed if you want automatic warnings to agent when the goal is possible / not possible anymore - ReGoapMemoryAdvanced: with update method, needed if you use sensors and want to automatically update memory with them - ReGoapAgentAdvanced: with updated metehod, needed if you want to validate continously current action in the agent Small changes to FSMExample
- Loading branch information
Showing
15 changed files
with
174 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ sysinfo.txt | |
|
||
# Builds | ||
*.apk | ||
*.unitypackage | ||
*.unitypackage | ||
ReGoap/Unity/SimExample/ | ||
ReGoap/Unity/SimExample.meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace ReGoap.Unity.FSMExample.Agents | ||
{ | ||
public class BuilderAgent : ReGoapAgent<string, object> | ||
public class BuilderAgent : ReGoapAgentAdvanced<string, object> | ||
{ | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace ReGoap.Unity | ||
{ | ||
public class ReGoapAgentAdvanced<T, W> : ReGoapAgent<T, W> | ||
{ | ||
public bool ValidateActiveAction; | ||
|
||
#region UnityFunctions | ||
protected virtual void Update() | ||
{ | ||
possibleGoalsDirty = true; | ||
|
||
if (currentActionState == null) | ||
{ | ||
if (!IsPlanning) | ||
CalculateNewGoal(); | ||
return; | ||
} | ||
// check if current action preconditions are still valid, else invalid action and restart planning | ||
if (ValidateActiveAction) | ||
{ | ||
var state = memory.GetWorldState(); | ||
if (currentActionState.Action.GetPreconditions(state).MissingDifference(state, 1) > 0) | ||
TryWarnActionFailure(currentActionState.Action); | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ReGoap.Core; | ||
using ReGoap.Planner; | ||
using UnityEngine; | ||
|
||
// generic goal, should inherit this to do your own goal | ||
namespace ReGoap.Unity | ||
{ | ||
public class ReGoapGoalAdvanced<T, W> : ReGoapGoal<T, W> | ||
{ | ||
public float WarnDelay = 2f; | ||
private float warnCooldown; | ||
|
||
#region UnityFunctions | ||
protected virtual void Update() | ||
{ | ||
if (planner != null && !planner.IsPlanning() && Time.time > warnCooldown) | ||
{ | ||
warnCooldown = Time.time + WarnDelay; | ||
var currentGoal = planner.GetCurrentGoal(); | ||
var plannerPlan = currentGoal == null ? null : currentGoal.GetPlan(); | ||
var equalsPlan = ReferenceEquals(plannerPlan, plan); | ||
var isGoalPossible = IsGoalPossible(); | ||
// check if this goal is not active but CAN be activated | ||
// or | ||
// if this goal is active but isn't anymore possible | ||
if ((!equalsPlan && isGoalPossible) || (equalsPlan && !isGoalPossible)) | ||
planner.GetCurrentAgent().WarnPossibleGoal(this); | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.