diff --git a/Assets/CAF/Entities/Managers/EntityHurtboxManager.cs b/Assets/CAF/Entities/Managers/EntityHurtboxManager.cs index 35d71d1a..f6e00c7e 100644 --- a/Assets/CAF/Entities/Managers/EntityHurtboxManager.cs +++ b/Assets/CAF/Entities/Managers/EntityHurtboxManager.cs @@ -1,4 +1,5 @@ -using CAF.Input; +using CAF.Combat; +using CAF.Input; using System; using System.Collections; using System.Collections.Generic; @@ -10,9 +11,102 @@ public class EntityHurtboxManager : MonoBehaviour { [SerializeField] protected EntityManager manager; + protected StateHurtboxDefinition currentHurtboxDefinition; + + protected List hurtboxPool = new List(); + protected Dictionary> hurtboxGroups = new Dictionary>(); + public virtual void Tick() { + CreateHurtboxes(manager.StateManager.CurrentStateFrame); + } + + List hurtboxGroupsToDelete = new List(); + public virtual void CreateHurtboxes(uint frame) + { + if(currentHurtboxDefinition == null) + { + return; + } + + // Create hurtbox groups. + for(int i = 0; i < currentHurtboxDefinition.hurtboxGroups.Count; i++) + { + if (!hurtboxGroups.ContainsKey(i)) + { + hurtboxGroups.Add(i, new List()); + } + // Create Hurtboxes. + for(int w = 0; w < currentHurtboxDefinition.hurtboxGroups[i].boxes.Count; w++) + { + Hurtbox hurtbox; + // Group doesn't already have a hurtbox, create one. + if(hurtboxGroups[i].Count < w) + { + hurtbox = CreateHurtbox(); + hurtboxGroups[i].Add(hurtbox); + } + else + { + // Group has a hurtbox here already. + hurtbox = hurtboxGroups[i][w]; + } + hurtbox.gameObject.SetActive(true); + + // Set the hurtbox's position/rotation/etc. + SetHurtboxInfo(i, w); + } + // Cleanup stray hurtboxes. + for(int s = currentHurtboxDefinition.hurtboxGroups[i].boxes.Count; s < hurtboxGroups[i].Count; s++) + { + DestroyHurtbox(hurtboxGroups[i][s]); + hurtboxGroups[i].RemoveAt(s); + } + } + + // Cleanup stray hurtbox groups. + foreach(int k in hurtboxGroups.Keys) + { + if(k >= currentHurtboxDefinition.hurtboxGroups.Count) + { + hurtboxGroupsToDelete.Add(k); + CleanupHurtboxGroup(k); + } + } + for(int h = 0; h < hurtboxGroupsToDelete.Count; h++) + { + hurtboxGroups.Remove(h); + } + hurtboxGroupsToDelete.Clear(); + } + + private void CleanupHurtboxGroup(int groupID) + { + for(int i = 0; i < hurtboxGroups[groupID].Count; i++) + { + DestroyHurtbox(hurtboxGroups[groupID][i]); + } + } + + protected virtual void SetHurtboxInfo(int groupID, int hurtboxIndex) + { + throw new NotImplementedException(); + } + protected virtual Hurtbox CreateHurtbox() + { + throw new NotImplementedException(); + } + + protected virtual void DestroyHurtbox(Hurtbox hurtbox) + { + hurtboxPool.Add(hurtbox); + hurtbox.gameObject.SetActive(false); + } + + public virtual void SetHurtboxDefinition(StateHurtboxDefinition stateHurtboxDefinition) + { + currentHurtboxDefinition = stateHurtboxDefinition; } } } \ No newline at end of file diff --git a/Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab b/Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab index 1ab20a8c..688d5726 100644 --- a/Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab +++ b/Assets/CAF/Samples/TDAction/Characters/Boxer/Boxer.prefab @@ -170,6 +170,7 @@ GameObject: - component: {fileID: 1031207210466028850} - component: {fileID: 6300165297845272074} - component: {fileID: 1715174515004957371} + - component: {fileID: -2960863564831657620} m_Layer: 8 m_Name: Boxer m_TagString: Untagged @@ -353,10 +354,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: manager: {fileID: 8147816337253296054} - forceMovement: {x: 0, y: 0, z: 0} - forceGravity: {x: 0, y: 0, z: 0} - forceDamage: {x: 0, y: 0, z: 0} - forcePushbox: {x: 0, y: 0, z: 0} + forceMovement: {x: 0, y: 0} + forceGravity: {x: 0, y: 0} + forceDamage: {x: 0, y: 0} + forcePushbox: {x: 0, y: 0} --- !u!114 &1031207210466028850 MonoBehaviour: m_ObjectHideFlags: 0 @@ -399,6 +400,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: health: 0 +--- !u!114 &-2960863564831657620 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6667267786158460212} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 204e422f772d87d4f8b23557a37b17b0, type: 3} + m_Name: + m_EditorClassIdentifier: + manager: {fileID: 8147816337253296054} --- !u!1 &8500522958957405919 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs new file mode 100644 index 00000000..297ce31d --- /dev/null +++ b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs @@ -0,0 +1,33 @@ +using CAF.Combat; +using System.Collections; +using System.Collections.Generic; +using TDAction.Managers; +using UnityEngine; + +namespace TDAction.Entities +{ + public class EntityHurtboxManager : CAF.Entities.EntityHurtboxManager + { + protected override void SetHurtboxInfo(int groupID, int hurtboxIndex) + { + + } + + protected override Hurtbox CreateHurtbox() + { + Hurtbox hurtbox; + // Hurtbox in the pool. + if(hurtboxPool.Count > 0) + { + hurtbox = hurtboxPool[0]; + hurtboxPool.RemoveAt(0); + } + else + { + hurtbox = GameObject.Instantiate(GameManager.instance.hurtboxPrefab, gameObject.transform, false); + } + hurtbox.gameObject.SetActive(false); + return hurtbox; + } + } +} \ No newline at end of file diff --git a/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs.meta b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs.meta new file mode 100644 index 00000000..b0243237 --- /dev/null +++ b/Assets/CAF/Samples/TDAction/Scripts/Entities/Managers/EntityHurtboxManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 204e422f772d87d4f8b23557a37b17b0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/CAF/Samples/TDAction/Scripts/Managers/GameManager.cs b/Assets/CAF/Samples/TDAction/Scripts/Managers/GameManager.cs index d4153645..0892de3b 100644 --- a/Assets/CAF/Samples/TDAction/Scripts/Managers/GameManager.cs +++ b/Assets/CAF/Samples/TDAction/Scripts/Managers/GameManager.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using CAF.Combat; +using UnityEngine; namespace TDAction.Managers { @@ -16,6 +17,7 @@ public class GameManager : MonoBehaviour [SerializeField] private GameHandler gameHandler = null; [SerializeField] private TDAction.Entities.EntityManager playerEntity; [SerializeField] private Vector3 playerSpawnPosition; + public Hurtbox hurtboxPrefab; private void Awake() { diff --git a/TDAction_CSharp.csproj b/TDAction_CSharp.csproj index 2d747585..cc2a3466 100644 --- a/TDAction_CSharp.csproj +++ b/TDAction_CSharp.csproj @@ -101,6 +101,7 @@ +