简体   繁体   中英

Unity storing an item in c#

so I have 100 items that I need to store in some sort of array. Each item has an att, def, cost, lvl, name and id(array key) value

What would be the best way to store them, keep in mind that i will need to sort the att and def values in descending order. While I have easily done this with php I am having some trouble with c#.

IF anyone could help provide a working example with just a couple of items that would be great thanks.

I am using unity and c#

Define a structure to store all the attribute:

class Enemy 
{
    public int Attack { get; set; }
    public int Defend { get; set; }
    public int Cost { get; set; }
    public ....
}

Then store all in a list:

var enemies = new List<Enemy>();
...

You can sort the enemies by anything

var sortedEnemies = enemies.OrderBy(item => item.Attack).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM