List of 2 different types

Hey everyone,
Currently I have a situation which means that I have 2 lists:

    public static List<ClickingUpgrade> clickUpgrades = new List<ClickingUpgrade>();
    public static List<SecondsUpgrade> secondsUpgrades = new List<SecondsUpgrade>();

(I chose lists as I hear that they are better performing for editing at runtime which I may need to do - although confirmation may help)
However, I would love to try and tidy this up as because of the 2 lists situation I have to do things like this:

        foreach(ClickingUpgrade click in clickUpgrades)
        {
            Debug.Log(click.name + " Saved");
            PlayerPrefs.SetInt(click.name, click.cost);
        }
        foreach(SecondsUpgrade click in secondsUpgrades)
        {
            Debug.Log(click.name + " Saved");
            PlayerPrefs.SetInt(click.name, click.cost);
        }

and

PlayerManager.clickUpgrades = FindObjectsOfType<ClickingUpgrade>().ToList();
        PlayerManager.secondsUpgrades = FindObjectsOfType<SecondsUpgrade>().ToList();

I know that there must be an easier way to sort this out and create a single list but I simply have not got experience doing this yet.
I am sure that I probably should be doing something like this:

However, help would be appreciated!
Thanks in advance.

You can use a List<> of an Interface implemented in both classes.

@L-Tyrosine 's idea would work, or alternatively you could make your ClickingUpgrade and SecondsUpgrades objects subclasses of a common parent, like class Upgrade for example. Then you could simply have a List.

1 Like

That sounds good thanks just looked into it.