C# Unity3D - Get stuck with an sticky situation -
im making game inside unity3d im stuck try find solution on it.
its part of stock system can store things in "items or materials".
the following variables / classes follows :
[serializable] public class itemstorage { public extendedlist.items item; public list<materialstorage> material; } [serializable] public class materialstorage { public extendedlist.ingots material; public int materialcount; }
above classes.
public list<itemstorage> itemstorage; public list<materialstorage> materialstorage;
above variables.
and under enums bassicly use :
public enum items : int { [description("helmet")] helmet = 0, [description("chestplate")] chestplate = 4, [description("platelegs")] platelegs = 8, [description("gaunlets")] gaunlets = 12, [description("boots")] boots = 16, [description("sword")] sword = 20, [description("shield")] shield = 24, [description("wheel")] wheel = 28, [description("axe")] axe = 32 } public enum ingots : int { [description("bronze ingot")] bronze = 0, [description("iron ingot")] iron = 5, [description("steel ingot")] steel = 10, [description("silver ingot")] silver = 15, [description("platinum ingot")] platinum = 20 }
but have code call in "awake" initialize / list(s) :
(int = 0; < enum.getvalues(typeof(extendedlist.ingots)).length; i++) { if (gamemanager.instance.playerlevel >= extendedlist.getingotvalue(i)) { materialstorage.add(new materialstorage() { material = (extendedlist.ingots)extendedlist.getingotvalue(i) }); } } (int = 0; < enum.getnames(typeof(extendedlist.items)).length; i++) { if (gamemanager.instance.playerlevel >= extendedlist.getitemvalue(i)) { itemstorage.add(new itemstorage() { item = (extendedlist.items)extendedlist.getitemvalue(i), material = materialstorage }); } }
on start initializes perfect. @ material list (bronze) , in item list (helmet) when level call function. in material list (bronze, bronze) , in item list (helmet, helmet) instead of (bronze) , (helmet).\
edit : (forgot) : when player level 0 initializes bronze. when reaches level 5 adding new list. instead of bronze iron. want add new list when player level equalls value give iron, steel, silver, platinum, etc.
i hope guys can me sticky situation.
best wishes, , have day.
the reason getting [bronze, bronze] @ level2 in materialstorage list (instead of [bronze]) because adding values list materialstorage.add, seems me want initialize new list every time method runs, before iterate through enums in loops, set materialstorage , itemstorage new lists.
also dont entirely understand reason having materialstorage list defined twice if appear same value. have defined @ gamemanager level , again in each itemstorage object. if understand edit statement correctly, seems want list of lists number of lists equal number of level increments so:
0: [[bronze]] 5: [[bronze], [bronze,iron]] 10: [[bronze], [bronze,iron], [bronze,iron,steel]] ...
in case need dictionary, 1 maps player level separate list of materials. can initialize @ in main gamemanager class. number of keys in dictionary equals number of elements in enum, so:
dictionary<int, list<materialstorage>> leveltomaterialsmap = new dictionary<int, list<materialstorage>>(); (int = 0; < enum.getvalues(typeof(extendedlist.ingots)).length; i++) { int key = extendedlist.getingotvalue(i); list<materialstorage> value = new list<materialstorage>(); leveltomaterialsmap.add(key, value); }
now every time call looping method, check see if player level 1 of levels in need add materials for, if create new materialstorage list, add materials it, set dictionary specific level key. like:
if(leveltomaterialmap.containskey(gamemanager.instance.playerlevel)) { list<materialstorage> materialstorage = new list<materialstorage>(); //do stuff need add materials player level //... //then leveltomaterialmap[gamemanager.instance.playerlevel] = materialstorage; }
Comments
Post a Comment