-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes multi-sensor missing keys warning
- Loading branch information
1 parent
08fd2d9
commit f7cf91c
Showing
17 changed files
with
179 additions
and
90 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
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
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
3 changes: 3 additions & 0 deletions
3
Demo/Assets/CrashKonijn/GOAP/Demos/Complex/Sensors/Multi.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
Demo/Assets/CrashKonijn/GOAP/Demos/Complex/Sensors/Multi/ItemSensors.cs
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,51 @@ | ||
using System.Linq; | ||
using CrashKonijn.Agent.Core; | ||
using CrashKonijn.Goap.Core; | ||
using CrashKonijn.Goap.Demos.Complex.Behaviours; | ||
using CrashKonijn.Goap.Demos.Complex.Interfaces; | ||
using CrashKonijn.Goap.Demos.Complex.Targets; | ||
using CrashKonijn.Goap.Demos.Complex.WorldKeys; | ||
using CrashKonijn.Goap.Runtime; | ||
using UnityEngine; | ||
using TransformTarget = CrashKonijn.Goap.Runtime.TransformTarget; | ||
|
||
namespace CrashKonijn.Goap.Demos.Complex.Sensors.Multi | ||
{ | ||
public class ItemSensor<T> : MultiSensorBase | ||
where T : class, IHoldable | ||
{ | ||
private ItemCollection collection; | ||
|
||
public ItemSensor() | ||
{ | ||
this.AddLocalTargetSensor<ClosestTarget<T>>(this.SenseClosestTarget); | ||
this.AddLocalWorldSensor<IsInWorld<T>>(this.SenseIsInWorld); | ||
} | ||
|
||
public override void Created() | ||
{ | ||
this.collection = Object.FindObjectOfType<ItemCollection>(); | ||
} | ||
|
||
public override void Update() { } | ||
|
||
private ITarget SenseClosestTarget(IActionReceiver agent, IComponentReference references, ITarget target) | ||
{ | ||
var closest = this.collection.GetFiltered<T>(false, true, agent.Transform.gameObject).Cast<ItemBase>().Closest(agent.Transform.position); | ||
|
||
if (closest == null) | ||
return null; | ||
|
||
// Re-use the existing target if the target exists | ||
if (target is TransformTarget targetTransform) | ||
return targetTransform.SetTransform(closest.transform); | ||
|
||
return new TransformTarget(closest.transform); | ||
} | ||
|
||
private SenseValue SenseIsInWorld(IActionReceiver agent, IComponentReference references) | ||
{ | ||
return this.collection.GetFiltered<T>(false, true, agent.Transform.gameObject).Length; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Demo/Assets/CrashKonijn/GOAP/Demos/Complex/Sensors/Multi/ItemSensors.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.