From ec2ede72ed21f0f85be2b48c4238074a868fd6a9 Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Wed, 16 Aug 2023 21:54:48 -0500 Subject: [PATCH] simplify runtime set access --- Assets/Scripts/Enemy.cs | 10 ++-------- Assets/Scripts/RuntimeSet/RuntimeSetSO.cs | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Enemy.cs b/Assets/Scripts/Enemy.cs index cc133c2..b7902cc 100644 --- a/Assets/Scripts/Enemy.cs +++ b/Assets/Scripts/Enemy.cs @@ -131,7 +131,7 @@ namespace DefaultNamespace private void Retarget() { - if (heroSet == null || heroSet.Count == 0) + if (heroSet.IsEmpty) { // No heroes to target. // TODO(zeph): switch to a special behavior? @@ -140,13 +140,7 @@ namespace DefaultNamespace } // TODO(zeph): target based on threat, once threat exists var k = Random.Range(0, heroSet.Count); - var it = heroSet.GetEnumerator(); - // This seems to be the best way to do this...? - for (var i = 0; i < k; i++) - { - it.MoveNext(); - } - target = it.Current.gameObject; + target = heroSet[k].gameObject; } private void SetBehavior(BehaviorState behavior) diff --git a/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs b/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs index caa83b5..a02bd2a 100644 --- a/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs +++ b/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs @@ -37,5 +37,7 @@ namespace RuntimeSet { return GetEnumerator(); } + + public T this[int index] { get { return items[index]; } } } } \ No newline at end of file