tl;dr: Debug.Log(list) returns System.Collections.Generic.List`1[ItemDatabase+item], but for a method I need to return direct reference to the list or something. What happen, what do
I have a bit of a clusterfuck of systems going on, so let me try to explain what’s happening.
Inside my ItemDatabase.cs I have a ListA of equipment slot types classA (weapon, arm, whatever), that has a ListB that contains all instances of classB (weapon001, arm048, etc) within said equipment slot type, yeah?
For debugging purposes I’m trying to get ListA.classA.ListB, but it always returns System.Collections.Generic.List`1[ItemDatabase+item], even if I change the list. I’m having trouble figuring out why I’m not getting a specific list, but instead just that generic list message with the class types. ToString() doesn’t actually affect the debug message at all, but I’m not entirely sure I know what it’s supposed to do to begin with. Anyway, I need the actual list so I can assign it to an event with a method.
Here’s some bits of code in case that makes things simpler:
EquipmentMenu
public class EquipmentMenu : MonoBehaviour {
public GameObject buttonPrefab; // Button prefab
void Start() {
// Add equipment slot buttons
CreateButtons (ItemDatabase.slotTypes);
}
// Create buttons from SLOT list
public void CreateButtons(List<ItemDatabase.slot> list) { // Take slotTypes from ItemDatabase
foreach (ItemDatabase.slot slot in list) { // For each slot type in slotTypes
GameObject go = (GameObject)Instantiate (buttonPrefab); // Instantiate button prefab as go
string objectID = slot.name; // Temporary storage for slot string, needed?
go.transform.GetComponentInChildren<Text> ().text = objectID; // Change text to slot type's name
Button b = go.GetComponent<Button> ();
b.onClick.AddListener (delegate {CreateButtons (slot.contents);}); // Add click event for CreateButtons. Slot.contents is a List of items (coreBase, armBase etc)
// Createbuttons executes different code when given a list of items (contents) instead of a list of slots
Debug.Log("Added button listener for " + objectID + " as CreateButtons " + slot.contents.ToString());
}
}
// Create buttons from ITEM list
public void CreateButtons(List<ItemDatabase.item> list) {
// Blah blah do something else
}
ItemDatabase
public class ItemDatabase : MonoBehaviour {
public class item { // Values for each individual equipment
// Values blah blah
}
public class slot {
public string name = "";
public List<item> contents = null; // List of items for this slot (coreBase, armBase etc)
}
public static List<slot> slotTypes = new List<slot> (); // List of equipment slot types
static List<item> coreBase = new List<item>(); // Core database
static List<item> armBase = new List<item>(); // Arm database
void Awake () {
// --------- Fill core database ---------------------------
List<item> cb = coreBase;
item core01 = new item {
name = "Core01",
slot = "core"
};
cb.Add (core01);
item core02 = new item {
name = "Core02",
slot = "core"
};
cb.Add (core02);
// --------- Fill arm database ---------------------------
List<item> ab = armBase;
item minigunL = new item {
name = "MinigunL",
slot = "arm"
};
ab.Add (minigunL);
// --------- Fill slot database ---------------------------
List<slot> sb = slotTypes;
slot core = new slot {
name = "Core",
contents = coreBase
};
sb.Add (core);
slot armR = new slot {
name = "Arm R",
contents = armBase
};
sb.Add (armR);
slot armL = new slot {
name = "Arm L",
contents = armBase
};
sb.Add (armL);
}
}
I tried to edit out most irrelevant stuff, hope it’s clear enough.
Or maybe I’m just completely misunderstanding what my problem is. Enlighten me, please?
EDIT: Solved, I’m an idiot. Added List<ItemDatabase.item> listID = slot.contents; in a similar manner to what I did with objectID and changed (delegate {CreateButtons (slot.contents);}); to (delegate {CreateButtons (listID);});