小编Mar*_*rco的帖子

在 Unity c# 中对列表 <string, int> 进行排序

我正在尝试为一些大学作品制作一个排名表。想到的更好的方法是为每个位置创建一个包含字符串和整数的列表。我在文档中搜索:https://unity3d.com/es/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries ?gq=sort,在那里我找到了解决我的问题的完美示例,所以我开始工作。现在,我已经创建了界面:

public class Name_Puntuation: IComparable

public string namePlayer;
public int puntuation;

public Name_Puntuation( string newNomPlayer, int newPuntuation){

    nomPlayer = newNomPlayer;
    puntuation= newPuntuation;

}

public int CompareTo(Name_Puntuation other){

    if (other == null) {
        return 1;

    }

    return Puntuation - other.Puntuation;
}
Run Code Online (Sandbox Code Playgroud)

我还在我的 GameController 中添加了我想要对列表执行的操作。该类控制游戏的画布。我们将所有信息打印到文本字段,所以我想处理排名:

public class GameController : MonoBehaviour {

    public List <Name_Puntuation> ranking;

    void Start () {

        playerName= GetComponent<MenuController> ().inp; //name the player choosed

        ranking = new List<Name_Puntuation> ();

    }

    void Update () {  }

    public void Ranking(){ …
Run Code Online (Sandbox Code Playgroud)

c# sorting list unity-game-engine

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

list ×1

sorting ×1

unity-game-engine ×1