Beispiel #1
0
        protected virtual Quaternion GetHitboxRotation(BoxDefinitionBase hitboxDefinitionBase)
        {
            BoxDefinition hitboxDefinition = (BoxDefinition)hitboxDefinitionBase;

            return(Quaternion.Euler(new Vector3(0, 0, manager.visual.transform.localScale.x < 0 ? 180 : 0)
                                    + hitboxDefinition.rotation));
        }
Beispiel #2
0
        protected virtual Vector3 GetHitboxPosition(BoxDefinitionBase hitboxDefinitionBase)
        {
            BoxDefinition hitboxDefinition = (BoxDefinition)hitboxDefinitionBase;

            return(manager.transform.position
                   + manager.GetVisualBasedDirection(Vector3.right) * hitboxDefinition.offset.x * ((EntityManager)manager).FaceDirection
                   + manager.GetVisualBasedDirection(Vector3.up) * hitboxDefinition.offset.y);
        }
Beispiel #3
0
        protected override HitboxBase InstantiateHitbox(BoxDefinitionBase hitboxDefinitionBase)
        {
            BoxDefinition boxDefinition = (BoxDefinition)hitboxDefinitionBase;
            GameManager   gm            = GameManager.current;

            Vector3 position = manager.transform.position
                               + manager.GetVisualBasedDirection(Vector3.forward) * boxDefinition.offset.z
                               + manager.GetVisualBasedDirection(Vector3.right) * boxDefinition.offset.x
                               + manager.GetVisualBasedDirection(Vector3.up) * boxDefinition.offset.y;

            Vector3 rotation = manager.visual.transform.eulerAngles + boxDefinition.rotation;

            GameObject hitbox = GameObject.Instantiate(gm.gameVariables.combat.hitbox, position, Quaternion.Euler(rotation));

            return(hitbox.GetComponent <Hitbox3D>());
        }
        /// <summary>
        /// Create the hitbox group of the given index.
        /// </summary>
        /// <param name="index">The index of the hitbox group.</param>
        public virtual void CreateHitboxGroup(int index)
        {
            // Group was already created.
            if (hitboxGroups.ContainsKey(index))
            {
                return;
            }

            // Variables.
            BoxGroup          currentGroup    = combatManager.CurrentAttack.attackDefinition.boxGroups[index];
            List <HitboxBase> groupHitboxList = new List <HitboxBase>(currentGroup.boxes.Count);

            // Keep track of what the hitbox ID has hit.
            if (!hurtablesHit.ContainsKey(currentGroup.ID))
            {
                hurtablesHit.Add(currentGroup.ID, new List <IHurtable>());
                hurtablesHit[currentGroup.ID].Add(combatManager);
            }

            // Loop through all the hitboxes in the group.
            for (int i = 0; i < currentGroup.boxes.Count; i++)
            {
                // Instantiate the hitbox with the correct position and rotation.
                BoxDefinitionBase hitboxDefinition = currentGroup.boxes[i];
                HitboxBase        hitbox           = InstantiateHitbox(hitboxDefinition);

                // Attach the hitbox if neccessary.
                if (currentGroup.attachToEntity)
                {
                    hitbox.transform.SetParent(manager.transform, true);
                }

                hitbox.Initialize(manager.gameObject, manager.visual.transform, manager.CombatManager.GetTeam(),
                                  currentGroup.boxes[i].shape, currentGroup.hitboxHitInfo, hitboxDefinition, hurtablesHit[currentGroup.ID]);
                int cID        = currentGroup.ID;
                int groupIndex = index;
                hitbox.OnHurt += (hurtable, hitInfo) => { OnHitboxHurt(hurtable, hitInfo, cID, groupIndex); };
                hitbox.Activate();
                groupHitboxList.Add(hitbox);
            }
            // Add the hitbox group to our list.
            hitboxGroups.Add(index, groupHitboxList);
        }
 protected virtual HitboxBase InstantiateHitbox(BoxDefinitionBase hitboxDefinitionBase)
 {
     throw new NotImplementedException("InstantiateHitbox in EntityHitboxManager must be overriden!");
 }
Beispiel #6
0
 protected override HitboxBase InstantiateHitbox(BoxDefinitionBase hitboxDefinitionBase)
 {
     return(GameObject.Instantiate(((EntityManager)manager).hitboxPrefab,
                                   GetHitboxPosition(hitboxDefinitionBase),
                                   GetHitboxRotation(hitboxDefinitionBase)));
 }