Inventory Pro

Item properties


Looping through all properties of an item.


using UnityEngine;
using Devdog.InventorySystem;

public class MyClass
{
	public InventoryItemBase item;
	
	public void Awake()
	{
		foreach (var prop in item.properties)
		{
                     // prop.name; // Use name (property name as defined in editor name)
                     //	prop.value; // Use value
		}
	}
}

Naturally properties can also be modified / added / removed at run-time. In order to add and remove properties values will have to be temporarily be copied to a list (or other data structure that allows adding / removing), and once completed be copied back to a regular array.


var l = new List(item.properties); // Create a new list that we can add to and remove from.
var myNewProperty = new InventoryItemProperty(){ name = "Strength", value = "3" };
l.Add(myNewProperty); // Add our own property
item.properties = l.ToArray(); // Convert to an array and set.