Commit 158f1ebc by alsunj

Merge branch 'feat/start-game-event' into 'main'

Added Start game countdown UI

See merge request alsunj/loputoo!9
parents 9c53ad40 afe90c11
using Unity.Netcode;
using UnityEngine;
public class ClientManager : NetworkBehaviour
{
private void Start()
{
if (IsClient && !IsServer)
{
RequestTimerState();
}
}
private void RequestTimerState()
{
if (NetworkManager.Singleton.IsConnectedClient)
{
GameManager gameManager = FindObjectOfType<GameManager>();
if (gameManager != null)
{
gameManager.RequestTimerStateServerRpc();
}
else
{
Debug.LogError("GameManager not found.");
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8d2e44d8b8cee4f4ca4cbc5753b50feb
\ No newline at end of file
using TMPro;
using Unity.Netcode;
using UnityEngine;
public class GameManager : NetworkBehaviour
{
private TextMeshProUGUI _timerText;
private float _initialTimer = 10f;
private float _startGameTimer = 10f;
private bool _initialTimerActive = true;
private bool _startGameTimerActive;
private void Start()
{
_timerText = GameObject.Find("Start_Game").GetComponent<TextMeshProUGUI>();
if (_timerText == null)
{
Debug.LogError("TextMeshPro component not found on Start Game GameObject!");
return;
}
if (IsServer)
{
_initialTimerActive = true;
}
}
private void Update()
{
if (!IsServer) return;
if (_initialTimerActive)
{
_initialTimer -= Time.deltaTime;
if (_initialTimer <= 0)
{
_initialTimerActive = false;
_startGameTimerActive = true;
EnableTimerTextClientRpc(true);
}
}
if (_startGameTimerActive)
{
_startGameTimer -= Time.deltaTime;
if (_startGameTimer > 0)
{
UpdateTimerClientRpc(_startGameTimer);
}
else
{
_startGameTimerActive = false;
UpdateTimerClientRpc(0);
EnableTimerTextClientRpc(false);
TimersEndedServerRpc();
}
}
}
[ClientRpc]
private void UpdateTimerClientRpc(float timeRemaining)
{
if (_timerText != null)
{
_timerText.text = $"Starting Game in {Mathf.Ceil(timeRemaining)}";
}
}
[ClientRpc]
private void EnableTimerTextClientRpc(bool state)
{
if (_timerText != null)
{
_timerText.enabled = state;
}
}
[ServerRpc]
private void TimersEndedServerRpc()
{
// Logic to handle when timers have ended
Debug.Log("Timers have ended.");
}
[ServerRpc(RequireOwnership = false)]
public void RequestTimerStateServerRpc(ServerRpcParams rpcParams = default)
{
if (_initialTimerActive)
{
RespondTimerStateClientRpc(_initialTimer, true, rpcParams.Receive.SenderClientId);
}
else if (_startGameTimerActive)
{
RespondTimerStateClientRpc(_startGameTimer, true, rpcParams.Receive.SenderClientId);
}
else
{
RespondTimerStateClientRpc(0, false, rpcParams.Receive.SenderClientId);
}
}
[ClientRpc]
private void RespondTimerStateClientRpc(float timeRemaining, bool timerActive, ulong clientId)
{
if (NetworkManager.Singleton.LocalClientId == clientId)
{
_timerText.enabled = timerActive;
_timerText.text = $"Starting Game in {Mathf.Ceil(timeRemaining)}";
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 9c71552cd67eabf489fab4fe0d80a0f9
\ No newline at end of file
......@@ -137,6 +137,7 @@ GameObject:
- component: {fileID: 5977278119335250016}
- component: {fileID: -5431455483652452085}
- component: {fileID: 6323309021802201727}
- component: {fileID: 911307299827299822}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
......@@ -332,6 +333,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c5e28a848c1e15846a459b682cc64164, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &911307299827299822
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7039287367920326276}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8d2e44d8b8cee4f4ca4cbc5753b50feb, type: 3}
m_Name:
m_EditorClassIdentifier:
ShowTopMostFoldoutHeaderGroup: 1
--- !u!1 &9074470363064250575
GameObject:
m_ObjectHideFlags: 0
......
......@@ -724,6 +724,7 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1504492730}
- {fileID: 1877249104}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
......@@ -963,6 +964,77 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 4040528778396390922, guid: 2abc46d65f2e2d7439c7689b3c2142c4, type: 3}
--- !u!1 &405720566
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 405720569}
- component: {fileID: 405720567}
- component: {fileID: 405720568}
m_Layer: 0
m_Name: Managers
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &405720567
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 405720566}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3}
m_Name:
m_EditorClassIdentifier:
GlobalObjectIdHash: 1158095512
InScenePlacedSourceGlobalObjectIdHash: 0
DeferredDespawnTick: 0
Ownership: 1
AlwaysReplicateAsRoot: 0
SynchronizeTransform: 1
ActiveSceneSynchronization: 0
SceneMigrationSynchronization: 1
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
SyncOwnerTransformWhenParented: 1
AllowOwnerToParent: 0
--- !u!114 &405720568
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 405720566}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9c71552cd67eabf489fab4fe0d80a0f9, type: 3}
m_Name:
m_EditorClassIdentifier:
ShowTopMostFoldoutHeaderGroup: 1
--- !u!4 &405720569
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 405720566}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.9441636, y: -0.5603608, z: -1.2710799}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &458110279
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -3749,6 +3821,142 @@ MeshCollider:
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: -3275770135416983120, guid: ceca936363ca6f446a07531901199ca9, type: 3}
--- !u!1 &1877249103
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1877249104}
- component: {fileID: 1877249106}
- component: {fileID: 1877249105}
m_Layer: 5
m_Name: Start_Game
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1877249104
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1877249103}
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: 303522006}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 262.3946, y: 108.8129}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1877249105
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1877249103}
m_Enabled: 0
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: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Start Game
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: 1166126335
m_fontColor: {r: 1, g: 0.6733512, b: 0.504717, a: 0.27058825}
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: 50.3
m_fontSizeBase: 50.3
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
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_TextWrappingMode: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_ActiveFontFeatures: 6e72656b
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_EmojiFallbackSupport: 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!222 &1877249106
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1877249103}
m_CullTransparentMesh: 1
--- !u!1 &1883582478 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 87d9e8aa89dc79e47bbc07b25704225c, type: 3}
......@@ -4456,3 +4664,4 @@ SceneRoots:
- {fileID: 1687222685}
- {fileID: 303522006}
- {fileID: 865924118}
- {fileID: 405720569}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment