Score on Side

dev-hazim
Ali Sharoz 2 weeks ago
parent 8923cb6123
commit 4cc7e60091

@ -11,8 +11,8 @@ GameObject:
- component: {fileID: 1819947140988654075} - component: {fileID: 1819947140988654075}
- component: {fileID: 4509456968230162509} - component: {fileID: 4509456968230162509}
- component: {fileID: 7390439618592381581} - component: {fileID: 7390439618592381581}
- component: {fileID: 5789924600880600385}
- component: {fileID: 3693389173024101360} - component: {fileID: 3693389173024101360}
- component: {fileID: 4947760305271843048}
m_Layer: 5 m_Layer: 5
m_Name: PlayerItem m_Name: PlayerItem
m_TagString: Untagged m_TagString: Untagged
@ -79,20 +79,6 @@ MonoBehaviour:
m_FillOrigin: 0 m_FillOrigin: 0
m_UseSpriteMesh: 0 m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1 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 --- !u!114 &3693389173024101360
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -105,7 +91,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
GlobalObjectIdHash: 0 GlobalObjectIdHash: 2641544669
InScenePlacedSourceGlobalObjectIdHash: 0 InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0 AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1 SynchronizeTransform: 1
@ -114,6 +100,20 @@ MonoBehaviour:
SpawnWithObservers: 1 SpawnWithObservers: 1
DontDestroyWithOwner: 0 DontDestroyWithOwner: 0
AutoObjectParentSync: 1 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 --- !u!1 &7049133288593759141
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -1612,6 +1612,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7df4fbc7cb5d44c42aeadfa5b2ea67fb, type: 3} m_Script: {fileID: 11500000, guid: 7df4fbc7cb5d44c42aeadfa5b2ea67fb, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_PlayerScoreComponents: []
playerItems: [] playerItems: []
playerItemPrefab: {fileID: 2970943852697257760, guid: 43de682fd88241b4e83d2fc606d8b6c1, type: 3} playerItemPrefab: {fileID: 2970943852697257760, guid: 43de682fd88241b4e83d2fc606d8b6c1, type: 3}
Parent: {fileID: 1527274046} Parent: {fileID: 1527274046}
@ -8976,6 +8977,10 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5762482089640033414, guid: 8b9c63e7d70c5ff48a03aad51e17103c, type: 3}
propertyPath: scoreboard
value:
objectReference: {fileID: 476537028}
- target: {fileID: 5762482089640033414, guid: 8b9c63e7d70c5ff48a03aad51e17103c, type: 3} - target: {fileID: 5762482089640033414, guid: 8b9c63e7d70c5ff48a03aad51e17103c, type: 3}
propertyPath: m_PlayerSpawnPoints.Array.size propertyPath: m_PlayerSpawnPoints.Array.size
value: 7 value: 7
@ -9390,7 +9395,7 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0.3943448 value: 0.39434478
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
@ -9430,11 +9435,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.30972984 value: 0.3097298
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734516695783279, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.1450697 value: -0.14506969
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734516724634599, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734516724634599, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
@ -9593,15 +9598,15 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0.39434484 value: 0.3943448
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 0.3104465 value: 0.31044647
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.1435298 value: -0.14352977
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3} - target: {fileID: 203267159508449512, guid: 36b3ee75677a1544191c0ddaaadd8140, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x

@ -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);
}
}
}
}

@ -61,7 +61,7 @@ namespace Unity.BossRoom.Gameplay.GameState
[Inject] ConnectionManager m_ConnectionManager; [Inject] ConnectionManager m_ConnectionManager;
[Inject] PersistentGameState m_PersistentGameState; [Inject] PersistentGameState m_PersistentGameState;
public Scoreboard scoreboard;
protected override void Awake() protected override void Awake()
{ {
base.Awake(); base.Awake();
@ -173,7 +173,6 @@ namespace Unity.BossRoom.Gameplay.GameState
var playerNetworkObject = NetworkManager.Singleton.SpawnManager.GetPlayerNetworkObject(clientId); var playerNetworkObject = NetworkManager.Singleton.SpawnManager.GetPlayerNetworkObject(clientId);
var newPlayer = Instantiate(m_PlayerPrefab, Vector3.zero, Quaternion.identity); var newPlayer = Instantiate(m_PlayerPrefab, Vector3.zero, Quaternion.identity);
var newPlayerCharacter = newPlayer.GetComponent<ServerCharacter>(); var newPlayerCharacter = newPlayer.GetComponent<ServerCharacter>();
var physicsTransform = newPlayerCharacter.physicsWrapper.Transform; var physicsTransform = newPlayerCharacter.physicsWrapper.Transform;
@ -216,6 +215,9 @@ namespace Unity.BossRoom.Gameplay.GameState
// spawn players characters with destroyWithScene = true // spawn players characters with destroyWithScene = true
newPlayer.SpawnWithOwnership(clientId, true); newPlayer.SpawnWithOwnership(clientId, true);
//var playerScoreComponent = newPlayer.GetComponent<PlayerScoreComponent>();
scoreboard.ScoreBoardListFiller(newPlayer);
} }
void OnLifeStateChangedEventMessage(LifeStateChangedEventMessage message) void OnLifeStateChangedEventMessage(LifeStateChangedEventMessage message)

@ -4,11 +4,11 @@ using Unity.Multiplayer.Samples.BossRoom;
using UnityEngine; using UnityEngine;
using Unity.Netcode; using Unity.Netcode;
using TMPro; using TMPro;
namespace Unity.Multiplayer.Samples.BossRoom //namespace Unity.Multiplayer.Samples.BossRoom
{ //{
public class PlayerItem : MonoBehaviour public class PlayerItem : MonoBehaviour
{ {
public TextMeshProUGUI PlayerName; public TextMeshProUGUI PlayerName;
public TextMeshProUGUI PlayerScore; public TextMeshProUGUI PlayerScore;
} }
} //}

@ -6,7 +6,7 @@ public class PlayerScoreComponent : NetworkBehaviour
{ {
public int CurrentScore { get; private set; } public int CurrentScore { get; private set; }
public ServerCharacter serverCharacter; public ServerCharacter serverCharacter;
public int index; public int m_index;
public override void OnNetworkSpawn() public override void OnNetworkSpawn()
{ {
if (IsOwner && IsClient) if (IsOwner && IsClient)

@ -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…
Cancel
Save