public override void ActivateVariant(int hitMaterial) { if (Variants == null || Variants.Count == 0) { WorldUtils.SpawnEffect(FallbackEffect, transform.position, transform.eulerAngles, CoreUtils.GetWorldRoot()); return; } string foundEffect = null; foreach (var variant in Variants) { if (variant.HitMaterial == hitMaterial) { foundEffect = variant.Effect; break; } } if (!string.IsNullOrEmpty(foundEffect)) { WorldUtils.SpawnEffect(foundEffect, transform.position, transform.eulerAngles, CoreUtils.GetWorldRoot()); } else { WorldUtils.SpawnEffect(FallbackEffect, transform.position, transform.eulerAngles, CoreUtils.GetWorldRoot()); } if (DestroyAfterSpawn) { Destroy(this.gameObject); } }
/// <summary> /// Spawns a hit puff, setting position and variant /// </summary> public static GameObject SpawnHitPuff(string effect, Vector3 position, int hitMaterial) { GameObject puff = null; try { if (!string.IsNullOrEmpty(effect)) { puff = WorldUtils.SpawnEffect(effect, position, Vector3.zero, CoreUtils.GetWorldRoot()); if (puff != null) { var puffScript = puff.GetComponent <HitPuffScript>(); if (puffScript != null) { puffScript.ActivateVariant(hitMaterial); } } } } catch (Exception e) { Debug.LogError("Failed to spawn HitPuff!"); Debug.LogException(e); } return(puff); }
private void EnterPainState() { Transform effectSpawnPoint = EffectSpawnPoint == null ? transform : EffectSpawnPoint; if (Animator != null) { Animator.Play(HurtingState); } if (FacingSpriteComponent != null) { FacingSpriteComponent.SetState(DestroyableThingState.Hurting); } if (!string.IsNullOrEmpty(PainSoundName)) { AudioPlayer.Instance.PlaySoundPositional(PainSoundName, SoundType.Sound, false, effectSpawnPoint.position); } PainSoundSource.Ref()?.Play(); if (!string.IsNullOrEmpty(PainEffect)) { WorldUtils.SpawnEffect(PainEffect, effectSpawnPoint.position, effectSpawnPoint.eulerAngles, null); } }
private void UpdateDeathState() { if (ForceDeadState) { //force dead state after a restore Debug.LogWarning($"{name}: force dead state after restore"); //force objects if they exist if (AliveObject != null) { AliveObject.SetActive(false); } if (DeadObject != null) { DeadObject.SetActive(true); } //force animator if (Animator != null) { Animator.Play(DeadState); } //force FacingSprite if (FacingSpriteComponent != null) { FacingSpriteComponent.SetState(DestroyableThingState.Dead); } //force colliders if (DisableCollidersOnDeath) { foreach (var collider in GetComponentsInChildren <Collider>()) { collider.enabled = false; } } if (RepeatDeathSpecial) { DeathSpecial.Ref()?.Execute(new ActionInvokerData() { Activator = LastDamageDealer }); //note that LastDamageDealer will almost certainly be null } //destroy/deactivate if (DeactivateOnDeath) { gameObject.SetActive(false); } if (DestroyOnDeath) { Destroy(gameObject); } ForceDeadState = false; IsDead = true; } /* * if(IsDead && Health > 0 && Reversible) * { * IsDead = false; //TODO full resurrections * return; * } */ if (IsDead) { return; } if (Health <= 0) { Transform effectSpawnPoint = EffectSpawnPoint == null ? transform : EffectSpawnPoint; //die //animation if (AliveObject != null) { AliveObject.SetActive(false); } if (DeadObject != null) { DeadObject.SetActive(true); } //Animator animation options if (Animator != null) { Animator.Play(DyingState); } //FacingSprite animation options if (FacingSpriteComponent != null) { FacingSpriteComponent.SetState(DestroyableThingState.Dying); } //colliders if (DisableCollidersOnDeath) { foreach (var collider in GetComponentsInChildren <Collider>()) { collider.enabled = false; } } //sound if (!string.IsNullOrEmpty(DeathSoundName)) { AudioPlayer.Instance.PlaySoundPositional(DeathSoundName, SoundType.Sound, false, effectSpawnPoint.position); } DeathSoundSource.Ref()?.Play(); //effect if (!string.IsNullOrEmpty(DeathEffect)) { WorldUtils.SpawnEffect(DeathEffect, effectSpawnPoint.position, effectSpawnPoint.eulerAngles, null); } DeathSpecial.Ref()?.Execute(new ActionInvokerData() { Activator = LastDamageDealer }); //destroy/deactivate if (DeactivateOnDeath) { gameObject.SetActive(false); } if (DestroyOnDeath) { Destroy(gameObject); } IsDead = true; } }