From defe6ed4ff9794e8718c31c5c0b1b9109a411dd3 Mon Sep 17 00:00:00 2001 From: Felix Boucher Date: Wed, 2 Aug 2023 01:39:24 -0400 Subject: [PATCH 1/4] creer le scriptable object GlobalConfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit besoin : il serait bien d'avoir un fichier central qui permettrait de modifier toutes les valeurs du jeu sans avoir à aller dans chaque prefab et gosser solution : un fichier central de paramétrage qui sera hooked en middleman dans les valeurs des différents objets du jeu, et pourra être changé en temps réel et appliqué globalement note : le fichier est créé mais les paramètres ne sont pas encore hooked. --- Assets/GlobalConfig.asset | 23 ++++++++++++ Assets/GlobalConfig.asset.meta | 8 +++++ Assets/Prefabs/LevelManager.prefab | 14 ++++++++ Assets/Scripts/General/GlobalConfig.cs | 8 +++++ Assets/Scripts/General/GlobalConfig.cs.meta | 11 ++++++ Assets/Scripts/General/GlobalConfigFile.cs | 25 +++++++++++++ .../Scripts/General/GlobalConfigFile.cs.meta | 11 ++++++ Assets/Scripts/LevelManager/LevelManager.cs | 36 ++++++------------- 8 files changed, 110 insertions(+), 26 deletions(-) create mode 100644 Assets/GlobalConfig.asset create mode 100644 Assets/GlobalConfig.asset.meta create mode 100644 Assets/Scripts/General/GlobalConfig.cs create mode 100644 Assets/Scripts/General/GlobalConfig.cs.meta create mode 100644 Assets/Scripts/General/GlobalConfigFile.cs create mode 100644 Assets/Scripts/General/GlobalConfigFile.cs.meta diff --git a/Assets/GlobalConfig.asset b/Assets/GlobalConfig.asset new file mode 100644 index 0000000..c75214d --- /dev/null +++ b/Assets/GlobalConfig.asset @@ -0,0 +1,23 @@ +%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: 32e788fd2a7bdaf4ab145b64231cb833, type: 3} + m_Name: GlobalConfig + m_EditorClassIdentifier: + enemyBaseDamage: 1 + enemyBaseLife: 5 + enemyBaseRange: 1 + enemyBaseAttackSpeed: 1 + damageFlashIntensity: 1 + harvestDuration: 1 + harvestAmount: 1 + harvestRandomDurationMinimum: 0 + harvestRandomDurationMaximum: 0 diff --git a/Assets/GlobalConfig.asset.meta b/Assets/GlobalConfig.asset.meta new file mode 100644 index 0000000..0245198 --- /dev/null +++ b/Assets/GlobalConfig.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 132e291fc51a8f445b1183b11a5d6b39 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/LevelManager.prefab b/Assets/Prefabs/LevelManager.prefab index 71fb6cb..b10ca1a 100644 --- a/Assets/Prefabs/LevelManager.prefab +++ b/Assets/Prefabs/LevelManager.prefab @@ -12,6 +12,7 @@ GameObject: - component: {fileID: 3028288566889208750} - component: {fileID: 3028288566889208749} - component: {fileID: -245230096461627285} + - component: {fileID: 5626804684391367242} m_Layer: 0 m_Name: LevelManager m_TagString: Untagged @@ -119,3 +120,16 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 37c0aa967043d974783120d6ea9b136c, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &5626804684391367242 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3028288566889208744} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c8f878516c4a3324aa1a9672f8b336c9, type: 3} + m_Name: + m_EditorClassIdentifier: + _current: {fileID: 11400000, guid: 132e291fc51a8f445b1183b11a5d6b39, type: 2} diff --git a/Assets/Scripts/General/GlobalConfig.cs b/Assets/Scripts/General/GlobalConfig.cs new file mode 100644 index 0000000..4135a7b --- /dev/null +++ b/Assets/Scripts/General/GlobalConfig.cs @@ -0,0 +1,8 @@ +using UnityEngine; + +public class GlobalConfig : SingletonBehaviour +{ + [SerializeField] + private GlobalConfigFile _current; + public GlobalConfigFile Current => _current; +} diff --git a/Assets/Scripts/General/GlobalConfig.cs.meta b/Assets/Scripts/General/GlobalConfig.cs.meta new file mode 100644 index 0000000..43d6acb --- /dev/null +++ b/Assets/Scripts/General/GlobalConfig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8f878516c4a3324aa1a9672f8b336c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/General/GlobalConfigFile.cs b/Assets/Scripts/General/GlobalConfigFile.cs new file mode 100644 index 0000000..94612de --- /dev/null +++ b/Assets/Scripts/General/GlobalConfigFile.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + + +[CreateAssetMenu(menuName = project_name + "/Global Config")] +public class GlobalConfigFile : ScriptableObject +{ + public const string project_name = "Gather And Defend"; + + [Header("Enemies")] + public float enemyBaseDamage; + public float enemyBaseLife; + public float enemyBaseRange; + public float enemyBaseAttackSpeed; + + public float damageFlashIntensity; + + [Header("resources")] + public float harvestDuration; + public float harvestAmount; + public float harvestRandomDurationMinimum; + public float harvestRandomDurationMaximum; +} diff --git a/Assets/Scripts/General/GlobalConfigFile.cs.meta b/Assets/Scripts/General/GlobalConfigFile.cs.meta new file mode 100644 index 0000000..3acea83 --- /dev/null +++ b/Assets/Scripts/General/GlobalConfigFile.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32e788fd2a7bdaf4ab145b64231cb833 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/LevelManager/LevelManager.cs b/Assets/Scripts/LevelManager/LevelManager.cs index dc73a2b..fafbd8e 100644 --- a/Assets/Scripts/LevelManager/LevelManager.cs +++ b/Assets/Scripts/LevelManager/LevelManager.cs @@ -96,8 +96,9 @@ public class LevelManager : Singleton #region [Level management] - public void UpdateLevel() + public void AddAndRemoveObjects() { + //add and remove var toAdd = new List(_toAdd); toAdd.ForEach(addedObject => { @@ -113,27 +114,18 @@ public class LevelManager : Singleton _levelObjects.Remove(removedObject); removedObject.LevelDestroy(); }); + } + + public void UpdateLevel() + { + AddAndRemoveObjects(); _levelObjects.ForEach(levelObject => { levelObject.LevelUpdate(); }); - toAdd = new List(_toAdd); - toAdd.ForEach(addedObject => - { - _toAdd.Remove(addedObject); - _levelObjects.Add(addedObject); - addedObject.LevelStart(); - }); - - toRemove = new List(_toRemove); - toRemove.ForEach(removedObject => - { - _toRemove.Remove(removedObject); - _levelObjects.Remove(removedObject); - removedObject.LevelDestroy(); - }); + AddAndRemoveObjects(); } public void ClearLevel() @@ -162,7 +154,9 @@ public class LevelManager : Singleton //create new grid if there is none if (!grid) { + var levelMgrScript = Object.FindObjectOfType(); grid = new GameObject("Grid").AddComponent(); + grid.transform.SetParent(levelMgrScript.transform); } //remove all tilemaps if there is a grid else @@ -199,11 +193,6 @@ public class LevelManager : Singleton ClearLevel(); } - foreach (var ob in Database.Instance.ScriptableObjects) - { - Debug.Log(ob); - } - //fetch level from database _currentLevel = Database.Instance.ScriptableObjects[levelName] as Level; @@ -290,10 +279,5 @@ public class LevelManager : Singleton } - - /// - /// align camera to the rightmost tile of the tilemap - /// - #endregion } \ No newline at end of file From b9908ab7176cf819554e37864d4b7d00b3b8ad37 Mon Sep 17 00:00:00 2001 From: Felix Boucher Date: Wed, 2 Aug 2023 01:39:57 -0400 Subject: [PATCH 2/4] forgot changes in game.unity --- Assets/Scenes/Game.unity | 120 +++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 2cf07a4..f993ea0 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -959,11 +959,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 400568530076150058, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568530076150058, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568530076150058, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -971,7 +971,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 400568530076150058, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -47.711605 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568530256114997, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y @@ -991,11 +991,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 400568530484276529, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568530484276529, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568530484276529, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1003,15 +1003,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 400568530484276529, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -47.711605 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568531361238196, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568531361238196, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 400568531361238196, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1019,15 +1019,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 400568531361238196, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -47.711605 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1361171379191865150, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1361171379191865150, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1361171379191865150, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1035,15 +1035,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1361171379191865150, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -6.0372024 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1366041080306649041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1366041080306649041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 1366041080306649041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1051,7 +1051,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1366041080306649041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -26.874405 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911515542116969, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y @@ -1087,11 +1087,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2335911515764278902, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911515764278902, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911515764278902, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1099,15 +1099,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2335911515764278902, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -6.0372024 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516153004653, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516153004653, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516153004653, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1115,15 +1115,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2335911516153004653, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -6.0372024 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516626281448, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516626281448, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2335911516626281448, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1131,7 +1131,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2335911516626281448, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -6.0372024 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796561267475078, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y @@ -1151,11 +1151,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2340796561450327705, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796561450327705, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796561450327705, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1163,7 +1163,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2340796561450327705, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -26.874405 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796561610837739, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y @@ -1183,11 +1183,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2340796562313902855, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796562313902855, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796562313902855, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1195,15 +1195,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2340796562313902855, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -26.874405 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796563190143618, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796563190143618, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 2340796563190143618, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1211,15 +1211,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2340796563190143618, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -26.874405 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3964878483247902818, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3964878483247902818, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 3964878483247902818, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1227,7 +1227,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3964878483247902818, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -47.711605 + value: 0 objectReference: {fileID: 0} - target: {fileID: 4021885618914922922, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: _food @@ -1323,11 +1323,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5316389173819650276, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5316389173819650276, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5316389173819650276, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1335,15 +1335,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5316389173819650276, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -26.874405 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5319145879937787915, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5319145879937787915, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5319145879937787915, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1351,15 +1351,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5319145879937787915, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -6.0372024 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393060989426, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393060989426, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393060989426, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1367,7 +1367,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5639720393060989426, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -103.3 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393215043968, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y @@ -1403,11 +1403,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5639720393720315369, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393720315369, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720393720315369, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1415,15 +1415,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5639720393720315369, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -5 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394252960041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394252960041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394252960041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1431,15 +1431,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5639720394252960041, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -5 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394327989356, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394327989356, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5639720394327989356, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1447,15 +1447,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5639720394327989356, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -103.3 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7797049475554395991, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7797049475554395991, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 7797049475554395991, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1463,15 +1463,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 7797049475554395991, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -47.711605 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8992921944992653498, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8992921944992653498, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8992921944992653498, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.x @@ -1479,7 +1479,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8992921944992653498, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} propertyPath: m_AnchoredPosition.y - value: -201.6 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 306211cf6348ac747a78d89bd72fca3e, type: 3} From 0aa3327433bc88082c45f7d37bda41b44a3c216e Mon Sep 17 00:00:00 2001 From: Felix Boucher Date: Sat, 5 Aug 2023 15:55:54 -0400 Subject: [PATCH 3/4] =?UTF-8?q?appliquer=20global=20config=20aux=20diff?= =?UTF-8?q?=C3=A9rents=20endroits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROBLÈME : la config existait mais n'était pas appliquée nulle part SOLUTION : maintenant elle l'est NOTES : Elle n'est pas encore appliquée au flash de dégat --- Assets/Scripts/Ally/Ally.cs | 13 ++--- Assets/Scripts/Detection.cs | 31 +++++++++++- Assets/Scripts/Entity.cs | 33 ++++--------- Assets/Scripts/General/Extensions.cs | 19 ++++++++ Assets/Scripts/General/GlobalConfig.cs | 12 ++++- Assets/Scripts/General/GlobalConfigFile.cs | 19 ++++---- Assets/Scripts/Resource/ResourceMaker.cs | 7 +-- Assets/Scripts/Root.cs | 2 +- Assets/Scripts/Tiles/ResourceTile.cs | 55 +++++++++++++++++----- Assets/Tiles/Farm.asset | 2 +- Assets/Tiles/Forest.asset | 2 +- Assets/Tiles/Meat.asset | 2 +- Assets/Tiles/RockNode.asset | 2 +- 13 files changed, 135 insertions(+), 64 deletions(-) diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index 4615d32..9e81acd 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -18,17 +18,18 @@ public class Ally : Entity } - void AttackEnemy() + void AttackEnemy() { //Attack Cooldown - if(AttackSpeed < AttackSpeedWait) { + if (AttackSpeed < AttackSpeedWait) + { - Animation.PlayAttackAnim(); + Animation.PlayAttackAnim(); - AttackSpeedWait = 0f; - } + AttackSpeedWait = 0f; + } - AttackSpeedWait += Time.deltaTime; + AttackSpeedWait += Time.deltaTime; } } diff --git a/Assets/Scripts/Detection.cs b/Assets/Scripts/Detection.cs index dda1736..f668583 100644 --- a/Assets/Scripts/Detection.cs +++ b/Assets/Scripts/Detection.cs @@ -4,22 +4,48 @@ using UnityEngine; public class Detection : MonoBehaviour { + private Vector2 detectionRange; + private BoxCollider2D _collider; public Rect DetectionRectangle { get { - var collider = GetComponent(); - var bounds = collider.bounds; + if (!_collider) _collider = GetComponent(); + var bounds = _collider.bounds; return new Rect(bounds.min - transform.position, bounds.size); } } [SerializeField] private Entity _entityLinked; + protected virtual void Start() + { + _collider = GetComponent(); + detectionRange = _collider.size; + } + void ResizeCollider() + { + var range = GlobalConfig.Instance.Current.enemyBaseRange; + var size = _collider.size; + size.x = detectionRange.x * range.x; + size.y = detectionRange.y * range.y; + _collider.size = size; + + var offset = _collider.offset; + if (offset == Vector2.zero) return; + + offset.x = size.x / 2; + _collider.offset = offset; + } //If it's a projectile damage > 0 private int _projectileDamage = 0; private float _distanceMin = 100f; + protected virtual void Update() + { + ResizeCollider(); + } + void OnTriggerEnter2D(Collider2D other) { //Projectiles detection + damage deal @@ -82,6 +108,7 @@ public class Detection : MonoBehaviour } + //Getter and Setter public Entity EntityLinked { diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 598493b..9d8a097 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using static Extensions; public class Entity : LevelObject { @@ -90,35 +89,19 @@ public class Entity : LevelObject //GETTERS AND SETTERS - public int Hp - { - get { return _hp; } - set { _hp = value; } - } + public int Hp => (int)(_hp * GlobalConfig.Instance.Current.enemyBaseLife); - public float Speed - { - get { return _speed; } - set { _speed = value; } - } + public float Speed => _speed; - public int AttackDamage - { - get { return _attack_damage; } - set { _attack_damage = value; } - } + public int AttackDamage => (int)(_attack_damage * GlobalConfig.Instance.Current.enemyBaseDamage); - public float AttackSpeed - { - get { return _attack_speed; } - set { _attack_speed = value; } - } + public float AttackSpeed => _attack_speed * GlobalConfig.Instance.Current.enemyBaseAttackSpeed; public float AttackSpeedWait -{ - get { return _attack_speed_wait; } - set { _attack_speed_wait = value; } -} + { + get { return _attack_speed_wait; } + set { _attack_speed_wait = value; } + } public bool IsEnemyDetected { diff --git a/Assets/Scripts/General/Extensions.cs b/Assets/Scripts/General/Extensions.cs index c938c49..ad694e2 100644 --- a/Assets/Scripts/General/Extensions.cs +++ b/Assets/Scripts/General/Extensions.cs @@ -4,6 +4,7 @@ using BindingFlags = System.Reflection.BindingFlags; using UnityEngine; using System.Collections; using GatherAndDefend.LevelEditor; +using System.Linq; public static class Extensions { @@ -96,4 +97,22 @@ public static class Extensions { return Vector2.Distance(vect, tilePosition) < 0.5f; } + + public static T Minimum(this IEnumerable list, Func func) + { + if (list.Count() < 1) throw new Exception("in " + nameof(Minimum) + " : Cannot find minimum of empty list : " + nameof(list)); + T minT = list.ElementAt(0); + float minVal = func(minT); + + foreach (var obj in list) + { + var newVal = func(obj); + if (minVal > newVal) + { + minT = obj; + minVal = newVal; + } + } + return minT; + } } \ No newline at end of file diff --git a/Assets/Scripts/General/GlobalConfig.cs b/Assets/Scripts/General/GlobalConfig.cs index 4135a7b..a954bd2 100644 --- a/Assets/Scripts/General/GlobalConfig.cs +++ b/Assets/Scripts/General/GlobalConfig.cs @@ -4,5 +4,15 @@ public class GlobalConfig : SingletonBehaviour { [SerializeField] private GlobalConfigFile _current; - public GlobalConfigFile Current => _current; + public GlobalConfigFile Current + { + get + { + if (!_current) + { + _current = ScriptableObject.CreateInstance(); + } + return _current; + } + } } diff --git a/Assets/Scripts/General/GlobalConfigFile.cs b/Assets/Scripts/General/GlobalConfigFile.cs index 94612de..8a277c7 100644 --- a/Assets/Scripts/General/GlobalConfigFile.cs +++ b/Assets/Scripts/General/GlobalConfigFile.cs @@ -10,16 +10,17 @@ public class GlobalConfigFile : ScriptableObject public const string project_name = "Gather And Defend"; [Header("Enemies")] - public float enemyBaseDamage; - public float enemyBaseLife; - public float enemyBaseRange; - public float enemyBaseAttackSpeed; + public float enemyBaseDamage = 1; + public float enemyBaseLife = 1; + public Vector2 enemyBaseRange = Vector2.one; + public float enemyBaseAttackSpeed = 1; - public float damageFlashIntensity; + public float damageFlashIntensity = 1; [Header("resources")] - public float harvestDuration; - public float harvestAmount; - public float harvestRandomDurationMinimum; - public float harvestRandomDurationMaximum; + public float baseHarvestDuration = 1; + public float baseHarvestAmount = 1; + public bool useRandomHarvestDuration = false; + public float randomHarvestDurationMinimum = 0; + public float randomHarvestDurationMaximum = 0; } diff --git a/Assets/Scripts/Resource/ResourceMaker.cs b/Assets/Scripts/Resource/ResourceMaker.cs index b52a821..d5598d7 100644 --- a/Assets/Scripts/Resource/ResourceMaker.cs +++ b/Assets/Scripts/Resource/ResourceMaker.cs @@ -43,6 +43,7 @@ public class ResourceMaker : MonoBehaviour if (_isPlaying) { + var amountMult = GlobalConfig.Instance.Current.baseHarvestAmount; _timePassed += Time.deltaTime; float duration = _timePassed / _desiredTime; duration = duration * duration * (3.0f - 2.0f * duration); @@ -53,13 +54,13 @@ public class ResourceMaker : MonoBehaviour switch (_resourceChoice) { case Enum.ResourceChoice.Rock: - _resourceManagerInstance.RockAmount = _resourceMakingAmount; + _resourceManagerInstance.RockAmount = (int)(_resourceMakingAmount * amountMult); break; case Enum.ResourceChoice.Wood: - _resourceManagerInstance.WoodAmount = _resourceMakingAmount; + _resourceManagerInstance.WoodAmount = (int)(_resourceMakingAmount * amountMult); break; case Enum.ResourceChoice.Food: - _resourceManagerInstance.FoodAmount = _resourceMakingAmount; + _resourceManagerInstance.FoodAmount = (int)(_resourceMakingAmount * amountMult); break; } Destroy(gameObject); diff --git a/Assets/Scripts/Root.cs b/Assets/Scripts/Root.cs index 91cfaf4..eb71304 100644 --- a/Assets/Scripts/Root.cs +++ b/Assets/Scripts/Root.cs @@ -13,7 +13,7 @@ public class Root : MonoBehaviour private Transform _projectileSpawn; void Attack() { - _entity.Enemy.Hit( _entity.AttackDamage); + _entity.Enemy.Hit(_entity.AttackDamage); if(_entity.Enemy.Hp <= 0) { _entity.Enemy.Death(); _entity.IsEnemyDetected = false; diff --git a/Assets/Scripts/Tiles/ResourceTile.cs b/Assets/Scripts/Tiles/ResourceTile.cs index 0327ef5..afcfe1f 100644 --- a/Assets/Scripts/Tiles/ResourceTile.cs +++ b/Assets/Scripts/Tiles/ResourceTile.cs @@ -12,30 +12,59 @@ public class ResourceTile : LevelTile public GameObject YieldPrefab => _yieldPrefab; private string YieldPrefabName => _yieldPrefab.name; - [SerializeField] - private float _yieldSpeed = 1; //resource per second + [SerializeField][Tooltip("mesure en seconde / ressource")] + private float _yieldDuration = 1; //resource per second + private float _realYieldDuration; [SerializeField] [Range(0.0f, 5.0f)] private float _randomPositionConfig = 0.5f; private float _yieldCounter = 0; public bool Occupied { get; set; } + public override void LevelStart() + { + base.LevelStart(); + _realYieldDuration = _yieldDuration; + ResetYieldDuration(); + } public override void LevelUpdate() { //check if there is an harvester unit on top var hasFarmer = LevelManager.Instance.Get(x => x.Position.IsContainedIn(Position)); if (!hasFarmer) return; + _yieldCounter += Time.deltaTime; + if (_yieldCounter < _realYieldDuration) return; - _yieldCounter += Time.deltaTime * _yieldSpeed; - if (_yieldCounter < 1) return; - if(_yieldPrefab != null) + ResetYieldDuration(); + + if (_yieldPrefab != null) { - _yieldCounter = 0; - float rangeConfig = 0.5f + _randomPositionConfig; - Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z); - var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity); - yielded.transform.SetParent(LevelManager.Instance.LevelTransform); + YieldResource(); + } + } + private void YieldResource() + { + float rangeConfig = 0.5f + _randomPositionConfig; + Vector3 yieldPosition = new Vector3(Position.x + Random.Range(-rangeConfig, rangeConfig), Position.y, Position.z); + var yielded = Instantiate(_yieldPrefab, yieldPosition, Quaternion.identity); + yielded.transform.SetParent(LevelManager.Instance.LevelTransform); + } + private void ResetYieldDuration() + { + _yieldCounter = 0; + var config = GlobalConfig.Instance.Current; + if (!config) return; + + if (config.useRandomHarvestDuration) + { + float min = config.randomHarvestDurationMinimum, + max = config.randomHarvestDurationMaximum; + _realYieldDuration = _yieldDuration * Random.Range(min, max); + } + else + { + _realYieldDuration = _yieldDuration * config.baseHarvestDuration; } } public override bool Equals(ILevelObject other) @@ -43,7 +72,7 @@ public class ResourceTile : LevelTile return other is ResourceTile otherRes && base.Equals(otherRes) && _yieldPrefab == otherRes._yieldPrefab - && _yieldSpeed == otherRes._yieldSpeed + && _yieldDuration == otherRes._yieldDuration && Occupied == otherRes.Occupied; } public override Dictionary ToDictionary() @@ -51,7 +80,7 @@ public class ResourceTile : LevelTile var dict = base.ToDictionary(); dict[nameof(YieldPrefabName)] = YieldPrefabName; - dict[nameof(_yieldSpeed)] = _yieldSpeed; + dict[nameof(_yieldDuration)] = _yieldDuration; dict[nameof(Occupied)] = Occupied; return dict; } @@ -60,7 +89,7 @@ public class ResourceTile : LevelTile base.LoadDictionary(dict); var prefabName = dict[nameof(YieldPrefabName)].ToString(); _yieldPrefab = Database.Instance.Prefabs[prefabName]; - _yieldSpeed = dict[nameof(_yieldSpeed)].ToFloat(); + _yieldDuration = dict[nameof(_yieldDuration)].ToFloat(); _yieldCounter = dict[nameof(_yieldCounter)].ToFloat(); Occupied = dict[nameof(Occupied)].ToBool(); } diff --git a/Assets/Tiles/Farm.asset b/Assets/Tiles/Farm.asset index 80c131e..326eb50 100644 --- a/Assets/Tiles/Farm.asset +++ b/Assets/Tiles/Farm.asset @@ -15,5 +15,5 @@ MonoBehaviour: _sprite: {fileID: 21300000, guid: ccca3e050cb082b45af0a099790463f6, type: 3} _isCollidable: 0 _yieldPrefab: {fileID: 6962989255644195630, guid: a2dc5d9672c10074fa9c35c12f6339c1, type: 3} - _yieldSpeed: 0.1 + _yieldDuration: 5 _randomPositionConfig: 0.25 diff --git a/Assets/Tiles/Forest.asset b/Assets/Tiles/Forest.asset index acbedaa..88f485a 100644 --- a/Assets/Tiles/Forest.asset +++ b/Assets/Tiles/Forest.asset @@ -15,5 +15,5 @@ MonoBehaviour: _sprite: {fileID: 21300000, guid: 43582b3c6b60fd144bc56d8ab3b14349, type: 3} _isCollidable: 0 _yieldPrefab: {fileID: 6962989255644195630, guid: f20569b5452c2b341a95d656b7534b7e, type: 3} - _yieldSpeed: 0.1 + _yieldDuration: 5 _randomPositionConfig: 0.5 diff --git a/Assets/Tiles/Meat.asset b/Assets/Tiles/Meat.asset index 6ec392b..ddf80a2 100644 --- a/Assets/Tiles/Meat.asset +++ b/Assets/Tiles/Meat.asset @@ -15,5 +15,5 @@ MonoBehaviour: _sprite: {fileID: 21300000, guid: b1e6b8ebeb2e25f4f8c5de93a31dd6a2, type: 3} _isCollidable: 0 _yieldPrefab: {fileID: 6962989255644195630, guid: a2dc5d9672c10074fa9c35c12f6339c1, type: 3} - _yieldSpeed: 0.1 + _yieldDuration: 5 _randomPositionConfig: 0.5 diff --git a/Assets/Tiles/RockNode.asset b/Assets/Tiles/RockNode.asset index 90feadb..2899c44 100644 --- a/Assets/Tiles/RockNode.asset +++ b/Assets/Tiles/RockNode.asset @@ -15,5 +15,5 @@ MonoBehaviour: _sprite: {fileID: 21300000, guid: 6298844400e212d40bce870425ac2a5b, type: 3} _isCollidable: 0 _yieldPrefab: {fileID: 6962989255644195630, guid: 484f0eca1c74ae34694692de56a36739, type: 3} - _yieldSpeed: 0.1 + _yieldDuration: 5 _randomPositionConfig: 0.5 From 0714036b57f45e2c04dc8de469ce99b1b8a2d6d3 Mon Sep 17 00:00:00 2001 From: Felix Boucher Date: Wed, 30 Aug 2023 14:57:01 -0400 Subject: [PATCH 4/4] separate ally and enemy config + bugfixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit la config des ennemis influencait la config des alliés, ce qui était un bug maintenant, il y a une config différente pour les alliés et les ennemis. l'animation d'attaque ne se terminait pas à temps pour faire le dégat, il a donc fallu multiplier la vitesse d'animation par le attack speed quand on attaque j'en ai profité pour faire la même chose pour le walk animation et le speed j'ai changé l'attribut des unités "attack speed" pour un "attack interval", pour que ça représente mieux son utilisation. Le multiplicateur reste sur la vitesse, et non sur l'interval. Les configs pour les ressources sont les valeurs des ressources directement (pas des multiplicateurs) --- Assets/GlobalConfig.asset | 23 ++-- .../Monsters/ClawClawRough_monster.prefab | 41 +------ .../Sticks/Harversters/axemanStick.prefab | 114 +----------------- .../Sticks/Harversters/minerStick.prefab | 114 +----------------- Assets/Prefabs/Sticks/archerStick.prefab | 41 +------ Assets/Prefabs/Sticks/baseStick.prefab | 43 +------ .../Prefabs/Sticks/farmersAssociation.prefab | 41 +------ Assets/Prefabs/baseProjectile.prefab | 39 ------ Assets/Scripts/Ally/Ally.cs | 12 +- Assets/Scripts/Ally/Archer.cs | 6 +- Assets/Scripts/Ally/Harvester.cs | 15 ++- Assets/Scripts/AnimationEntity.cs | 43 ++++++- Assets/Scripts/Detection.cs | 10 +- Assets/Scripts/Entity.cs | 37 +++--- Assets/Scripts/General/GlobalConfigFile.cs | 31 +++-- Assets/Scripts/Opponent/Opponent.cs | 17 ++- Assets/Scripts/Resource/ResourceMaker.cs | 10 +- Assets/Scripts/Tiles/ResourceTile.cs | 22 +--- 18 files changed, 154 insertions(+), 505 deletions(-) diff --git a/Assets/GlobalConfig.asset b/Assets/GlobalConfig.asset index c75214d..74ae7ed 100644 --- a/Assets/GlobalConfig.asset +++ b/Assets/GlobalConfig.asset @@ -12,12 +12,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 32e788fd2a7bdaf4ab145b64231cb833, type: 3} m_Name: GlobalConfig m_EditorClassIdentifier: - enemyBaseDamage: 1 - enemyBaseLife: 5 - enemyBaseRange: 1 - enemyBaseAttackSpeed: 1 damageFlashIntensity: 1 - harvestDuration: 1 - harvestAmount: 1 - harvestRandomDurationMinimum: 0 - harvestRandomDurationMaximum: 0 + enemySpeedMultiplier: 1 + enemyDamageMultiplier: 1 + enemyLifeMultiplier: 1 + enemyRangeMultiplier: {x: 1, y: 1} + enemyAttackSpeedMultiplier: 1 + allyDamageMultiplier: 1 + allyLifeMultiplier: 1 + allyAttackSpeedMultiplier: 0.5 + allySpeedMultiplier: 1 + allyRangeMultiplier: {x: 1, y: 1} + harvestDuration: 5 + harvestAmount: 10 + useRandomHarvestDuration: 0 + randomHarvestDurationMinimum: 0 + randomHarvestDurationMaximum: 0 diff --git a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab index 118f159..e325aad 100644 --- a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab +++ b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab @@ -9,7 +9,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 80204295746100151} - - component: {fileID: 3889963999147056896} - component: {fileID: 788547799086903831} - component: {fileID: 8565800310011739221} - component: {fileID: 313037212318601125} @@ -37,44 +36,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1839735485 &3889963999147056896 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 80204295746100150} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 --- !u!50 &788547799086903831 Rigidbody2D: serializedVersion: 4 @@ -137,7 +98,7 @@ MonoBehaviour: _hp: 20 _speed: 0.12 _attack_damage: 2 - _attack_speed: 2 + _attack_interval: 2 --- !u!1 &381864779947488822 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Sticks/Harversters/axemanStick.prefab b/Assets/Prefabs/Sticks/Harversters/axemanStick.prefab index 4bddfbf..4740bfe 100644 --- a/Assets/Prefabs/Sticks/Harversters/axemanStick.prefab +++ b/Assets/Prefabs/Sticks/Harversters/axemanStick.prefab @@ -1,77 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &270769315063318434 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 71124047072817123} - - component: {fileID: 2608989659328117942} - - component: {fileID: 3358069652062874313} - m_Layer: 0 - m_Name: detection - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &71124047072817123 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - 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: 6962989255644195631} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!61 &2608989659328117942 -BoxCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 1 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0.5, y: 0} - m_SpriteTilingProperty: - border: {x: 0, y: 0, z: 0, w: 0} - pivot: {x: 0, y: 0} - oldSize: {x: 0, y: 0} - newSize: {x: 0, y: 0} - adaptiveTilingThreshold: 0 - drawMode: 0 - adaptiveTiling: 0 - m_AutoTiling: 0 - serializedVersion: 2 - m_Size: {x: 0.5, y: 0.5} - m_EdgeRadius: 0 ---- !u!114 &3358069652062874313 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3} - m_Name: - m_EditorClassIdentifier: - _entityLinked: {fileID: 0} --- !u!1 &6962989255035248094 GameObject: m_ObjectHideFlags: 0 @@ -397,7 +325,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6962989255644195631} - - component: {fileID: 6072713849781841816} - component: {fileID: -1491803373025033585} - component: {fileID: -7538281095464317747} - component: {fileID: -7651792297317791922} @@ -422,48 +349,9 @@ Transform: m_Children: - {fileID: 6962989256011107500} - {fileID: 6962989255883535387} - - {fileID: 71124047072817123} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1839735485 &6072713849781841816 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6962989255644195630} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 --- !u!50 &-1491803373025033585 Rigidbody2D: serializedVersion: 4 @@ -526,7 +414,7 @@ MonoBehaviour: _hp: 0 _speed: 0 _attack_damage: 0 - _attack_speed: 0 + _attack_interval: 0 _harvesterResourcePairs: - _harvesterPrefab: {fileID: 5157279992115123224, guid: 85534a2d6c2add54d864073914646192, type: 3} _resource: 2 diff --git a/Assets/Prefabs/Sticks/Harversters/minerStick.prefab b/Assets/Prefabs/Sticks/Harversters/minerStick.prefab index 2b70e35..63fc5fc 100644 --- a/Assets/Prefabs/Sticks/Harversters/minerStick.prefab +++ b/Assets/Prefabs/Sticks/Harversters/minerStick.prefab @@ -1,77 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &270769315063318434 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 71124047072817123} - - component: {fileID: 2608989659328117942} - - component: {fileID: 3358069652062874313} - m_Layer: 0 - m_Name: detection - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &71124047072817123 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - 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: 6962989255644195631} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!61 &2608989659328117942 -BoxCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 1 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0.5, y: 0} - m_SpriteTilingProperty: - border: {x: 0, y: 0, z: 0, w: 0} - pivot: {x: 0, y: 0} - oldSize: {x: 0, y: 0} - newSize: {x: 0, y: 0} - adaptiveTilingThreshold: 0 - drawMode: 0 - adaptiveTiling: 0 - m_AutoTiling: 0 - serializedVersion: 2 - m_Size: {x: 0.5, y: 0.5} - m_EdgeRadius: 0 ---- !u!114 &3358069652062874313 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 270769315063318434} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3} - m_Name: - m_EditorClassIdentifier: - _entityLinked: {fileID: 0} --- !u!1 &6962989255035248094 GameObject: m_ObjectHideFlags: 0 @@ -397,7 +325,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6962989255644195631} - - component: {fileID: 6072713849781841816} - component: {fileID: -1491803373025033585} - component: {fileID: -7538281095464317747} - component: {fileID: 6812572548963698156} @@ -422,48 +349,9 @@ Transform: m_Children: - {fileID: 6962989256011107500} - {fileID: 6962989255883535387} - - {fileID: 71124047072817123} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1839735485 &6072713849781841816 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6962989255644195630} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 --- !u!50 &-1491803373025033585 Rigidbody2D: serializedVersion: 4 @@ -526,7 +414,7 @@ MonoBehaviour: _hp: 0 _speed: 0 _attack_damage: 0 - _attack_speed: 0 + _attack_interval: 0 _harvesterResourcePairs: - _harvesterPrefab: {fileID: 5157279992115123224, guid: 85534a2d6c2add54d864073914646192, type: 3} _resource: 2 diff --git a/Assets/Prefabs/Sticks/archerStick.prefab b/Assets/Prefabs/Sticks/archerStick.prefab index b375de6..dd76c39 100644 --- a/Assets/Prefabs/Sticks/archerStick.prefab +++ b/Assets/Prefabs/Sticks/archerStick.prefab @@ -545,7 +545,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 5531237550998824025} - - component: {fileID: 8657602915366199534} - component: {fileID: 5129435415547448825} - component: {fileID: 4251894621246849979} - component: {fileID: 9177659942431061517} @@ -574,44 +573,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1839735485 &8657602915366199534 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5531237550998824024} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 --- !u!50 &5129435415547448825 Rigidbody2D: serializedVersion: 4 @@ -674,7 +635,7 @@ MonoBehaviour: _hp: 10 _speed: 0 _attack_damage: 2 - _attack_speed: 2 + _attack_interval: 2 --- !u!1 &6125909153338481476 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Sticks/baseStick.prefab b/Assets/Prefabs/Sticks/baseStick.prefab index 492fdd4..77ed112 100644 --- a/Assets/Prefabs/Sticks/baseStick.prefab +++ b/Assets/Prefabs/Sticks/baseStick.prefab @@ -398,7 +398,6 @@ GameObject: m_Component: - component: {fileID: 6962989255644195631} - component: {fileID: 8585520847943034727} - - component: {fileID: 6072713849781841816} - component: {fileID: -1491803373025033585} - component: {fileID: -7538281095464317747} m_Layer: 0 @@ -440,46 +439,8 @@ MonoBehaviour: m_EditorClassIdentifier: _hp: 100 _speed: 0 - _attack_damage: 1 - _attack_speed: 1.2 ---- !u!1839735485 &6072713849781841816 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6962989255644195630} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 + _attack_damage: 0 + _attack_interval: 0 --- !u!50 &-1491803373025033585 Rigidbody2D: serializedVersion: 4 diff --git a/Assets/Prefabs/Sticks/farmersAssociation.prefab b/Assets/Prefabs/Sticks/farmersAssociation.prefab index 94ad7c2..89c8175 100644 --- a/Assets/Prefabs/Sticks/farmersAssociation.prefab +++ b/Assets/Prefabs/Sticks/farmersAssociation.prefab @@ -1063,7 +1063,6 @@ GameObject: m_Component: - component: {fileID: 6962989255644195631} - component: {fileID: 8585520847943034727} - - component: {fileID: 6072713849781841816} - component: {fileID: -1491803373025033585} - component: {fileID: -7538281095464317747} m_Layer: 0 @@ -1106,45 +1105,7 @@ MonoBehaviour: _hp: 10 _speed: 0 _attack_damage: 2 - _attack_speed: 2 ---- !u!1839735485 &6072713849781841816 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6962989255644195630} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 + _attack_interval: 2 --- !u!50 &-1491803373025033585 Rigidbody2D: serializedVersion: 4 diff --git a/Assets/Prefabs/baseProjectile.prefab b/Assets/Prefabs/baseProjectile.prefab index cbab2f8..bba972b 100644 --- a/Assets/Prefabs/baseProjectile.prefab +++ b/Assets/Prefabs/baseProjectile.prefab @@ -9,7 +9,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6962989255644195631} - - component: {fileID: 6072713849781841816} - component: {fileID: -1491803373025033585} - component: {fileID: 8133954670424616578} m_Layer: 0 @@ -36,44 +35,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1839735485 &6072713849781841816 -Tilemap: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6962989255644195630} - m_Enabled: 0 - m_Tiles: {} - m_AnimatedTiles: {} - m_TileAssetArray: [] - m_TileSpriteArray: [] - m_TileMatrixArray: [] - m_TileColorArray: [] - m_TileObjectToInstantiateArray: [] - m_AnimationFrameRate: 1 - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 0, y: 0, z: 1} - m_TileAnchor: {x: 0.5, y: 0.5, z: 0} - m_TileOrientation: 0 - m_TileOrientationMatrix: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 --- !u!50 &-1491803373025033585 Rigidbody2D: serializedVersion: 4 diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index 9e81acd..8145a0d 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -4,14 +4,20 @@ using UnityEngine; public class Ally : Entity { + public override float DamageMultiplier => GlobalConfig.Instance.Current.allyDamageMultiplier; + public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.allyAttackSpeedMultiplier; + public override float HpMultiplier => GlobalConfig.Instance.Current.allyLifeMultiplier; + public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.allyRangeMultiplier; + public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier; + public override void Start() { base.Start(); } - void Update() + public override void Update() { - + base.Update(); if(IsEnemyDetected) { AttackEnemy(); } @@ -21,7 +27,7 @@ public class Ally : Entity void AttackEnemy() { //Attack Cooldown - if (AttackSpeed < AttackSpeedWait) + if (AttackSpeedWait > AttackInterval) { Animation.PlayAttackAnim(); diff --git a/Assets/Scripts/Ally/Archer.cs b/Assets/Scripts/Ally/Archer.cs index 8f4f4e9..c63c3a1 100644 --- a/Assets/Scripts/Ally/Archer.cs +++ b/Assets/Scripts/Ally/Archer.cs @@ -10,9 +10,9 @@ public class Archer : Ally base.Start(); } - void Update() + public override void Update() { - + base.Update(); if(IsEnemyDetected) { AttackEnemy(); } @@ -23,7 +23,7 @@ public class Archer : Ally { //Attack Cooldown - if(AttackSpeed < AttackSpeedWait) { + if(AttackInterval < AttackSpeedWait) { Animation.PlayAttackAnim(); diff --git a/Assets/Scripts/Ally/Harvester.cs b/Assets/Scripts/Ally/Harvester.cs index 2e117da..f90afac 100644 --- a/Assets/Scripts/Ally/Harvester.cs +++ b/Assets/Scripts/Ally/Harvester.cs @@ -2,11 +2,22 @@ using UnityEngine; using System.Collections.Generic; using static Enum; -public class Harvester : Entity +public class Harvester : Entity { - [SerializeField][Tooltip("helps choose the right skin for the harvester depending on resource")] + [SerializeField] [Tooltip("helps choose the right skin for the harvester depending on resource")] private List _harvesterResourcePairs; protected ResourceChoice ResourceChoice => _resourceChoice; + + public override Vector2 RangeMultiplier { get; } + + public override float HpMultiplier { get; } + + public override float SpeedMultiplier { get; } + + public override float DamageMultiplier { get; } + + public override float AttackSpeedMultiplier { get; } + [SerializeField] private ResourceChoice _resourceChoice; public override sealed void Start() diff --git a/Assets/Scripts/AnimationEntity.cs b/Assets/Scripts/AnimationEntity.cs index b3b071a..b8c0f77 100644 --- a/Assets/Scripts/AnimationEntity.cs +++ b/Assets/Scripts/AnimationEntity.cs @@ -4,39 +4,63 @@ using UnityEngine; public class AnimationEntity : MonoBehaviour { + enum EntityAnimationState + { + Idle = 0, + Walking = 1, + Attacking = 2, + Dying = 3 + } + private EntityAnimationState entityState; private Animator _animatorEntity; private bool _doSomething = false; private bool _isDead = false; private bool _isWalking = false; - + void Start() { + AttackSpeedMultiplier = 10; + SpeedMultiplier = 10; _animatorEntity = GetComponentInChildren(); } void Update() - { - + { if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f) { PlayIdleAnim(); _doSomething = false; _isWalking = false; } + _animatorEntity.speed = GetAnimatorSpeed(); + } + + private float GetAnimatorSpeed() + { + return entityState switch + { + EntityAnimationState.Attacking => AttackSpeedMultiplier, + EntityAnimationState.Walking => SpeedMultiplier, + _ => 1, + }; } public void PlayIdleAnim() { if(!_isDead) { + _animatorEntity.speed = 1; _animatorEntity.Play("idle", 0, 0f); + entityState = EntityAnimationState.Idle; } } public void PlayWalkAnim() { if(!_isDead) { + _animatorEntity.speed = SpeedMultiplier; _animatorEntity.Play("walk", 0, 0f); + entityState = EntityAnimationState.Walking; _isWalking = true; } } @@ -44,14 +68,18 @@ public class AnimationEntity : MonoBehaviour public void PlayAttackAnim() { if(!_isDead) { + _animatorEntity.speed = AttackSpeedMultiplier; _animatorEntity.Play("attack", 0, 0f); + entityState = EntityAnimationState.Attacking; _doSomething = true; } } public void PlayDieAnim() { + _animatorEntity.speed = 1; _animatorEntity.Play("die", 0, 0f); + entityState = EntityAnimationState.Dying; _doSomething = true; _isDead = true; } @@ -62,5 +90,12 @@ public class AnimationEntity : MonoBehaviour get { return _isWalking; } set { _isWalking = value; } } - + public float AttackSpeedMultiplier + { + get; set; + } + public float SpeedMultiplier + { + get; set; + } } diff --git a/Assets/Scripts/Detection.cs b/Assets/Scripts/Detection.cs index f668583..045534b 100644 --- a/Assets/Scripts/Detection.cs +++ b/Assets/Scripts/Detection.cs @@ -24,17 +24,17 @@ public class Detection : MonoBehaviour } void ResizeCollider() { - var range = GlobalConfig.Instance.Current.enemyBaseRange; - + if (!EntityLinked) return; + var multiplier = EntityLinked.RangeMultiplier; var size = _collider.size; - size.x = detectionRange.x * range.x; - size.y = detectionRange.y * range.y; + size.x = detectionRange.x * multiplier.x; + size.y = detectionRange.y * multiplier.y; _collider.size = size; var offset = _collider.offset; if (offset == Vector2.zero) return; - offset.x = size.x / 2; + offset.x = Mathf.Sign(offset.x) * size.x / 2; _collider.offset = offset; } //If it's a projectile damage > 0 diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 9d8a097..5fc8a74 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class Entity : LevelObject +public abstract class Entity : LevelObject { //Attribut [SerializeField] @@ -10,9 +10,9 @@ public class Entity : LevelObject [SerializeField] private float _speed; [SerializeField] - private int _attack_damage; + private int _attack_damage = 2; [SerializeField] - private float _attack_speed; + private float _attack_interval = 2; private float _attack_speed_wait = 0f; private AnimationEntity _animation; private Shader _shaderGUItext; @@ -29,7 +29,11 @@ public class Entity : LevelObject _spriteRenderers = GetComponentsInChildren(); Animation = gameObject.AddComponent(); } - + public virtual void Update() + { + Animation.AttackSpeedMultiplier = AttackSpeedMultiplier; + Animation.SpeedMultiplier = SpeedMultiplier; + } //Start the animation of death and the fading of the entity public void Death() { @@ -88,14 +92,20 @@ public class Entity : LevelObject } //GETTERS AND SETTERS - - public int Hp => (int)(_hp * GlobalConfig.Instance.Current.enemyBaseLife); - public float Speed => _speed; + public abstract Vector2 RangeMultiplier { get; } + public abstract float HpMultiplier { get; } + public abstract float SpeedMultiplier { get; } + public abstract float DamageMultiplier { get; } + public abstract float AttackSpeedMultiplier { get; } - public int AttackDamage => (int)(_attack_damage * GlobalConfig.Instance.Current.enemyBaseDamage); + public int Hp => (int)(_hp * HpMultiplier); - public float AttackSpeed => _attack_speed * GlobalConfig.Instance.Current.enemyBaseAttackSpeed; + public float Speed => _speed * SpeedMultiplier; + + public int AttackDamage => (int)(_attack_damage * DamageMultiplier); + + public float AttackInterval => _attack_interval / AttackSpeedMultiplier; public float AttackSpeedWait { @@ -128,19 +138,17 @@ public class Entity : LevelObject && base.Equals(otherEntity) && otherEntity._hp == _hp && otherEntity._speed == _speed - && otherEntity._attack_speed == _attack_speed + && otherEntity._attack_interval == _attack_interval && otherEntity._attack_damage == _attack_damage; } - public override Dictionary ToDictionary() { var dict = base.ToDictionary(); dict[nameof(_hp)] = _hp; dict[nameof(_speed)] = _speed; - dict[nameof(_attack_speed)] = _attack_speed; + dict[nameof(_attack_interval)] = _attack_interval; dict[nameof(_attack_damage)] = _attack_damage; - dict[nameof(_attack_speed_wait)] = _attack_speed_wait; return dict; } @@ -150,9 +158,8 @@ public class Entity : LevelObject _hp = dict[nameof(_hp)].ToInt(); _speed = dict[nameof(_speed)].ToFloat(); - _attack_speed = dict[nameof(_attack_speed)].ToFloat(); + _attack_interval = dict[nameof(_attack_interval)].ToFloat(); _attack_damage = dict[nameof(_attack_damage)].ToInt(); - _attack_speed_wait = dict[nameof(_attack_speed_wait)].ToFloat(); } #endregion } diff --git a/Assets/Scripts/General/GlobalConfigFile.cs b/Assets/Scripts/General/GlobalConfigFile.cs index 8a277c7..3423538 100644 --- a/Assets/Scripts/General/GlobalConfigFile.cs +++ b/Assets/Scripts/General/GlobalConfigFile.cs @@ -2,25 +2,32 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; - - [CreateAssetMenu(menuName = project_name + "/Global Config")] public class GlobalConfigFile : ScriptableObject { + public const string project_name = "Gather And Defend"; - - [Header("Enemies")] - public float enemyBaseDamage = 1; - public float enemyBaseLife = 1; - public Vector2 enemyBaseRange = Vector2.one; - public float enemyBaseAttackSpeed = 1; public float damageFlashIntensity = 1; + [Header("Enemies")] + public float enemySpeedMultiplier = 1; + public float enemyDamageMultiplier = 1; + public float enemyLifeMultiplier = 1; + public Vector2 enemyRangeMultiplier = Vector2.one; + public float enemyAttackSpeedMultiplier = 1; + + [Header("Allies")] + public float allyDamageMultiplier = 1; + public float allyLifeMultiplier = 1; + public float allyAttackSpeedMultiplier = 1; + public float allySpeedMultiplier = 1; + public Vector2 allyRangeMultiplier = Vector2.one; + [Header("resources")] - public float baseHarvestDuration = 1; - public float baseHarvestAmount = 1; + public float harvestDuration = 1; + public int harvestAmount = 1; public bool useRandomHarvestDuration = false; - public float randomHarvestDurationMinimum = 0; - public float randomHarvestDurationMaximum = 0; + public int randomHarvestDurationMinimum = 0; + public int randomHarvestDurationMaximum = 0; } diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 14a2451..b0d7b26 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -4,6 +4,11 @@ using UnityEngine; public class Opponent : Entity { + public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.enemyRangeMultiplier; + public override float DamageMultiplier => GlobalConfig.Instance.Current.enemyDamageMultiplier; + public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.enemyAttackSpeedMultiplier; + public override float HpMultiplier => GlobalConfig.Instance.Current.enemyLifeMultiplier; + public override float SpeedMultiplier => GlobalConfig.Instance.Current.enemySpeedMultiplier; private Vector2 _movementVector = Vector2.zero; private Rigidbody2D _rigidbody; @@ -16,11 +21,15 @@ public class Opponent : Entity Animation = gameObject.AddComponent(); } - void Update() + public override void Update() { - if(IsEnemyDetected) { + base.Update(); + if(IsEnemyDetected) + { AttackEnemy(); - }else { + } + else + { _movementVector.x = -Time.deltaTime * Speed; transform.position += (Vector3)_movementVector; @@ -36,7 +45,7 @@ public class Opponent : Entity void AttackEnemy() { //Attack Cooldown - if(AttackSpeed < AttackSpeedWait) + if(AttackInterval < AttackSpeedWait) { Animation.PlayAttackAnim(); diff --git a/Assets/Scripts/Resource/ResourceMaker.cs b/Assets/Scripts/Resource/ResourceMaker.cs index d5598d7..efe051a 100644 --- a/Assets/Scripts/Resource/ResourceMaker.cs +++ b/Assets/Scripts/Resource/ResourceMaker.cs @@ -5,8 +5,6 @@ using UnityEngine; /// public class ResourceMaker : MonoBehaviour { - [SerializeField] - private int _resourceMakingAmount; [SerializeField] private Enum.ResourceChoice _resourceChoice; private ResourceManager _resourceManagerInstance; @@ -43,7 +41,7 @@ public class ResourceMaker : MonoBehaviour if (_isPlaying) { - var amountMult = GlobalConfig.Instance.Current.baseHarvestAmount; + var amount = GlobalConfig.Instance.Current.harvestAmount; _timePassed += Time.deltaTime; float duration = _timePassed / _desiredTime; duration = duration * duration * (3.0f - 2.0f * duration); @@ -54,13 +52,13 @@ public class ResourceMaker : MonoBehaviour switch (_resourceChoice) { case Enum.ResourceChoice.Rock: - _resourceManagerInstance.RockAmount = (int)(_resourceMakingAmount * amountMult); + _resourceManagerInstance.RockAmount = amount; break; case Enum.ResourceChoice.Wood: - _resourceManagerInstance.WoodAmount = (int)(_resourceMakingAmount * amountMult); + _resourceManagerInstance.WoodAmount = amount; break; case Enum.ResourceChoice.Food: - _resourceManagerInstance.FoodAmount = (int)(_resourceMakingAmount * amountMult); + _resourceManagerInstance.FoodAmount = amount; break; } Destroy(gameObject); diff --git a/Assets/Scripts/Tiles/ResourceTile.cs b/Assets/Scripts/Tiles/ResourceTile.cs index afcfe1f..cfd4e6a 100644 --- a/Assets/Scripts/Tiles/ResourceTile.cs +++ b/Assets/Scripts/Tiles/ResourceTile.cs @@ -12,19 +12,14 @@ public class ResourceTile : LevelTile public GameObject YieldPrefab => _yieldPrefab; private string YieldPrefabName => _yieldPrefab.name; - [SerializeField][Tooltip("mesure en seconde / ressource")] - private float _yieldDuration = 1; //resource per second - private float _realYieldDuration; [SerializeField] [Range(0.0f, 5.0f)] private float _randomPositionConfig = 0.5f; private float _yieldCounter = 0; - public bool Occupied { get; set; } public override void LevelStart() { base.LevelStart(); - _realYieldDuration = _yieldDuration; ResetYieldDuration(); } public override void LevelUpdate() @@ -33,8 +28,8 @@ public class ResourceTile : LevelTile var hasFarmer = LevelManager.Instance.Get(x => x.Position.IsContainedIn(Position)); if (!hasFarmer) return; - _yieldCounter += Time.deltaTime; - if (_yieldCounter < _realYieldDuration) return; + _yieldCounter -= Time.deltaTime; + if (_yieldCounter > 0) return; ResetYieldDuration(); @@ -60,28 +55,24 @@ public class ResourceTile : LevelTile { float min = config.randomHarvestDurationMinimum, max = config.randomHarvestDurationMaximum; - _realYieldDuration = _yieldDuration * Random.Range(min, max); + _yieldCounter = Random.Range(min, max); } else { - _realYieldDuration = _yieldDuration * config.baseHarvestDuration; + _yieldCounter = config.harvestDuration; } } public override bool Equals(ILevelObject other) { return other is ResourceTile otherRes && base.Equals(otherRes) - && _yieldPrefab == otherRes._yieldPrefab - && _yieldDuration == otherRes._yieldDuration - && Occupied == otherRes.Occupied; + && _yieldPrefab == otherRes._yieldPrefab; } public override Dictionary ToDictionary() { var dict = base.ToDictionary(); dict[nameof(YieldPrefabName)] = YieldPrefabName; - dict[nameof(_yieldDuration)] = _yieldDuration; - dict[nameof(Occupied)] = Occupied; return dict; } public override void LoadDictionary(Dictionary dict) @@ -89,8 +80,5 @@ public class ResourceTile : LevelTile base.LoadDictionary(dict); var prefabName = dict[nameof(YieldPrefabName)].ToString(); _yieldPrefab = Database.Instance.Prefabs[prefabName]; - _yieldDuration = dict[nameof(_yieldDuration)].ToFloat(); - _yieldCounter = dict[nameof(_yieldCounter)].ToFloat(); - Occupied = dict[nameof(Occupied)].ToBool(); } } \ No newline at end of file