using System;
using System.Collections;
using UnityEngine;
[CreateAssetMenu(fileName = "New Item", menuName = "Item/Create New Item")]
public class Item : ScriptableObject
{
public int id;
public string itemName;
public Sprite icon;
public string globaltype;
public int amount;
[Serializable]
public class ConsumeStats
{
public bool consumable;
public string consumetype;
public int value;
}
[Serializable]
public class EquipStats
{
public bool equipable;
public string equiptype;
public string type;
public int ammo;
}
[Serializable]
public class CraftStats1
{
public bool craftable;
public int requireid1;
public int requireamount1;
public int stackamount;
public CraftStats2 SecondItem;
}
[Serializable]
public class CraftStats2
{
public bool req2item;
public bool toolincluded;
public int requireid2;
public int requireamount2;
}
[SerializeField] public ConsumeStats Consumable;
[SerializeField] public EquipStats Equipable;
[SerializeField] public CraftStats1 Craftable;
}
I wanted to tidy up the Item Database and I’ve searched a while and found that I can use classes or structs in the script to split the variables to groups. The variables were shown and assignable on the inspector but I have lost all my references on other scripts. How can I reference the classes in the script or is there a easier way?
If you change how it’s structured, you’re usually going to have to re-do your references, unfortunately. There’s kind of no way for it to know what’s what.
Alternatively, instead of using classes, you can separate the values in the Inspector by using the Header Attribute, it may save you some headaches. This however, won’t allow you to minimize groups without doing some extra work.
Same way you reference any accessible field or property.
Say you’ve got a reference to one of these items and you want to know if it’s consumable, you’d get the bool with bool consumable = item.Consumable.consumable;.
Do note that public member names should be capitalised.