Skip to content

Commit 53e0f52

Browse files
committed
add RemoveAll
1 parent 284d473 commit 53e0f52

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

Scripts/UdonArrayPlus.cs

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ public static T[] Add<T>(T[] _array, T _value, bool duplicates = true)
2525
_newArray.SetValue(_value, length);
2626
return _newArray;
2727
}
28-
public static T[] Add<T>(ref T[] _array, T _value, bool duplicates = true)
29-
{
30-
return _array = Add(_array, _value, duplicates);
31-
}
28+
public static T[] Add<T>(ref T[] _array, T _value, bool duplicates = true) => _array = Add(_array, _value, duplicates);
3229
public static T[] Insert<T>(T[] array, int index, T item, bool duplicates = true)
3330
{
3431
if (!duplicates)
@@ -60,10 +57,7 @@ public static T[] Insert<T>(T[] array, int index, T item, bool duplicates = true
6057

6158
return newArray;
6259
}
63-
public static T[] Insert<T>(ref T[] array, int index, T item, bool duplicates = true)
64-
{
65-
return array = Insert(array, index, item, duplicates);
66-
}
60+
public static T[] Insert<T>(ref T[] array, int index, T item, bool duplicates = true) => array = Insert(array, index, item, duplicates);
6761
public static bool Contains<T>(T[] array, T item)
6862
{
6963
return IndexOf(array, item) >= 0;
@@ -126,21 +120,28 @@ public static T[] RemoveAt<T>(T[] array, int index)
126120

127121
return newArray;
128122
}
129-
public static T[] RemoveAt<T>(ref T[] array, int index)
130-
{
131-
return array = RemoveAt(array, index);
132-
}
123+
public static T[] RemoveAt<T>(ref T[] array, int index) => array = RemoveAt(array, index);
133124
public static T[] Remove<T>(T[] _array, T _value)
134125
{
135126
var index = IndexOf(_array, _value);
136127
if (index == -1)
137128
return _array;
138129
return RemoveAt(_array, index);
139130
}
140-
public static T[] Remove<T>(ref T[] _array, T _value)
131+
public static T[] Remove<T>(ref T[] _array, T _value) => _array = Remove(_array, _value);
132+
public static T[] RemoveAll<T>(T[] _array, T _value)
141133
{
142-
return _array = Remove(_array, _value);
134+
var index = IndexOf(_array, _value);
135+
if (index == -1)
136+
return _array;
137+
while (index != -1)
138+
{
139+
_array = RemoveAt(_array, index);
140+
index = IndexOf(_array, _value);
141+
}
142+
return _array;
143143
}
144+
public static T[] RemoveAll<T>(ref T[] _array, T _value) => _array = RemoveAll(_array, _value);
144145
public static T[] AddRange<T>(T[] _array, T[] collection)
145146
{
146147
var length = _array.Length;
@@ -155,10 +156,7 @@ public static T[] AddRange<T>(T[] _array, T[] collection)
155156

156157
return newArray;
157158
}
158-
public static T[] AddRange<T>(ref T[] _array, T[] collection)
159-
{
160-
return _array = AddRange(_array, collection);
161-
}
159+
public static T[] AddRange<T>(ref T[] _array, T[] collection) => _array = AddRange(_array, collection);
162160
// String
163161
public static string[] StringsFindLikeAll(string[] _array, string _value)
164162
{
@@ -206,10 +204,7 @@ public static int[] IntsSort(int[] _array, bool reverse = false)
206204
}
207205
return _newArray;
208206
}
209-
public static int[] IntsSort(ref int[] _array, bool reverse = false)
210-
{
211-
return _array = IntsSort(_array, reverse);
212-
}
207+
public static int[] IntsSort(ref int[] _array, bool reverse = false) => _array = IntsSort(_array, reverse);
213208
// Float
214209
public static float[] FloatsSort(float[] _array, bool reverse)
215210
{
@@ -231,10 +226,7 @@ public static float[] FloatsSort(float[] _array, bool reverse)
231226
}
232227
return _newArray;
233228
}
234-
public static float[] FloatsSort(ref float[] _array, bool reverse)
235-
{
236-
return _array = FloatsSort(_array, reverse);
237-
}
229+
public static float[] FloatsSort(ref float[] _array, bool reverse) => _array = FloatsSort(_array, reverse);
238230
// VRCPlayerApi
239231
public static VRCPlayerApi[] Players()
240232
{
@@ -297,10 +289,7 @@ public static VRCPlayerApi[] PlayersAdd(VRCPlayerApi[] players, VRCPlayerApi _pl
297289
newPlayers[players.Length] = _player;
298290
return newPlayers;
299291
}
300-
public static VRCPlayerApi[] PlayersAdd(ref VRCPlayerApi[] players, VRCPlayerApi _player, bool force = false)
301-
{
302-
return players = PlayersAdd(players, _player, force);
303-
}
292+
public static VRCPlayerApi[] PlayersAdd(ref VRCPlayerApi[] players, VRCPlayerApi _player, bool force = false) => players = PlayersAdd(players, _player, force);
304293
public static VRCPlayerApi[] PlayersAddIndex(VRCPlayerApi[] players, VRCPlayerApi _player, int index, bool force = false)
305294
{
306295
if (index < 0 || index > players.Length)
@@ -329,10 +318,7 @@ public static VRCPlayerApi[] PlayersAddIndex(VRCPlayerApi[] players, VRCPlayerAp
329318
return newPlayers;
330319
}
331320
}
332-
public static VRCPlayerApi[] PlayersAddIndex(ref VRCPlayerApi[] players, VRCPlayerApi _player, int index, bool force = false)
333-
{
334-
return players = PlayersAddIndex(players, _player, index, force);
335-
}
321+
public static VRCPlayerApi[] PlayersAddIndex(ref VRCPlayerApi[] players, VRCPlayerApi _player, int index, bool force = false) => players = PlayersAddIndex(players, _player, index, force);
336322
public static VRCPlayerApi[] PlayersRemove(VRCPlayerApi[] players, VRCPlayerApi _player)
337323
{
338324
var index = PlayersIndex(players, _player);
@@ -354,10 +340,7 @@ public static VRCPlayerApi[] PlayersRemove(VRCPlayerApi[] players, VRCPlayerApi
354340
return newPlayers;
355341
}
356342
}
357-
public static VRCPlayerApi[] PlayersRemove(ref VRCPlayerApi[] players, VRCPlayerApi _player)
358-
{
359-
return players = PlayersRemove(players, _player);
360-
}
343+
public static VRCPlayerApi[] PlayersRemove(ref VRCPlayerApi[] players, VRCPlayerApi _player) => players = PlayersRemove(players, _player);
361344
public static VRCPlayerApi PlayersFindID(int _id)
362345
{
363346
VRCPlayerApi[] players = Players();

0 commit comments

Comments
 (0)