From eccd25d02960b9d8013f87af280f806dfa1c0aa8 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Thu, 15 Dec 2016 17:47:06 +0000 Subject: [PATCH 1/2] Add OnNeighborsChanged event to SteerForNeighborGroup2D This is useful for adjusting other behaviours when neighbors change --- 2D/Behaviors/SteerForNeighborGroup2D.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/2D/Behaviors/SteerForNeighborGroup2D.cs b/2D/Behaviors/SteerForNeighborGroup2D.cs index a23f66c..96a1658 100644 --- a/2D/Behaviors/SteerForNeighborGroup2D.cs +++ b/2D/Behaviors/SteerForNeighborGroup2D.cs @@ -1,5 +1,7 @@ +using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Profiling; using UnitySteer.Attributes; namespace UnitySteer2D.Behaviors @@ -116,6 +118,12 @@ public List Neighbors get { return _neighbors; } } + /// + /// Delegate which is called when the detected neighbors list is changed + /// + public Action OnNeighborsChanged = delegate { }; + + #endregion #region Methods @@ -162,6 +170,14 @@ private void HandleDetection(Radar2D radar) _neighbors.Add(other); } } + + if (OnNeighborsChanged != null) + { + Profiler.BeginSample("Neighbor event handler"); + OnNeighborsChanged(this); + Profiler.EndSample(); + } + } protected override Vector2 CalculateForce() From d014aecb1e5fed53b81a0e222d3f07a7ea555afb Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Wed, 21 Dec 2016 09:38:41 +0000 Subject: [PATCH 2/2] Updated Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2de3ef5..a7323d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # UnitySteer changelog +## WIP + +* Added OnNeighborsChanged event to SteerForNeighbourGroup2D + ## v3.1 * 2D support thanks to @GandaG and @pjohalloran.