diff --git a/Assets/Scripts/Core/Game/Data/GameControls.cs b/Assets/Scripts/Core/Game/Data/GameControls.cs index acd8630a824884c25a60c875b602715e24c86a3e..3dd7e06a089786fcc3a1f24769b00447a1d6dcd6 100644 --- a/Assets/Scripts/Core/Game/Data/GameControls.cs +++ b/Assets/Scripts/Core/Game/Data/GameControls.cs @@ -7,6 +7,7 @@ public class GameControls : MonoBehaviour { // Attributes public KeyCode backButton = KeyCode.Escape; public KeyCode attackButton = KeyCode.Z; + public KeyCode interactButton = KeyCode.X; // Constructor protected void Awake(){ diff --git a/Assets/Scripts/Core/Game/Managers/EntityManager.cs b/Assets/Scripts/Core/Game/Managers/EntityManager.cs index aec186b7fe11e880f8a57c263e6b6fede9c31e4f..0bf304d62065c88b677b0b4e99e9579ac446439e 100644 --- a/Assets/Scripts/Core/Game/Managers/EntityManager.cs +++ b/Assets/Scripts/Core/Game/Managers/EntityManager.cs @@ -2,12 +2,13 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class EntityManager : MonoBehaviour{ +public class EntityManager : BaseObjectManager{ // Static instance public static EntityManager instance; // Constructor protected void Awake(){ instance = this; + ManagerName = "Entity Manager"; } } diff --git a/Assets/Scripts/Core/Game/Managers/EnvironmentManager.cs b/Assets/Scripts/Core/Game/Managers/EnvironmentManager.cs index 1d7c8260dc5ab15db9539b27eface016eea7190b..7f9623965889138cdae076d69f967a3f61601086 100644 --- a/Assets/Scripts/Core/Game/Managers/EnvironmentManager.cs +++ b/Assets/Scripts/Core/Game/Managers/EnvironmentManager.cs @@ -2,12 +2,13 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class EnvironmentManager : MonoBehaviour{ +public class EnvironmentManager : BaseObjectManager{ // Static instance public static EnvironmentManager instance; // Constructor protected void Awake(){ instance = this; + ManagerName = "Environment Manager"; } } diff --git a/Assets/Scripts/Core/Game/Managers/ObjectManager.cs b/Assets/Scripts/Core/Game/Managers/ObjectManager.cs index 38a3f90a5ad54d0fe6c25a5e88991fd285d595c4..0882dd1253742d2aa9655cf54a66b520a26ef11c 100644 --- a/Assets/Scripts/Core/Game/Managers/ObjectManager.cs +++ b/Assets/Scripts/Core/Game/Managers/ObjectManager.cs @@ -1,11 +1,12 @@ using UnityEngine; -public class ObjectManager : MonoBehaviour{ +public class ObjectManager : BaseObjectManager{ // Static Instance public static ObjectManager instance; // Constructor protected void Awake(){ instance = this; + ManagerName = "Object Manager"; } } \ No newline at end of file diff --git a/Assets/Scripts/Core/Objects/Collectibles/Collectible.cs b/Assets/Scripts/Core/Objects/Collectibles/Collectible.cs index 6985de0e62995bf3823384cc659b2e903bce9281..3c59fe0121db1a2d0ba267a649cab234c96081b6 100644 --- a/Assets/Scripts/Core/Objects/Collectibles/Collectible.cs +++ b/Assets/Scripts/Core/Objects/Collectibles/Collectible.cs @@ -2,7 +2,7 @@ using System; using System.Collections; using UnityEngine; -public abstract class Collectible : MonoBehaviour { +public abstract class Collectible : WorldObject { // Attributes [SerializeField] float TimeToLive; private event Action OnCollectEvent; diff --git a/Assets/Scripts/Core/Player/Player.cs b/Assets/Scripts/Core/Player/Player.cs index 8f40213fa257cd98f56147e70949aee01552b261..dc6bcb1ff25d09b17904afe73e0e76603e8c5c9e 100644 --- a/Assets/Scripts/Core/Player/Player.cs +++ b/Assets/Scripts/Core/Player/Player.cs @@ -7,7 +7,7 @@ public class Player : AccompaniableCombatant { // Attributes private PlayerAnimationController animationController; private PlayerMovementController movementController; - private PlayerAttackController attackController; + public PlayerInputController inputController; public PlayerStateController stateController; public PlayerStats stats; @@ -23,7 +23,7 @@ public class Player : AccompaniableCombatant { stateController = new PlayerStateController(this); movementController = new PlayerMovementController(this); animationController = new PlayerAnimationController(this); - attackController = new PlayerAttackController(this); + inputController = new PlayerInputController(this); stats = new PlayerStats(this); GameController.instance.player = this; @@ -33,7 +33,7 @@ public class Player : AccompaniableCombatant { new void Update(){ base.Update(); - attackController.HandleInputs(); + inputController.HandleInputs(); } new void FixedUpdate(){ diff --git a/Assets/Scripts/Core/Player/PlayerAttackController.cs b/Assets/Scripts/Core/Player/PlayerAttackController.cs deleted file mode 100644 index 157a93d114f7807a5b4677ce002e76061a4e74ee..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Core/Player/PlayerAttackController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using UnityEngine; - -public class PlayerAttackController{ - private readonly Player player; - - public PlayerAttackController(Player player){ - this.player = player; - } - - public void HandleInputs(){ - if(Input.GetKeyDown(GameControls.instance.attackButton)){ - Debug.Log("Player is attacking"); - - if(player.Weapon == null) return; - - player.Weapon.Attack(); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Core/Player/PlayerInputController.cs b/Assets/Scripts/Core/Player/PlayerInputController.cs new file mode 100644 index 0000000000000000000000000000000000000000..09084365b1c35f9a3587e4e1652141dbdfefd1a7 --- /dev/null +++ b/Assets/Scripts/Core/Player/PlayerInputController.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +public class PlayerInputController{ + private readonly Player player; + + public float movementInputX; + public float movementInputZ; + + public PlayerInputController(Player player){ + this.player = player; + } + + public void HandleInputs(){ + movementInputX = Input.GetAxisRaw("Horizontal"); + movementInputZ = Input.GetAxisRaw("Vertical"); + + if(Input.GetKeyDown(GameControls.instance.attackButton)){ + Debug.Log("Player is attacking"); + + if(player.Weapon == null) return; + + player.Weapon.Attack(); + } + else if(Input.GetKeyDown(GameControls.instance.interactButton)){ + Debug.Log("Player is interacting"); + + ObjectManager.instance.LogObjects(); + EntityManager.instance.LogObjects(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Core/Player/PlayerAttackController.cs.meta b/Assets/Scripts/Core/Player/PlayerInputController.cs.meta similarity index 100% rename from Assets/Scripts/Core/Player/PlayerAttackController.cs.meta rename to Assets/Scripts/Core/Player/PlayerInputController.cs.meta diff --git a/Assets/Scripts/Core/Player/PlayerMovementController.cs b/Assets/Scripts/Core/Player/PlayerMovementController.cs index 9cd5490ff09c289a1670ea08581ffc0623d74437..58681cee7b9c00f1dd708f7da43f1d63ed18cd2d 100644 --- a/Assets/Scripts/Core/Player/PlayerMovementController.cs +++ b/Assets/Scripts/Core/Player/PlayerMovementController.cs @@ -19,12 +19,12 @@ public class PlayerMovementController{ } public void HandleMovement(){ - float keyPressX = Input.GetAxisRaw("Horizontal"); - float keyPressZ = Input.GetAxisRaw("Vertical"); + float inputX = player.inputController.movementInputX; + float inputZ = player.inputController.movementInputZ; Vector3 velocity = new(player.Rigidbody.velocity.x, player.Rigidbody.velocity.y, player.Rigidbody.velocity.z); Vector3 dampVelocity = Vector3.zero; - Vector3 inputVector = new(keyPressX, 0, keyPressZ); + Vector3 inputVector = new(inputX, 0, inputZ); Vector3 modifierVector = inputVector.normalized * player.stats.MaxSpeed; velocity.x = modifierVector.x; velocity.z = modifierVector.z; diff --git a/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..5c1854d7c7305f6b24ba471f78beb1e706863ae5 --- /dev/null +++ b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using UnityEngine; + +public class BaseObjectManager : MonoBehaviour{ + protected string ManagerName = "Manager"; + // Functions + public virtual void LogObjects(){ + WorldObject[] worldObjects = GetComponentsInChildren<WorldObject>(); + string idArray = "["; + for (int i = 0; i < worldObjects.Length; i++){ + idArray += worldObjects[i].Id; + if(i != worldObjects.Length - 1) idArray += ","; + } + idArray += "]"; + + Debug.Log(string.Format("Object ids in {0}: {1}", ManagerName, idArray)); + } + + public virtual WorldObject GetWorldObject(string id){ + WorldObject[] worldObjects = GetComponentsInChildren<WorldObject>(); + for (int i = 0; i < worldObjects.Length; i++){ + if(worldObjects[i].Id == id) return worldObjects[i]; + } + return null; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs.meta b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..99f2c1828a84cf55ff51a8d7c12b53527d2fc7f9 --- /dev/null +++ b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e021d77bd3c097341bf8774207a6ab50 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/AttackEntity.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/AttackEntity.cs index 7cdde8436755e7f216eb44ea7317a1682ab01dca..5b77ced02201a574821d0e8d252e6ab3a5949cfc 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/AttackEntity.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/AttackEntity.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -public class AttackEntity : RigidEntity, IAttack{ +public class AttackEntity : WorldObject, IAttack{ // Attributes [SerializeField] private float damage; [SerializeField] private float knockbackPower; diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/AttackObject.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/AttackObject.cs index 41c5ea2c299ef8a6199f5a8d253de8a4e834ec2e..940b3447aa0853f4c4c2ac90f00ded37807ee5d8 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/AttackObject.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/AttackObject.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -public class AttackObject : MonoBehaviour, IAttack{ +public class AttackObject : WorldObject, IAttack{ // Attributes [SerializeField] private float damage; [SerializeField] private float knockbackPower; diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableObject.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableObject.cs index 84356f9ef85dd0a4bc755bb60fbf9ed330b507e3..927c4e8ce831e4f1651ca6735b2e69cc0388f9ea 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableObject.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableObject.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -public class DamageableObject : MonoBehaviour, IDamageable{ +public class DamageableObject : WorldObject, IDamageable{ // Attributes private bool damageable = true; [SerializeField] private float maxHealth; diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs index 2b27abc800e455c6938e89791902360bd31e1f45..105e3b70ab2a702b72705bc065e006ac8d943f2a 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs @@ -1,6 +1,6 @@ using UnityEngine; -public class RigidEntity : MonoBehaviour, IRigid { +public class RigidEntity : WorldObject, IRigid { // Attributes [SerializeField] private float knockbackResistance; [SerializeField] private float baseSpeed; diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs new file mode 100644 index 0000000000000000000000000000000000000000..cae45231e0ea7cd7c609ebd300fbde9abfaa6e98 --- /dev/null +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs @@ -0,0 +1,11 @@ +using UnityEngine; + +public class WorldObject : MonoBehaviour{ + private static int autoIncrement = 0; + public string Id; + + protected void Awake(){ + Id = autoIncrement.ToString(); + autoIncrement++; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs.meta b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..f4ebe400849cc5b4958485773b38e2d815698b8d --- /dev/null +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcd557e81d5a5f145874252a42723dcc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: