Skip to content

Commit 08869e5

Browse files
committed
Feat: support dictionary on random choose one
1 parent 0593260 commit 08869e5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
using System.Collections.Generic;
1010
using System.Linq;
11+
using Unity.VisualScripting;
1112
using UnityEngine;
1213

1314
namespace JCSUnity
@@ -158,14 +159,23 @@ public static T ChooseOneE<T>(params T[] args) // Ellipsis
158159
{
159160
return ChooseOne(args);
160161
}
161-
public static T ChooseOne<T>(ICollection<T> inList)
162+
public static T ChooseOne<T>(ICollection<T> lst)
162163
{
163-
if (inList.Count == 0)
164+
if (lst.Count == 0)
164165
return default(T);
165166

166-
int index = Range(0, inList.Count);
167+
int index = Range(0, lst.Count);
167168

168-
return inList.ElementAt(index);
169+
return lst.ElementAt(index);
170+
}
171+
public static KeyValuePair<T, K> ChooseOne<T, K>(ICollection<KeyValuePair<T, K>> dict)
172+
{
173+
if (dict == null || dict.Count == 0)
174+
return default;
175+
176+
int index = Range(0, dict.Count);
177+
178+
return dict.ElementAt(index);
169179
}
170180

171181
/// <summary>

0 commit comments

Comments
 (0)