Score on Side
parent
8923cb6123
commit
4cc7e60091
@ -1,53 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Multiplayer.Samples.BossRoom;
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
public class Scoreboard : NetworkBehaviour
|
||||
{
|
||||
PlayerScoreComponent[] playerScoreComponents;
|
||||
List<PlayerScoreComponent> m_PlayerScoreComponents;
|
||||
public List<PlayerItem> playerItems;
|
||||
public GameObject playerItemPrefab;
|
||||
public Transform Parent;
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
if (IsServer)
|
||||
{
|
||||
Starter();
|
||||
}
|
||||
}
|
||||
public void Starter()
|
||||
{
|
||||
playerScoreComponents = FindObjectsOfType<PlayerScoreComponent>();
|
||||
for (int i = 0; i < playerScoreComponents.Length; i++)
|
||||
{
|
||||
playerScoreComponents[i].index = i;
|
||||
m_PlayerScoreComponents.Add(playerScoreComponents[i]);
|
||||
}
|
||||
Instantiator(playerScoreComponents.Length);
|
||||
StartCoroutine(ScoreUpdater());
|
||||
}
|
||||
public void Instantiator(int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
playerItems.Add(Instantiate(playerItemPrefab, Parent).GetComponent<PlayerItem>());
|
||||
playerItems[i].PlayerScore.text = playerScoreComponents[i].CurrentScore.ToString();
|
||||
playerItems[i].PlayerName.text = playerScoreComponents[i].serverCharacter.uIStateDisplayHandler.m_UIState.playerName.ToString();
|
||||
}
|
||||
}
|
||||
IEnumerator ScoreUpdater()
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
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].index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue