예제 #1
0
        public void Show(Dictionary <string, PlayerScoreData> chefsScoreData)
        {
            int count = 0;

            foreach (KeyValuePair <string, PlayerScoreData> chefScoreData in chefsScoreData)
            {
                m_ChefName[count].text = chefScoreData.Key.ToString();
                m_Contents[count].transform.ClearChildren();
                List <int> scores = chefScoreData.Value.scores.OrderByDescending(ele => ele).ToList();
                for (int i = 0; i < scores.Count && i < 10; ++i)
                {
                    UIScoreItem scoreItem = Instantiate <UIScoreItem>(m_Template, m_Contents[count]);
                    scoreItem.text.text = scores[i].ToString();
                }

                ++count;
            }
        }
예제 #2
0
    public void OnScoreInfo(NetworkMessage netMsg)
    {
        MObjects.ScoreInfo mObject = netMsg.ReadMessage <MObjects.ScoreInfo>();

        ushort c = (ushort)mObject.ids.Length;

        for (ushort i = 0; i < c; i++)
        {
            // find team grid first
            Transform tGrid = score_grid.Find(mObject.teams[i].ToString());
            if (tGrid == null)
            {
                // team not found
                tGrid      = Instantiate(score_teamPrefab, score_grid);
                tGrid.name = mObject.teams[i].ToString();
                Color color = new Color(teamColors[mObject.teams[i]].r, teamColors[mObject.teams[i]].g, teamColors[mObject.teams[i]].b, 0.5f);
                tGrid.GetComponent <Image>().color = color;
            }

            // find player prefab

            MobileAgent ma = MobileAgent.list.Find(x => x.id == mObject.ids[i]);

            Transform p = tGrid.Find(mObject.ids[i].ToString());
            if (p == null)
            {
                // player not found
                p      = Instantiate(score_playerPrefab, tGrid);
                p.name = mObject.ids[i].ToString();

                if (ma != null)
                {
                    p.Find("icon").GetComponent <Image>().sprite = icons.Find(x => x.name == ma.clientPrefab);
                }
            }

            p.Find("kills").GetComponent <Text>().text = Language.GetText(46) + " " + mObject.kills[i].ToString();
            p.Find("death").GetComponent <Text>().text = Language.GetText(47) + " " + mObject.deaths[i].ToString();

            UIScoreItem usi = p.GetComponent <UIScoreItem>();
            usi.kills  = mObject.kills[i];
            usi.deaths = mObject.deaths[i];

            if (ma != null)
            {
                p.Find("name").GetComponent <Text>().text = ma.alias;
            }
        }

        /*
         * SORT ALL
         */

        // Sort teams first
        ushort e = (ushort)score_grid.childCount;

        short[] teamScores = new short[e];

        for (int i = 0; i < e; i++)
        {
            ushort teamId = ushort.Parse(score_grid.GetChild(i).name);
            // find my scorers
            for (int a = 0; a < c; a++)
            {
                if (mObject.teams[a] == teamId)
                {
                    teamScores[i] += (short)(mObject.kills[a]);
                }
            }

            score_grid.GetChild(i).GetComponentInChildren <Text>().text = teamScores[i].ToString();
        }

        List <Transform> teams = new List <Transform>();

        for (int i = 0; i < e; i++)
        {
            teams.Add(score_grid.GetChild(i));
        }

        teams = teams.OrderByDescending(x => short.Parse(x.GetComponentInChildren <Text>().text)).ToList();

        for (int i = 0; i < e; i++)
        {
            teams[i].SetSiblingIndex(i);
        }

        /*
         * SORT PLAYERS
         * */

        for (int i = 0; i < e; i++)
        {
            Transform team = score_grid.GetChild(i);
            ushort    cc   = (ushort)team.childCount;

            List <Transform> players = new List <Transform>();
            for (int a = 1; a < cc; a++)
            { // search every member
                players.Add(team.GetChild(a));
            }

            players = players.OrderByDescending(x => x.GetComponent <UIScoreItem>().kills).ThenBy(x => x.GetComponent <UIScoreItem>().deaths).ToList();

            cc = (ushort)players.Count;
            for (int p = 0; p < cc; p++)
            {
                players[p].SetSiblingIndex(p + 1);
            }
        }
    }