Hi all, sure this need has been requested before …
I came from Blender, and there I kept for the logical mechanic about Objects and Characters in the game in a Global Dictionary (globalDict). The inconvenience is now to work by Unity I can’t create a Dictionary with multiple parameters, like a List or Arrays…
For example in Blender/Python I had something like this…
logic.globalDict["ObjectsID"] = {
1:{
'Name':'Name for Object1',
'Desc':'A description for Object1',
'Txt':'A show text for Object 1',
'Usable':'Yes',
'Dropeable':'Yes',
'IDCombinable': 0,
},
2:{
'Name':'Name for Object2',
'Desc':'A description for Object2',
'Txt':'A show text for Object2',
'Usable':'Yes',
'Dropeable':'Yes',
'IDCombinable': 3,
},
3:{
'Name':'Name for Object3',
'Desc':'A description of Object3',
'Txt':'A show text for Object3',
'Usable':'No',
'Dropeable':'Yes',
'IDCombinable': 2,
},
...
}
I have look around to make in similar way in unity but I haven’t seen, I found this http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use? but no ones is so complete like a multiple dictionary, and the other choice is to create differents arraysList but not all in one. I’m trying to make a dinamic and useful way to interactuate with the different items in the scene, and I think create a script and attach them to all the interactive items in the scene is the way…
I would aprecciated if somebody can guide me to follow the regular way for this common technic in games or show me an example project.
I think you could just use a list in the same way. However, if it were me, I would attach a script component to each object with those variables, and edit them in the editor or by scripting. You could use a tag to group them, or put a reference to each object in a list and edit them that way also by using object.GetComponent.
Thank you for response, but how you create a List with multiple parameters?, I suppouse must be different lists, each one for each property … nameList, DescList… or how you mean? Anybody can show a example? It should be a common use (trading with objetcs, inventory management, character dialogs…). Something else I’ve thinked is to store them in a database …
1.) Create a class or struct with the variables you need. We’ll call this class/struct “Thingy”
2.) Create a List or Dictionary<int, Thingy>
3.) ?
4.) Profit
But in all seriousness, you would create a class or struct that contains the variables you need for the objects:
//C# Example
public class Thingy {
public string Name;
public string Desc;
public string Txt;
public bool Usable;
public bool Dropable;
public int IDCombinable;
}
And then you would use it in a List or Dictionary<int, Thingy>, with the Dictionary<int, Thingy> being roughly the equivalent to what you posted.
You would of course, like XGundam05 suggested, need a class to contain the variables. And if you’re looking to represent multiple objects with the same dictionary key, you can use a List as the Value type. Example:
logic.globalDict = new Dictionary<string, List<Thingy>>();
of course, every time you add a new object id you’ll need to initialize it with a new List().
First at all thank you both for your help, I’m newbie in Unity and “POO”…
So the methodoly is the next…
Create in a separate file the Class “Thingy” (unique in the project…)
Create another script Object with the List or Dictionary, and in the same file instantiated and defined all the objects with the previous class (must be predefined, no filled in game time…)
Attach this script to all interactive objects in the scene …
¿?
If somebody can paste (pasteAll?) a real example is much better to realize it …
Anyway I’m gonna trying by my self…