CoolDown timer fixed and WarningPanel UI

dev-ali
Ali Sharoz 2 days ago
parent 9633a7ae18
commit a15f6d6b34

@ -4382,13 +4382,14 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 731395403} - component: {fileID: 731395403}
- component: {fileID: 731395404}
m_Layer: 5 m_Layer: 5
m_Name: WarningPanel m_Name: WarningPanel
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &731395403 --- !u!224 &731395403
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4409,6 +4410,19 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &731395404
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 731395402}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 725a3a3076d96f54f8ffcb254140c646, type: 3}
m_Name:
m_EditorClassIdentifier:
panel: {fileID: 1586538565}
--- !u!1 &732850150 --- !u!1 &732850150
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -13889,11 +13903,11 @@ PrefabInstance:
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
value: 0.28987604 value: 0.28987613
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734515771252668, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.1815203 value: -0.1815204
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1676734516302391364, guid: 0193228de87741d40a42e561901c9083, type: 3} - target: {fileID: 1676734516302391364, guid: 0193228de87741d40a42e561901c9083, type: 3}
propertyPath: m_UpdateMethod propertyPath: m_UpdateMethod
@ -17092,12 +17106,12 @@ GameObject:
- component: {fileID: 1586538568} - component: {fileID: 1586538568}
- component: {fileID: 1586538567} - component: {fileID: 1586538567}
m_Layer: 5 m_Layer: 5
m_Name: BG m_Name: PanelBG
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &1586538566 --- !u!224 &1586538566
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

@ -414,6 +414,10 @@ public class AbilitySystem : NetworkBehaviour
abilitiesOnCooldown.Remove(ability); abilitiesOnCooldown.Remove(ability);
Debug.Log($"{ability.abilityName} is off cooldown."); Debug.Log($"{ability.abilityName} is off cooldown.");
if (abilityUI)
{
abilityUI.CancelCooldownUI();
}
} }
private void UpdateIndicatorPosition() private void UpdateIndicatorPosition()

@ -1,46 +1,66 @@
using System.Collections; using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Unity.Multiplayer.Samples.BossRoom namespace Unity.Multiplayer.Samples.BossRoom
{ {
public class AbilityUI : MonoBehaviour public class AbilityUI : MonoBehaviour
{ {
public string key; public string key;
public Image CoolDownImg; public Image CoolDownImg;
public GameObject CoolDownImgParent; public GameObject CoolDownImgParent;
public IEnumerator StopWatchRoutine;
private Coroutine stopWatchRoutine;
private bool isCooldownActive = false;
public void StopWatchFiller(float coolDownTime) public void StopWatchFiller(float coolDownTime)
{ {
if (StopWatchRoutine == null) if (stopWatchRoutine != null)
{
StopWatchRoutine = StopWatchFillerRoutine(coolDownTime);
StartCoroutine(StopWatchRoutine);
}
else
{ {
StopCoroutine(StopWatchRoutine); StopCoroutine(stopWatchRoutine);
StopWatchRoutine = StopWatchFillerRoutine(coolDownTime);
StartCoroutine(StopWatchRoutine);
} }
stopWatchRoutine = StartCoroutine(StopWatchFillerRoutine(coolDownTime));
} }
public IEnumerator StopWatchFillerRoutine(float coolDownTime)
private IEnumerator StopWatchFillerRoutine(float coolDownTime)
{ {
float factor = coolDownTime; isCooldownActive = true;
CoolDownImgParent.SetActive(true); CoolDownImgParent.SetActive(true);
// CoolDownImg.gameObject.SetActive(true);
CoolDownImg.fillAmount = 1; CoolDownImg.fillAmount = 1;
while (coolDownTime > 0)
float elapsedTime = 0;
while (elapsedTime < coolDownTime)
{
// Check if cooldown is still active before updating UI
if (!isCooldownActive)
{
CoolDownImgParent.SetActive(false);
yield break;
}
elapsedTime += Time.deltaTime;
CoolDownImg.fillAmount = 1 - (elapsedTime / coolDownTime);
yield return null;
}
CoolDownImgParent.SetActive(false);
isCooldownActive = false;
stopWatchRoutine = null;
}
/// <summary>
/// Cancels cooldown UI immediately if the ability is available before the countdown ends.
/// </summary>
public void CancelCooldownUI()
{
if (stopWatchRoutine != null)
{ {
coolDownTime -= Time.deltaTime; StopCoroutine(stopWatchRoutine);
CoolDownImg.fillAmount = coolDownTime / factor; stopWatchRoutine = null;
yield return new WaitForSeconds(Time.deltaTime);
} }
CoolDownImgParent.SetActive(false); CoolDownImgParent.SetActive(false);
// CoolDownImg.gameObject.SetActive(false); isCooldownActive = false;
StopWatchRoutine = null;
} }
} }
} }

@ -48,7 +48,7 @@ public class ExecutionerBox : NetworkBehaviour
{ {
// Show warning UI on all clients // Show warning UI on all clients
// UIManager.Instance.ShowExecutionerWarning(_warningTime); // UIManager.Instance.ShowExecutionerWarning(_warningTime);
WarningPanel.Instance.ShowPanelForTime(_warningTime);
// Wait for the warning time before moving // Wait for the warning time before moving
yield return new WaitForSeconds(_warningTime); yield return new WaitForSeconds(_warningTime);

@ -0,0 +1,44 @@
using Unity.Netcode;
using UnityEngine;
using System.Collections;
public class WarningPanel : NetworkBehaviour
{
public static WarningPanel Instance { get; private set; }
[SerializeField] private GameObject panel;
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
public void ShowPanelForTime(float seconds)
{
if (IsServer) // Only the server should trigger this
{
ShowPanelClientRpc(seconds);
}
}
[ClientRpc]
private void ShowPanelClientRpc(float seconds)
{
panel.SetActive(true);
StartCoroutine(HidePanelAfterTime(seconds));
}
private IEnumerator HidePanelAfterTime(float seconds)
{
yield return new WaitForSeconds(seconds);
panel.SetActive(false);
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 725a3a3076d96f54f8ffcb254140c646
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save