So I'm trying to do something to avoid repeating the same code and changing just the object, I tought i could do it like this:
But it doesn't work, i never worked with generics before so i need a little hand in here, is there any way i could do something like this?Code:object getObjectList<T>() { return UnityEngine.Object.FindObjectsOfType<T>(); }
[DOUBLEPOST=1437517919][/DOUBLEPOST]Edit: I currently use it like this:
But i don't want to do it for barricades, buildingblocks, traps etc etc, i just want a generic method.Code:new HashSet<Barricade>(UnityEngine.Object.FindObjectsOfType<Barricade>())
Generic Hashset
Discussion in 'Rust Development' started by WolfsDarker, Jul 21, 2015.
-
Calytic Community Admin Community Mod
Haven't tested it but maybe something like this..
Code:HashSet<T> getObjectList<T>() where T : UnityEngine.Object { return new HashSet<T>(UnityEngine.Object.FindObjectsOfType<T>()); }
-
Code:
new HashSet<T>(UnityEngine.Object.FindObjectsOfType<T>());
EDIT: It worked, thanks alot man -
Calytic Community Admin Community Mod
Yea, sorry I edited my post 2 seconds after I posted it.
You needed the..
Code:where T : UnityEngine.Object
-
Yeah, thats all i added and it worked. Will be testing in around 15 mins, this will make everything smaller and cleaner
[DOUBLEPOST=1437523794][/DOUBLEPOST]It worked and has been added to my plugin update:
http://oxidemod.org/plugins/object-remover.1213/