diff --git a/Assets/Scripts/Core/Entities/Mobs/Dummy/Dummy.cs b/Assets/Scripts/Core/Entities/Mobs/Dummy/Dummy.cs index bc52d4d90e43df551f4520726a3783401c6bfe2c..b0db12c7c9a709a82cfce4f2c20e56533e443dc1 100644 --- a/Assets/Scripts/Core/Entities/Mobs/Dummy/Dummy.cs +++ b/Assets/Scripts/Core/Entities/Mobs/Dummy/Dummy.cs @@ -1,6 +1,9 @@ using UnityEngine; public class Dummy : EnemyEntity{ + // Static attributes + public static string ObjectIdPrefix = "Dummy"; + // Attributes private DummyAnimationController animationController; public DummyStateController stateController; @@ -8,6 +11,7 @@ public class Dummy : EnemyEntity{ // Constructor new protected void Start(){ base.Start(); + SetIdPrefix(ObjectIdPrefix); stateController = new DummyStateController(this); animationController = new DummyAnimationController(this); } diff --git a/Assets/Scripts/Core/Objects/Collectibles/TestCollectible/TestCollectible.cs b/Assets/Scripts/Core/Objects/Collectibles/TestCollectible/TestCollectible.cs index 4fa1dcf94a3835cc3f565cf334d11e251f088c83..86ae86d36bf426c8e165858d1878446f4694f850 100644 --- a/Assets/Scripts/Core/Objects/Collectibles/TestCollectible/TestCollectible.cs +++ b/Assets/Scripts/Core/Objects/Collectibles/TestCollectible/TestCollectible.cs @@ -1,6 +1,16 @@ using UnityEngine; public class TestCollectible : Collectible{ + // Static attributes + public static string ObjectIdPrefix = "Player"; + + // Constructor + protected new void Start(){ + base.Start(); + SetIdPrefix(ObjectIdPrefix); + } + + // Functions protected override void OnCollect(){ Debug.Log("Test collectible collected"); } diff --git a/Assets/Scripts/Core/Player/Player.cs b/Assets/Scripts/Core/Player/Player.cs index dc6bcb1ff25d09b17904afe73e0e76603e8c5c9e..24b9f6944163576cc9e221dedf26ec3a55973f08 100644 --- a/Assets/Scripts/Core/Player/Player.cs +++ b/Assets/Scripts/Core/Player/Player.cs @@ -4,6 +4,9 @@ using System.Collections.Generic; using UnityEngine; public class Player : AccompaniableCombatant { + // Static attributes + public static string ObjectIdPrefix = "Player"; + // Attributes private PlayerAnimationController animationController; private PlayerMovementController movementController; @@ -14,6 +17,7 @@ public class Player : AccompaniableCombatant { // Constructor new void Start(){ base.Start(); + SetIdPrefix(ObjectIdPrefix); Health *= GameConfig.DIFFICULTY_MODIFIERS[GameSaveData.instance.difficulty].PlayerHealthMultiplier; // TODO: Review, base damage is currently done in the ObjectFactory. Might need to decide which is best diff --git a/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs index 5c1854d7c7305f6b24ba471f78beb1e706863ae5..b495b2ea417a20fe4224d11e7fd976de9194f0ae 100644 --- a/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs +++ b/Assets/Scripts/Library/BaseClasses/BaseObjectManager.cs @@ -16,6 +16,10 @@ public class BaseObjectManager : MonoBehaviour{ Debug.Log(string.Format("Object ids in {0}: {1}", ManagerName, idArray)); } + public virtual WorldObject[] GetWorldObjects(){ + return GetComponentsInChildren<WorldObject>(); + } + public virtual WorldObject GetWorldObject(string id){ WorldObject[] worldObjects = GetComponentsInChildren<WorldObject>(); for (int i = 0; i < worldObjects.Length; i++){ @@ -23,4 +27,9 @@ public class BaseObjectManager : MonoBehaviour{ } return null; } + + public virtual void RemoveWorldObject(string id){ + WorldObject worldObject = GetWorldObject(id); + Destroy(worldObject.gameObject); + } } \ No newline at end of file diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableEntity.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableEntity.cs index 128b94fa598c81a742cada506ad5be6cf0adbff8..544e3516a4dda39019471785a79394c946aed6cc 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableEntity.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/DamageableEntity.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -public class DamageableEntity : RigidEntity, IDamageable{ +public class DamageableEntity : WorldEntity, 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/WorldEntity.cs similarity index 96% rename from Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs rename to Assets/Scripts/Library/BaseClasses/EntityObject/WorldEntity.cs index 105e3b70ab2a702b72705bc065e006ac8d943f2a..9e5369b455347701d80a9e3a6dee22f7553fe62d 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldEntity.cs @@ -1,6 +1,6 @@ using UnityEngine; -public class RigidEntity : WorldObject, IRigid { +public class WorldEntity : WorldObject, IRigid { // Attributes [SerializeField] private float knockbackResistance; [SerializeField] private float baseSpeed; diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs.meta b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldEntity.cs.meta similarity index 100% rename from Assets/Scripts/Library/BaseClasses/EntityObject/RigidEntity.cs.meta rename to Assets/Scripts/Library/BaseClasses/EntityObject/WorldEntity.cs.meta diff --git a/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs index cae45231e0ea7cd7c609ebd300fbde9abfaa6e98..7495451c1faa7ed390ebdc3320267b77e2587e8d 100644 --- a/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs +++ b/Assets/Scripts/Library/BaseClasses/EntityObject/WorldObject.cs @@ -1,11 +1,23 @@ using UnityEngine; public class WorldObject : MonoBehaviour{ + // Attributes private static int autoIncrement = 0; + private int NumberId; + private string Prefix; public string Id; + // Constructor protected void Awake(){ - Id = autoIncrement.ToString(); + NumberId = autoIncrement; + Id = NumberId.ToString(); autoIncrement++; } -} \ No newline at end of file + + // Functions + protected void SetIdPrefix(string prefix){ + Prefix = prefix; + if(Prefix == "") Id = NumberId.ToString(); + else Id = Prefix + "_" + Id; + } +} diff --git a/Assets/Scripts/Library/Util/ObjectFactory.cs b/Assets/Scripts/Library/Util/ObjectFactory.cs index e0d8a44ceec52c4822e6780aec7b635d6eabb57c..bbe48929784f371aad5a38e5c2a4d9a05789b75d 100644 --- a/Assets/Scripts/Library/Util/ObjectFactory.cs +++ b/Assets/Scripts/Library/Util/ObjectFactory.cs @@ -12,7 +12,7 @@ public static class ObjectFactory{ int renderingOrder = 0, string objectName = "Unnamed Object" ){ - GameObject returnObject = parent == null? GameObject.Instantiate(gameObject) : GameObject.Instantiate(gameObject, parent); + GameObject returnObject = parent == null? GameObject.Instantiate(gameObject, ObjectManager.instance.transform) : GameObject.Instantiate(gameObject, parent); if(position != null) returnObject.transform.position = position.Value; if(rotation != null) returnObject.transform.rotation = rotation.Value; if(scale != null) returnObject.transform.localScale = Vector3.Scale(returnObject.transform.localScale, scale.Value); @@ -73,7 +73,7 @@ public static class ObjectFactory{ return prefabObject; } - public static GameObject CreateCollectibleObject( + public static Collectible CreateCollectibleObject( string prefabPath, Transform parent = null, Vector3? position = null, @@ -83,10 +83,24 @@ public static class ObjectFactory{ string objectName = "Unnamed Object" ){ GameObject prefabObject = CreateObject(prefabPath, parent == null? ObjectManager.instance.transform : parent, position, scale, rotation, renderingOrder, objectName); - if(!prefabObject.TryGetComponent<Collectible>(out var collectibleObject)) Debug.LogError("Loaded prefab is not a Collectible: " + prefabPath); + if(!prefabObject.TryGetComponent<Collectible>(out var collectible)) Debug.LogError("Loaded prefab is not a Collectible: " + prefabPath); prefabObject.layer = LayerMask.NameToLayer(GameEnvironmentConfig.LAYER_COLLECTIBLE); - return prefabObject; + return collectible; + } + + public static WorldEntity CreateEntity( + string prefabPath, + Transform parent = null, + Vector3? position = null, + Vector3? scale = null, + Quaternion? rotation = null, + int renderingOrder = 0, + string objectName = "Unnamed Object" + ){ + GameObject prefabObject = CreateObject(prefabPath, parent == null? EntityManager.instance.transform : parent, position, scale, rotation, renderingOrder, objectName); + if(!prefabObject.TryGetComponent<WorldEntity>(out var entity)) Debug.LogError("Loaded prefab is not an entity: " + prefabPath); + return entity; } public static void Destroy(GameObject gameObject, float delay = 0){