Merge branch 'dev-ali' into dev-hazim

dev-hazim
Hazim Bin Ijaz 2 weeks ago
commit 0deaf611d4

@ -852,6 +852,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a73f85cd904406945a2192aaecb2c310, type: 3}
m_Name:
m_EditorClassIdentifier:
serverCharacter: {fileID: 741733315856861890}
m_index: 0
playerItem: {fileID: 0}
--- !u!4 &6009713983291384766 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4600110157238723791, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}

@ -0,0 +1,384 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2970943852697257760
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1819947140988654075}
- component: {fileID: 4509456968230162509}
- component: {fileID: 7390439618592381581}
- component: {fileID: 3693389173024101360}
- component: {fileID: 4947760305271843048}
m_Layer: 5
m_Name: PlayerItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1819947140988654075
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2970943852697257760}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6253493493099477558}
- {fileID: 7356930925280018859}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 500, y: 90}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4509456968230162509
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2970943852697257760}
m_CullTransparentMesh: 1
--- !u!114 &7390439618592381581
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: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.31764707}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &3693389173024101360
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: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 2641544669
InScenePlacedSourceGlobalObjectIdHash: 0
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 1
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
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6253493493099477558}
- component: {fileID: 7542418279510568437}
- component: {fileID: 2955079016503491369}
m_Layer: 5
m_Name: PlayerName
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6253493493099477558
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7049133288593759141}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1819947140988654075}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 25, y: 0}
m_SizeDelta: {x: 324.57004, y: 0}
m_Pivot: {x: 0, y: 0.5}
--- !u!222 &7542418279510568437
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7049133288593759141}
m_CullTransparentMesh: 1
--- !u!114 &2955079016503491369
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7049133288593759141}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Name
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 72
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &9018967735098624331
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7356930925280018859}
- component: {fileID: 1515101761500525564}
- component: {fileID: 8823867059228070186}
m_Layer: 5
m_Name: PlayerScore
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7356930925280018859
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9018967735098624331}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1819947140988654075}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 138.78, y: 0}
m_Pivot: {x: 1, y: 0.5}
--- !u!222 &1515101761500525564
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9018967735098624331}
m_CullTransparentMesh: 1
--- !u!114 &8823867059228070186
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9018967735098624331}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 300
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 72
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 43de682fd88241b4e83d2fc606d8b6c1
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.12731749, g: 0.13414757, b: 0.1210787, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

@ -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<ServerCharacter>();
var physicsTransform = newPlayerCharacter.physicsWrapper.Transform;
@ -216,7 +215,35 @@ namespace Unity.BossRoom.Gameplay.GameState
// spawn players characters with destroyWithScene = true
newPlayer.SpawnWithOwnership(clientId, true);
//ScoreboardCaller(newPlayer);
//ScoreboardCallerServerRpc(newPlayer);
//var playerScoreComponent = newPlayer.GetComponent<PlayerScoreComponent>();
}
//void ScoreboardCaller(NetworkObject newplayer)
//{
// scoreboard.ScoreBoardListFiller(newplayer);
//}
//[ServerRpc(RequireOwnership = false)]
//void ScoreboardCallerServerRpc(NetworkObject newPlayer)
//{
// // Call the method on the server first
// scoreboard.ScoreBoardListFiller(newPlayer);
// // Then invoke it on the client
// ScoreboardCallerClientRpc(newPlayer);
//}
//[ClientRpc]
//void ScoreboardCallerClientRpc(NetworkObject newPlayer)
//{
// // Call the method on the client
// if (NetworkManager.Singleton.IsClient)
// {
// scoreboard.ScoreBoardListFiller(newPlayer);
// }
//}
void OnLifeStateChangedEventMessage(LifeStateChangedEventMessage message)
{

@ -22,7 +22,7 @@ namespace Unity.BossRoom.Gameplay.GameState
public override GameState ActiveState => GameState.CharSelect;
public NetworkCharSelection networkCharSelection { get; private set; }
//public static int numOfPlayers;
Coroutine m_WaitToEndLobbyCoroutine;
[Inject]
@ -165,6 +165,7 @@ namespace Unity.BossRoom.Gameplay.GameState
void SaveLobbyResults()
{
int numofPlayersInLobby = networkCharSelection.LobbyPlayers.Count;
//numOfPlayers = numofPlayersInLobby;
PlayerPrefs.SetInt("NumberOfLobbyPlayers", numofPlayersInLobby);
Debug.Log("Number of Players in lobby are: " + numofPlayersInLobby);
foreach (NetworkCharSelection.LobbyPlayerState playerInfo in networkCharSelection.LobbyPlayers)

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Multiplayer.Samples.BossRoom;
using UnityEngine;
using Unity.Netcode;
using TMPro;
//namespace Unity.Multiplayer.Samples.BossRoom
//{
public class PlayerItem : MonoBehaviour
{
public TextMeshProUGUI PlayerName;
public TextMeshProUGUI PlayerScore;
}
//}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0dd49e4fefe1c0444abd48c3b4c193be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,22 +1,26 @@
using UnityEngine;
using Unity.Netcode;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
public class PlayerScoreComponent : NetworkBehaviour
{
public int CurrentScore { get; private set; }
public ServerCharacter serverCharacter;
public int m_index;
public PlayerItem playerItem;
public override void OnNetworkSpawn()
{
if (IsOwner && IsClient)
{
Debug.Log($"[PlayerScoreComponent] Requesting score initialization for Player {OwnerClientId}");
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId);
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId,serverCharacter.uIStateDisplayHandler.m_UIState.playerName);
}
// For the server player (host), ensure the PlayerScoreComponent is registered properly
if (IsServer && OwnerClientId == NetworkManager.Singleton.LocalClientId)
{
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId);
ScoreManager.Instance?.InitializePlayerScoreServerRpc(OwnerClientId, serverCharacter.uIStateDisplayHandler.m_UIState.playerName);
}
serverCharacter=GetComponent<ServerCharacter>();
}
public void UpdateScore(int newScore)
@ -31,4 +35,9 @@ public class PlayerScoreComponent : NetworkBehaviour
// Update the player's score display in the UI.
Debug.Log($"[PlayerScoreComponent] Updated score UI for Player {OwnerClientId}: {CurrentScore}");
}
private void OnDestroy()
{
Destroy(playerItem.gameObject);
Scoreboard.instance.DestroyChecker();
}
}

