void Awake() { _invincibilityTimer = new Timer(1, false, false); _freezeFrameEvent = new FreezeFrameEvent(FREEZE_FRAMES); _hitStunEvent = new HitStunEvent(1); }
public void UpdateHitBoxes(SCAttack currentAttack, SCAttack.HurtboxState hurtboxState) { if (currentAttack == null) { for (int i = 0; i < this.DamageBoxes.Length; ++i) { this.DamageBoxes[i].transform.localPosition = Vector2.zero; this.DamageBoxes[i].enabled = false; } } else { SCAttack.HitboxKeyframe? keyframe = getKeyframeForUpdateFrame(currentAttack, this.Animator.Elapsed); if (keyframe.HasValue) { if (keyframe.Value.HurtboxState != hurtboxState) { bool success = this.HurtboxChangeCallback(keyframe.Value.HurtboxState); if (!success) return; } GameObject collided = null; IntegerRectCollider collider = null; for (int i = 0; i < this.DamageBoxes.Length; ++i) { if (i < keyframe.Value.HitboxCount) { this.DamageBoxes[i].enabled = true; this.DamageBoxes[i].transform.localPosition = (Vector2)keyframe.Value.HitboxPositions[i]; this.DamageBoxes[i].Size = keyframe.Value.HitboxSizes[i]; if (collided == null) { collided = this.DamageBoxes[i].CollideFirst(0, 0, this.DamagableLayers); if (collided != null) collider = this.DamageBoxes[i]; } } else { this.DamageBoxes[i].enabled = false; } } // Apply damage if we hit if (collided != null) { Damagable otherDamagable = collided.GetComponent<Damagable>(); if (otherDamagable != null) { IntegerVector hitPoint = collided.GetComponent<IntegerCollider>().ClosestContainedPoint((Vector2)collider.transform.position); bool landedHit = otherDamagable.Damage(currentAttack, (Vector2)this.Actor.transform.position, hitPoint); if (landedHit) { if (_freezeFrameEvent == null) _freezeFrameEvent = new FreezeFrameEvent(Damagable.FREEZE_FRAMES); this.localNotifier.SendEvent(_freezeFrameEvent); if (this.Damagable != null) this.Damagable.SetInvincible(Damagable.FREEZE_FRAMES); PooledObject hitEffect = this.HitEffect.Retain(); hitEffect.transform.position = (Vector2)hitPoint; hitEffect.GetComponent<HitEffectHandler>().InitializeWithFreezeFrames(Damagable.FREEZE_FRAMES); } } } } } }