I am looking to write a generic function to resize builtin arrays. When I use builtin arrays, they are often of a custom class, like this:
public RangedSetWeapon[] rangedSetWeapons;
And I want to create a function that works for all builtin arrays, something like this:
public static void append (Array[] originalArray, GameObject newItem) {
Array[] updatedArray = new Array[originalArray.Length] + 1;
int i = 0;
foreach (Array existingItem in originalArray) {
updatedArray *= existingItem;*
-
i += 1;*
- }*
_ updatedArray = newItem;_
* return updatedArray;*
}
But this obviously wont work because the originalArray type is unknown, as is the type of the newItem object.
Is there a way to generisize this code so it would work for ANY builtin array using ANY object type (as long as it matches the originalArray type)?
Any thoughts would be appreciated