You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
4 weeks ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using Unity.Multiplayer.Samples.BossRoom;
|
||
|
using UnityEngine;
|
||
|
using Unity.BossRoom.Gameplay.GameState;
|
||
|
using Unity.Netcode;
|
||
|
using VContainer.Unity;
|
||
|
public class Scoreboard : MonoBehaviour
|
||
|
{
|
||
|
public List<PlayerScoreComponent> m_PlayerScoreComponents;
|
||
|
public List<PlayerItem> playerItems;
|
||
|
public GameObject playerItemPrefab;
|
||
|
public Transform Parent;
|
||
|
int index = 0;
|
||
|
bool coroutineStarter = false;
|
||
|
private IEnumerator Start()
|
||
|
{
|
||
|
Debug.Log("Scoreboard start1");
|
||
|
yield return new WaitUntil(() => coroutineStarter == true);
|
||
|
Debug.Log("Scoreboard start2");
|
||
|
yield return new WaitForSeconds(2);
|
||
|
Debug.Log("Scoreboard start3");
|
||
|
Starter();
|
||
|
Debug.Log("Scoreboard start4");
|
||
|
}
|
||
|
public void ScoreBoardListFiller(NetworkObject playerObj)
|
||
|
{
|
||
|
|
||
|
m_PlayerScoreComponents.Add(playerObj.GetComponent<PlayerScoreComponent>());
|
||
|
m_PlayerScoreComponents[m_PlayerScoreComponents.Count - 1].m_index = index;
|
||
|
index++;
|
||
|
Instantiator(m_PlayerScoreComponents.Count);
|
||
|
if (!coroutineStarter)
|
||
|
{
|
||
|
coroutineStarter = true;
|
||
|
}
|
||
|
}
|
||
|
public void Starter()
|
||
|
{
|
||
|
StartCoroutine(ScoreUpdater());
|
||
|
}
|
||
|
public void Instantiator(int count)
|
||
|
{
|
||
|
for (int i = 0; i < count; i++)
|
||
|
{
|
||
|
GameObject temp = Instantiate(playerItemPrefab, Parent);
|
||
|
PlayerItem item = temp.GetComponent<PlayerItem>();
|
||
|
playerItems.Add(item);
|
||
|
playerItems[playerItems.Count-1].PlayerScore.text = m_PlayerScoreComponents[i].CurrentScore.ToString();
|
||
|
playerItems[i].PlayerName.text = m_PlayerScoreComponents[i].serverCharacter.uIStateDisplayHandler.m_UIState.playerName.ToString();
|
||
|
}
|
||
|
}
|
||
|
IEnumerator ScoreUpdater()
|
||
|
{
|
||
|
|
||
|
yield return new WaitForSeconds(0.5f);
|
||
|
Debug.Log("Scoreboard start5");
|
||
|
while (true)
|
||
|
{
|
||
|
yield return new WaitForSeconds(0.1f);
|
||
|
m_PlayerScoreComponents.Sort((p1, p2) => p2.CurrentScore.CompareTo(p1.CurrentScore));
|
||
|
for (int i = 0; i < playerItems.Count; i++)
|
||
|
{
|
||
|
playerItems[i].transform.SetSiblingIndex(m_PlayerScoreComponents[i].m_index);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|