/// <summary> /// (Cross-Game compatible) Return this with all Items of type TCast removed /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TCast">The Type of the Items that you want to remove</typeparam> /// <param name="referenceArray"></param> /// <returns></returns> public static Il2CppReferenceArray <TSource> RemoveItemsOfType <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray) where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object { if (!HasItemsOfType <TSource, TCast>(referenceArray)) { return(referenceArray); } int numRemoved = 0; List <TSource> arrayList = referenceArray.ToList(); for (int i = 0; i < referenceArray.Count; i++) { TSource item = referenceArray[i]; if (item is null || !item.IsType <TCast>()) { continue; } if (item is null || !item.IsType <TCast>()) { continue; } arrayList.RemoveAt(i - numRemoved); numRemoved++; } return(arrayList.ToIl2CppReferenceArray()); }
/// <summary> /// (Cross-Game compatible) Return this with the first Item of type TCast removed /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TCast">The Type of the Item you want to remove</typeparam> /// <param name="referenceArray"></param> /// <param name="itemToRemove">The specific Item to remove</param> /// <returns></returns> public static Il2CppReferenceArray <TSource> RemoveItem <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray, TCast itemToRemove) where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object { if (!HasItemsOfType <TSource, TCast>(referenceArray)) { return(referenceArray); } List <TSource> arrayList = referenceArray.ToList(); for (int i = 0; i < referenceArray.Count; i++) { TSource item = referenceArray[i]; if (item is null || !item.Equals(itemToRemove.TryCast <TCast>())) { continue; } arrayList.RemoveAt(i); break; } return(arrayList.ToIl2CppReferenceArray()); }