unit cooldown

#Le besoin addressé par le commit
les unités et bâtiments devrait avoir un temps de cooldown avant de pouvoir être spawné à nouveau

#Comment le besoin est-il addressé? (modifications)
les unités et bâtiments prennent maintenant 3 secondes avant de redevenir interactif après avoir été spawné
This commit is contained in:
Felix Boucher 2024-02-18 11:11:03 -05:00
parent 474b47be53
commit effe4ca2cc
4 changed files with 199 additions and 1 deletions

View File

@ -112,6 +112,7 @@ RectTransform:
- {fileID: 578448310312278818}
- {fileID: 907652128235033330}
- {fileID: 7424225105167539335}
- {fileID: 5501162456977524028}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -203,9 +204,11 @@ MonoBehaviour:
_wood: 0
_rock: 0
_food: 0
_cooldownInSeconds: 3
_foodLabel: {fileID: 907652129260736055}
_woodLabel: {fileID: 2551561112895533431}
_rockLabel: {fileID: 3195941792010457804}
_cooldownIndicator: {fileID: 5207475109691974292}
_prefab: {fileID: 0}
--- !u!225 &6913755812382793111
CanvasGroup:
@ -941,6 +944,82 @@ CanvasGroup:
m_Interactable: 0
m_BlocksRaycasts: 0
m_IgnoreParentGroups: 0
--- !u!1 &5828230984884335261
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5501162456977524028}
- component: {fileID: 8338249668523744596}
- component: {fileID: 5207475109691974292}
m_Layer: 5
m_Name: CooldownIndicator
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &5501162456977524028
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5828230984884335261}
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: 907652127959947829}
m_RootOrder: 3
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: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &8338249668523744596
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5828230984884335261}
m_CullTransparentMesh: 1
--- !u!114 &5207475109691974292
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5828230984884335261}
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.3018868, g: 0, b: 0, a: 0.6901961}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 3
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!1 &7114462096084942491
GameObject:
m_ObjectHideFlags: 0

View File

@ -125,6 +125,7 @@ RectTransform:
- {fileID: 7042708939576806788}
- {fileID: 7287691806885839956}
- {fileID: 1059349486317029921}
- {fileID: 1217819425183827895}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -216,9 +217,11 @@ MonoBehaviour:
_wood: 30
_rock: 0
_food: 0
_cooldownInSeconds: 3
_foodLabel: {fileID: 7287691807974070417}
_woodLabel: {fileID: 5391726344234182609}
_rockLabel: {fileID: 5035571921358210154}
_cooldownIndicator: {fileID: 1268446567353174613}
tile: {fileID: 11400000, guid: 7568f730b2ba3754297a7612452482e2, type: 2}
--- !u!225 &2889836282219012120
CanvasGroup:
@ -1178,6 +1181,82 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &8638014914632680632
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1217819425183827895}
- component: {fileID: 7644251973362524053}
- component: {fileID: 1268446567353174613}
m_Layer: 5
m_Name: CooldownIndicator
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1217819425183827895
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8638014914632680632}
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: 907652127959947829}
m_RootOrder: 3
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: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7644251973362524053
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8638014914632680632}
m_CullTransparentMesh: 1
--- !u!114 &1268446567353174613
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8638014914632680632}
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.3018868, g: 0, b: 0, a: 0.6901961}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10913, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 3
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!1 &8965017596094456768
GameObject:
m_ObjectHideFlags: 0

View File

@ -8,10 +8,13 @@ public abstract class UnitPlaceholder : DraggablePlaceholder
public override void Place()
{
ResourceManager.Instance.Remove(Rock, Wood, Food);
WasPlaced?.Invoke(this);
}
public override bool CanBePlacedHere()
{
return base.CanBePlacedHere() && ResourceManager.Instance.EnoughFor(Rock, Wood, Food)
&& !LevelManager.Instance.Has<ILevelObject>(obj => obj.Position.IsContainedIn(transform.position));
}
public event System.Action<UnitPlaceholder> WasPlaced;
}

View File

@ -1,3 +1,5 @@
using GatherAndDefend.Events;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
@ -14,6 +16,8 @@ public abstract class UnitPlacementButton : PlacementButton
protected int _rock;
[SerializeField]
protected int _food;
[SerializeField]
protected int _cooldownInSeconds = 3;
[SerializeField]
private TMP_Text _foodLabel;
@ -22,7 +26,10 @@ public abstract class UnitPlacementButton : PlacementButton
[SerializeField]
private TMP_Text _rockLabel;
[SerializeField]
protected Image _cooldownIndicator;
protected bool _lockedByCooldown;
protected override void Update()
{
base.Update();
@ -44,6 +51,36 @@ public abstract class UnitPlacementButton : PlacementButton
placeHolder.Rock = _rock;
placeHolder.Wood = _wood;
placeHolder.Food = _food;
placeHolder.WasPlaced += HandleCooldown;
}
}
private void HandleCooldown(UnitPlaceholder unitPlaceholder)
{
unitPlaceholder.WasPlaced -= HandleCooldown;
StartCoroutine(HandleCooldownCoroutine());
IEnumerator HandleCooldownCoroutine()
{
var countDown = 0f;
_lockedByCooldown = true;
_cooldownIndicator.gameObject.SetActive(true);
while (countDown < _cooldownInSeconds)
{
countDown += Time.deltaTime;
var percentDone = countDown / _cooldownInSeconds;
_cooldownIndicator.fillAmount = 1 - percentDone;
yield return null;
}
_cooldownIndicator.gameObject.SetActive(false);
_lockedByCooldown = false;
}
}
protected override bool CanPlace()
{
return base.CanPlace() && !_lockedByCooldown;
}
}