@ -8,7 +8,8 @@ public class ScoreManager : NetworkBehaviour
{
public static ScoreManager Instance { get; private set; }
private Dictionary<ulong, int> playerScores = new Dictionary<ulong, int>();
public Dictionary<ulong, int> playerScores = new Dictionary<ulong, int>();
public Dictionary<ulong, string> playerNames = new Dictionary<ulong, string>();
private void Awake()
{
@ -29,13 +30,17 @@ public class ScoreManager : NetworkBehaviour
}
[ServerRpc(RequireOwnership = false)]
public void InitializePlayerScoreServerRpc(ulong ownerClientId)
public void InitializePlayerScoreServerRpc(ulong ownerClientId,string name)
{
if (!playerScores.ContainsKey(ownerClientId))
{
playerScores[ownerClientId] = 200;
Debug.Log($"[ScoreManager] Player {ownerClientId} initialized with a starting score of 200.");
UpdatePlayerScoreClientRpc(ownerClientId, 200);
playerNames[ownerClientId]= name;
Scoreboard.instance.ScoreBoardItemInitializer(ownerClientId, playerScores[ownerClientId],name);
}
else
{
@ -49,6 +54,7 @@ public class ScoreManager : NetworkBehaviour
if (playerScores.ContainsKey(ownerClientId))
{
playerScores[ownerClientId] = newScore;
Scoreboard.instance.ScoreBoardUpdater(ownerClientId, newScore);
Debug.Log($"[ScoreManager] Updating Player {ownerClientId} score to {newScore}.");
UpdatePlayerScoreClientRpc(ownerClientId, newScore);
}

@ -0,0 +1,159 @@
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 : NetworkBehaviour
{
public List<PlayerScoreComponent> m_PlayerScoreComponents;
public List<PlayerItem> playerItems;
public GameObject playerItemPrefab;
public Transform Parent;
public Transform FinalParent;
int index = 0;
bool coroutineStarter = false;
public static Scoreboard instance;
public GameObject FinalLeaderBoardObj;
private void Awake()
{
instance = this;
}
public void DestroyChecker()
{
for (int i = 0; i < m_PlayerScoreComponents.Count; i++)
{
if (m_PlayerScoreComponents[i] == null)
{
m_PlayerScoreComponents.RemoveAt(i);
}
}
for (int i = 0; i < playerItems.Count; i++)
{
if (playerItems[i] == null)
{
playerItems.RemoveAt(i);
}
}
}
public void ScoreBoardListFiller(NetworkObject playerObj)
{
if (IsServer)
{
ulong clientId = playerObj.OwnerClientId;
int initialScore = ScoreManager.Instance.GetPlayerScore(clientId);
m_PlayerScoreComponents.Add(playerObj.GetComponent<PlayerScoreComponent>());
m_PlayerScoreComponents[m_PlayerScoreComponents.Count - 1].m_index = index;
// Synchronize across clients
InstantiatePlayerItemClientRpc(index, clientId, initialScore);
index++;
}
}
[ClientRpc]
public void InstantiatePlayerItemClientRpc(int index, ulong clientId, int currentScore)
{
GameObject temp = Instantiate(playerItemPrefab, Parent);
PlayerItem item = temp.GetComponent<PlayerItem>();
item.PlayerName.text = clientId.ToString();
item.PlayerScore.text = currentScore.ToString();
playerItems.Add(item);
}
[ClientRpc]
public void ScoreBoardItemInitializerClientRpc(ulong id, int score,string name)
{
playerItems.Add(Instantiate(playerItemPrefab, Parent).GetComponent<PlayerItem>());
playerItems[^1].PlayerName.text = name.ToString();
playerItems[^1].PlayerScore.text = score.ToString();
}
public void ScoreBoardItemInitializer(ulong id, int score,string name)
{
if (IsServer)
{
ScoreBoardItemInitializerClientRpc(id, score,name); // Send to clients
}
}
[ClientRpc]
public void ScoreBoardUpdaterClientRpc(ulong id, int score)
{
for (int i = 0; i < playerItems.Count; i++)
{
if (playerItems[i].PlayerName.text == id.ToString())
{
playerItems[i].PlayerScore.text = score.ToString();
}
}
}
public void FinalLeaderBoard()
{
Debug.Log("FinalLeaderBoard");
if (IsServer)
{
FinalLeaderBoardClientRPC();
}
}
[ClientRpc]
public void FinalLeaderBoardClientRPC()
{
for (int i = 0; i < playerItems.Count; i++)
{
Instantiate(playerItems[i], FinalParent);
}
FinalLeaderBoardObj.SetActive(true);
}
public void ScoreBoardUpdater(ulong id, int score)
{
if (IsServer)
{
ScoreBoardUpdaterClientRpc(id, score); // Send to all clients
}
}
public void Starter()
{
// Start the coroutine for updating the scores
StartCoroutine(ScoreUpdater());
}
public void Instantiator(int index)
{
// Only instantiate UI elements on the client side
if (!NetworkManager.Singleton.IsClient)
{
Debug.LogError("Instantiator called on server, should be on client");
return;
}
Debug.Log("Instantiator called on client");
GameObject temp = Instantiate(playerItemPrefab, Parent);
PlayerItem item = temp.GetComponent<PlayerItem>();
m_PlayerScoreComponents[m_PlayerScoreComponents.Count - 1].playerItem = item;
playerItems.Add(item);
playerItems[playerItems.Count - 1].PlayerScore.text = m_PlayerScoreComponents[index].CurrentScore.ToString();
playerItems[playerItems.Count - 1].PlayerName.text = m_PlayerScoreComponents[index].serverCharacter.uIStateDisplayHandler.m_UIState.playerName.ToString();
}
IEnumerator ScoreUpdater()
{
//yield return new WaitForSeconds(0.5f);
Debug.Log("Scoreboard Start - ScoreUpdater started");
yield return new WaitUntil(() => coroutineStarter == true);
while (true)
{
if (IsOwner)
{
yield return new WaitForSeconds(0.1f);
//m_PlayerScoreComponents.Sort((p1, p2) => p2.CurrentScore.CompareTo(p1.CurrentScore));
playerItems.Sort((p1, p2) => p2.PlayerScore.GetParsedText().CompareTo(p1.PlayerScore.GetParsedText()));
for (int i = 0; i < playerItems.Count; i++)
playerItems[i].transform.SetSiblingIndex(m_PlayerScoreComponents[i].m_index);
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7df4fbc7cb5d44c42aeadfa5b2ea67fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,5 +1,6 @@
using System.Collections;
using Unity.Multiplayer.Samples.Utilities;
using Unity.Netcode;
using UnityEngine;
using static TMPro.SpriteAssetUtilities.TexturePacker_JsonArray;
@ -28,8 +29,8 @@ public class TimerScript : MonoBehaviour
{
Debug.Log("Timer has ended!");
// Add logic for what happens when the timer ends
Scoreboard.instance.FinalLeaderBoard();
}
private void OnDestroy()
{
if (timer != null)

Loading…
Cancel
Save