简体   繁体   English

unity在C#中存储项目

[英]Unity storing an item in c#

so I have 100 items that I need to store in some sort of array. 所以我有100个项目需要存储在某种数组中。 Each item has an att, def, cost, lvl, name and id(array key) value 每个项目都有一个att,def,cost,lvl,name和id(数组键)值

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. 最好的存储方式是什么,请记住,我将需要按降序对at和def值进行排序。 While I have easily done this with php I am having some trouble with c#. 虽然我很容易用php完成此操作,但是我在使用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# 我正在使用unity和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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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