diff --git a/Assets/Prefabs/PlayerItem.prefab b/Assets/Prefabs/PlayerItem.prefab index d65acbe..666df7d 100644 --- a/Assets/Prefabs/PlayerItem.prefab +++ b/Assets/Prefabs/PlayerItem.prefab @@ -11,8 +11,8 @@ GameObject: - component: {fileID: 1819947140988654075} - component: {fileID: 4509456968230162509} - component: {fileID: 7390439618592381581} - - component: {fileID: 5789924600880600385} - component: {fileID: 3693389173024101360} + - component: {fileID: 4947760305271843048} m_Layer: 5 m_Name: PlayerItem m_TagString: Untagged @@ -79,20 +79,6 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!114 &5789924600880600385 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2970943852697257760} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0dd49e4fefe1c0444abd48c3b4c193be, type: 3} - m_Name: - m_EditorClassIdentifier: - PlayerName: {fileID: 2955079016503491369} - PlayerScore: {fileID: 8823867059228070186} --- !u!114 &3693389173024101360 MonoBehaviour: m_ObjectHideFlags: 0 @@ -105,7 +91,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} m_Name: m_EditorClassIdentifier: - GlobalObjectIdHash: 0 + GlobalObjectIdHash: 2641544669 InScenePlacedSourceGlobalObjectIdHash: 0 AlwaysReplicateAsRoot: 0 SynchronizeTransform: 1 @@ -114,6 +100,20 @@ MonoBehaviour: SpawnWithObservers: 1 DontDestroyWithOwner: 0 AutoObjectParentSync: 1 +--- !u!114 &4947760305271843048 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2970943852697257760} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0dd49e4fefe1c0444abd48c3b4c193be, type: 3} + m_Name: + m_EditorClassIdentifier: + PlayerName: {fileID: 2955079016503491369} + PlayerScore: {fileID: 8823867059228070186} --- !u!1 &7049133288593759141 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/BossRoom.unity b/Assets/Scenes/BossRoom.unity index 3c88d68..aec52c6 100644 --- a/Assets/Scenes/BossRoom.unity +++ b/Assets/Scenes/BossRoom.unity @@ -1612,6 +1612,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7df4fbc7cb5d44c42aeadfa5b2ea67fb, type: 3} m_Name: m_EditorClassIdentifier: + m_PlayerScoreComponents: [] playerItems: [] playerItemPrefab: {fileID: 2970943852697257760, guid: 43de682fd88241b4e83d2fc606d8b6c1, type: 3} Parent: {fileID: 1527274046} @@ -8976,6 +8977,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 5762482089640033414, guid: 8b9c63e7d70c5ff48a03aad51e17103c, type: 3} + propertyPath: scoreboard + value: + objectReference: {fileID: 476537028} - target: {fileID: 5762482089640033414, guid: 8b9c63e7d70c5ff48a03aad51e17103c, type: 3} propertyPath: m_PlayerSpawnPoints.Array.size value: 7 @@ -9390,7 +9395,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.x - value: 0.3943448 + value: 0.39434478 objectReference: {fileID: 0} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.y @@ -9430,11 +9435,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.y - value: 0.30972984 + value: 0.3097298 objectReference: {fileID: 0} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalRotation.z - value: -0.1450697 + value: -0.14506969 objectReference: {fileID: 0} - target: {fileID: 1676734516724634599, guid: 0193228de87741d40a42e561901c9083, type: 3} propertyPath: m_LocalPosition.z @@ -9593,15 +9598,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.x - value: 0.39434484 + value: 0.3943448 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.y - value: 0.3104465 + value: 0.31044647 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalRotation.z - value: -0.1435298 + value: -0.14352977 objectReference: {fileID: 0} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} propertyPath: m_LocalEulerAnglesHint.x diff --git a/Assets/Scoreboard.cs b/Assets/Scoreboard.cs deleted file mode 100644 index 97ae7f6..0000000 --- a/Assets/Scoreboard.cs +++ /dev/null @@ -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 m_PlayerScoreComponents; - public List playerItems; - public GameObject playerItemPrefab; - public Transform Parent; - public override void OnNetworkSpawn() - { - if (IsServer) - { - Starter(); - } - } - public void Starter() - { - playerScoreComponents = FindObjectsOfType(); - 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()); - 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); - } - } - } -} diff --git a/Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs b/Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs index 4f89fd3..31c5a98 100644 --- a/Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs +++ b/Assets/Scripts/Gameplay/GameState/ServerBossRoomState.cs @@ -61,7 +61,7 @@ namespace Unity.BossRoom.Gameplay.GameState [Inject] ConnectionManager m_ConnectionManager; [Inject] PersistentGameState m_PersistentGameState; - + public Scoreboard scoreboard; protected override void Awake() { base.Awake(); @@ -173,7 +173,6 @@ namespace Unity.BossRoom.Gameplay.GameState var playerNetworkObject = NetworkManager.Singleton.SpawnManager.GetPlayerNetworkObject(clientId); var newPlayer = Instantiate(m_PlayerPrefab, Vector3.zero, Quaternion.identity); - var newPlayerCharacter = newPlayer.GetComponent(); var physicsTransform = newPlayerCharacter.physicsWrapper.Transform; @@ -216,6 +215,9 @@ namespace Unity.BossRoom.Gameplay.GameState // spawn players characters with destroyWithScene = true newPlayer.SpawnWithOwnership(clientId, true); + + //var playerScoreComponent = newPlayer.GetComponent(); + scoreboard.ScoreBoardListFiller(newPlayer); } void OnLifeStateChangedEventMessage(LifeStateChangedEventMessage message) diff --git a/Assets/PlayerItem.cs b/Assets/Scripts/Gameplay/PlayerItem.cs similarity index 84% rename from Assets/PlayerItem.cs rename to Assets/Scripts/Gameplay/PlayerItem.cs index ac19091..0cde315 100644 --- a/Assets/PlayerItem.cs +++ b/Assets/Scripts/Gameplay/PlayerItem.cs @@ -4,11 +4,11 @@ using Unity.Multiplayer.Samples.BossRoom; using UnityEngine; using Unity.Netcode; using TMPro; -namespace Unity.Multiplayer.Samples.BossRoom -{ +//namespace Unity.Multiplayer.Samples.BossRoom +//{ public class PlayerItem : MonoBehaviour { public TextMeshProUGUI PlayerName; public TextMeshProUGUI PlayerScore; } -} +//} diff --git a/Assets/PlayerItem.cs.meta b/Assets/Scripts/Gameplay/PlayerItem.cs.meta similarity index 100% rename from Assets/PlayerItem.cs.meta rename to Assets/Scripts/Gameplay/PlayerItem.cs.meta diff --git a/Assets/Scripts/Gameplay/PlayerScoreComponent.cs b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs index 53f1f20..8ae864f 100644 --- a/Assets/Scripts/Gameplay/PlayerScoreComponent.cs +++ b/Assets/Scripts/Gameplay/PlayerScoreComponent.cs @@ -6,7 +6,7 @@ public class PlayerScoreComponent : NetworkBehaviour { public int CurrentScore { get; private set; } public ServerCharacter serverCharacter; - public int index; + public int m_index; public override void OnNetworkSpawn() { if (IsOwner && IsClient) diff --git a/Assets/Scripts/Gameplay/Scoreboard.cs b/Assets/Scripts/Gameplay/Scoreboard.cs new file mode 100644 index 0000000..2e4b3a4 --- /dev/null +++ b/Assets/Scripts/Gameplay/Scoreboard.cs @@ -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 m_PlayerScoreComponents; + public List 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()); + 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(); + 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); + } + } + } +} diff --git a/Assets/Scoreboard.cs.meta b/Assets/Scripts/Gameplay/Scoreboard.cs.meta similarity index 100% rename from Assets/Scoreboard.cs.meta rename to Assets/Scripts/Gameplay/Scoreboard.cs.meta