Pull request #63: extraire les prix et cooldowns des unit cards

Merge in CGD/gather-and-defend from feature/separate_cooldown_from_units to main

* commit '927c08559f2f0c8850be6c9b3e170165e8bccb27':
  extraire les prix et cooldowns des unit cards
This commit is contained in:
Felix-gabriel Boucher-luneau 2024-03-17 19:03:14 +00:00
commit 99655f7e09
23 changed files with 293 additions and 21 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 160cacddb5bd0764ebef981b91f59608
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Archer
m_EditorClassIdentifier:
_wood: 30
_rock: 0
_food: 20
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ff4b606166b07d4bb3afb15e5a23f41
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Castle
m_EditorClassIdentifier:
_wood: 0
_rock: 350
_food: 0
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4728bef0a18b70945bedf5b1190c491e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Farm
m_EditorClassIdentifier:
_wood: 40
_rock: 0
_food: 0
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f4dcf11b827a5ca49a70b5db1e72e16e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Farmer
m_EditorClassIdentifier:
_wood: 0
_rock: 0
_food: 10
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee85fc25d3460c745806649e7f9d166a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: FarmerMob
m_EditorClassIdentifier:
_wood: 0
_rock: 0
_food: 10
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f433c214b267f2a40b7427ae18ac80ac
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: House
m_EditorClassIdentifier:
_wood: 50
_rock: 0
_food: 0
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4fda8972f6f46684891773953155782e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Knight
m_EditorClassIdentifier:
_wood: 0
_rock: 0
_food: 60
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0334115ab72f6d5449497db1bb50377e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Mill
m_EditorClassIdentifier:
_wood: 120
_rock: 0
_food: 0
_cooldownInSeconds: 3

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b326df01bdba895448b1df3f2918fa9b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2428,6 +2428,10 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 1092900232}
m_Modifications:
- target: {fileID: 385500479923064057, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: f433c214b267f2a40b7427ae18ac80ac, type: 2}
- target: {fileID: 400568530076150058, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@ -2478,11 +2482,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 907652128862280229, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 907652128862280229, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMin.y
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 907652128862280229, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchoredPosition.x
@ -2490,7 +2494,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 907652128862280229, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchoredPosition.y
value: -103.3
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1144883118211503064, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
@ -2684,6 +2688,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3060107528281312343, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: b326df01bdba895448b1df3f2918fa9b, type: 2}
- target: {fileID: 3964878483247902818, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@ -2700,6 +2708,22 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4021885618240460209, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: 9ff4b606166b07d4bb3afb15e5a23f41, type: 2}
- target: {fileID: 4021885618914922922, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: ee85fc25d3460c745806649e7f9d166a, type: 2}
- target: {fileID: 4021885619120025647, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: 4728bef0a18b70945bedf5b1190c491e, type: 2}
- target: {fileID: 4448694950779727683, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: 0334115ab72f6d5449497db1bb50377e, type: 2}
- target: {fileID: 4453469705328566160, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@ -2964,6 +2988,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6772290102801599907, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: f4dcf11b827a5ca49a70b5db1e72e16e, type: 2}
- target: {fileID: 7106892479276285262, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
@ -3012,6 +3040,10 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8434244524890535526, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: _unitCardInformation
value:
objectReference: {fileID: 11400000, guid: 4fda8972f6f46684891773953155782e, type: 2}
- target: {fileID: 8992921944992653498, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3}
propertyPath: m_AnchorMax.y
value: 0

View File

@ -13,7 +13,7 @@ public class GameObjectPlacementButton : UnitPlacementButton
var isBuilding = _prefab.GetComponent<Building>();
var defaultPopCost = GlobalConfig.Instance.Current.populationCostPerUnit;
var hasEnoughPopulation = isBuilding || ResourceManager.Instance.EnoughPopulationFor(defaultPopCost);
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food)
return ResourceManager.Instance.EnoughFor(_unitCardInformation.Rock, _unitCardInformation.Wood, _unitCardInformation.Food)
&& hasEnoughPopulation
&& base.CanPlace();
}

View File

@ -8,7 +8,7 @@ public class TilePlacementButton : UnitPlacementButton
protected override bool CanPlace()
{
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food) && base.CanPlace();
return ResourceManager.Instance.EnoughFor(_unitCardInformation.Rock, _unitCardInformation.Wood, _unitCardInformation.Food) && base.CanPlace();
}
protected override DraggablePlaceholder Place()

View File

@ -0,0 +1,19 @@
using UnityEngine;
[CreateAssetMenu(menuName = "Gather And Defend/Buyable Unit Card")]
public class UnitCard : ScriptableObject
{
[SerializeField]
protected int _wood;
[SerializeField]
protected int _rock;
[SerializeField]
protected int _food;
[SerializeField]
protected int _cooldownInSeconds = 3;
public int Wood => _wood;
public int Rock => _rock;
public int Food => _food;
public int CooldownInSeconds => _cooldownInSeconds;
}

View File

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

View File

@ -11,14 +11,8 @@ public abstract class UnitPlacementButton : PlacementButton
protected Sprite _detectionRangeSprite;
[SerializeField]
protected int _wood;
[SerializeField]
protected int _rock;
[SerializeField]
protected int _food;
[SerializeField]
protected int _cooldownInSeconds = 3;
protected UnitCard _unitCardInformation;
[SerializeField]
private TMP_Text _foodLabel;
[SerializeField]
@ -34,9 +28,9 @@ public abstract class UnitPlacementButton : PlacementButton
{
base.Update();
SetTextFor(_foodLabel, _food);
SetTextFor(_rockLabel, _rock);
SetTextFor(_woodLabel, _wood);
SetTextFor(_foodLabel, _unitCardInformation.Food);
SetTextFor(_rockLabel, _unitCardInformation.Rock);
SetTextFor(_woodLabel, _unitCardInformation.Wood);
}
void SetTextFor(TMP_Text label, int value)
{
@ -48,9 +42,9 @@ public abstract class UnitPlacementButton : PlacementButton
base.OnPointerDown(eventData);
if (Placeholder is UnitPlaceholder placeHolder)
{
placeHolder.Rock = _rock;
placeHolder.Wood = _wood;
placeHolder.Food = _food;
placeHolder.Rock = _unitCardInformation.Rock;
placeHolder.Wood = _unitCardInformation.Wood;
placeHolder.Food = _unitCardInformation.Food;
placeHolder.WasPlaced += HandleCooldown;
}
@ -67,10 +61,10 @@ public abstract class UnitPlacementButton : PlacementButton
var countDown = 0f;
_lockedByCooldown = true;
_cooldownIndicator.gameObject.SetActive(true);
while (countDown < _cooldownInSeconds)
while (countDown < _unitCardInformation.CooldownInSeconds)
{
countDown += Time.deltaTime;
var percentDone = countDown / _cooldownInSeconds;
var percentDone = countDown / _unitCardInformation.CooldownInSeconds;
_cooldownIndicator.fillAmount = 1 - percentDone;
yield return null;
}