Giter Club home page Giter Club logo

Comments (3)

wesleywh avatar wesleywh commented on June 25, 2024

Done. This has been implemented and will be part of v0.3.6 release.

from easymultiplayer-invector.

AmmarTee avatar AmmarTee commented on June 25, 2024

It is not fixed We are testing on the latest release

from easymultiplayer-invector.

AmmarTee avatar AmmarTee commented on June 25, 2024
using UnityEngine;
using EMI.Utils;
using EMI.Managers;
using UnityEngine.UI;
using System.Collections;
using System.Linq;

namespace EMI.UI
{
    /// <summary>
    /// A very simple script showing how you can tie into the available callback and populate
    /// a list of player names and tie it to their total kill count;
    /// </summary>
    public class KillCounterPlayerList : MonoBehaviour
    {
        #region Properties
        [SerializeField, Tooltip("The text to update, if not supplied will try to auto populate")] protected Text textComp = null;
        #endregion

        #region Init
        protected virtual void Start()
        {
            StartCoroutine(InitCallback());
            if (textComp == null) textComp = GetComponent<Text>();
        }
        protected virtual IEnumerator InitCallback()
        {
            yield return new WaitUntil(() => KillCounterUI.instance != null);
            KillCounterUI.instance.OnKillCounterUpdated += KillCountUpdated;
        }
        #endregion

        #region KillCount Updated
        /// <summary>
	    /// This is called every single time the killCounter is updated. //Default Broken
        /// </summary>
        //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter)
        //{
	    //    string playerName;
        //    string tmpString = "";
        //    foreach (KeyValuePair<int, int> item in killCounter)
        //    {
        //        ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
	    //        playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
	    //        //if((playerName[0])!='-'){
	    //        //}
	    //        //else
	    //        //{
		//        //    tmpString += $"{playerName} : {item.Value}\n";
	    //        //}
	    //        //if((playerName[0])=='-')
	    //        //{
	            	
	    //        //}
	    //        //else
	    //        tmpString += $"{playerName} : {item.Value}\n";

        //    }
        //    if (textComp) textComp.text = tmpString;
	    //}
	    //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Git Hub Broken
	    //{
		//    string playerName;
		//    string tmpString = "";
		//    Dictionary<string, int> playerNameDictionary = new Dictionary<string, int>();
		//    foreach (KeyValuePair<int, int> item in killCounter)
		//    {
		//	    ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
		//	    playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
		//	    playerNameDictionary.Add(playerName, item.Value);
		//    }
		//    foreach (KeyValuePair<string, int> item in playerNameDictionary.OrderByDescending(x => x.Key))
		//    {
		//	    tmpString += $"{item.Key} : {item.Value}\n";
		//    }
		//    if (textComp) textComp.text = tmpString;
		    
		//    Debug.Log(tmpString);
	    //}
	    //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Works
	    //{
		//    string playerName;
		//    string tmpString = "";
		//    foreach (KeyValuePair<int, int> item in killCounter)
		//    {
		//	    ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
		//	    playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
		//	    tmpString += $"{playerName} : {item.Value}\n";
		//    }
		//    if (textComp) textComp.text = tmpString;
	    //}
	    
	    protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Ammars
	    {
		    string playerName;
		    string tmpString = "";
		    Dictionary<string, int> playerNameDictionary = new Dictionary<string, int>();
		    foreach (KeyValuePair<int, int> item in killCounter)
		    {
			    ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
			    playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
			    playerNameDictionary.Add(playerName, item.Value);
			    //tmpString += $"{playerName} : {item.Value}\n";
		    }
		    foreach (KeyValuePair<string, int> item in playerNameDictionary.OrderByDescending(x => x.Key))
		        {
		    	    tmpString += $"{item.Key} : {item.Value}\n";
		        }
		    if (textComp) textComp.text = tmpString;
		    Debug.Log(tmpString);
	    }
        #endregion
    }
}

from easymultiplayer-invector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.