/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Objects
{
using Opsive.Shared.Game;
using Opsive.UltimateCharacterController.Audio;
using Opsive.UltimateCharacterController.Game;
using Opsive.UltimateCharacterController.Events;
using Opsive.UltimateCharacterController.Objects.ItemAssist;
using Opsive.UltimateCharacterController.Traits;
using Opsive.UltimateCharacterController.Utility;
using System.Collections.Generic;
using UnityEngine;
using EventHandler = Opsive.Shared.Events.EventHandler;
///
/// Creates an explosion which applies a force and damage to any object that is within the specified radius.
///
public class Explosion : MonoBehaviour
{
[Tooltip("Should the object explode when the object is enabled?")]
[SerializeField] protected bool m_ExplodeOnEnable;
[Tooltip("Determines how far out the explosion affects other objects.")]
[SerializeField] protected float m_Radius = 5;
[Tooltip("The maximum amount of damage the explosion applies to objects with the Health component.")]
[SerializeField] protected float m_DamageAmount = 10;
[Tooltip("The maximum amount of force the explosion applies to nearby Rigidbody/IForceObject objects.")]
[SerializeField] protected float m_ImpactForce = 2;
[Tooltip("The number of frames to add the impact force to.")]
[SerializeField] protected int m_ImpactForceFrames = 1;
[Tooltip("The layers that the explosion can affect.")]
[SerializeField] protected LayerMask m_ImpactLayers = ~(1 << LayerManager.IgnoreRaycast | 1 << LayerManager.Water | 1 << LayerManager.SubCharacter | 1 << LayerManager.Overlay |
1 << LayerManager.VisualEffect);
[Tooltip("Does the explosion require line of sight in order to damage the hit object?")]
[SerializeField] protected bool m_LineOfSight;
[Tooltip("The duration of the explosion.")]
[SerializeField] protected float m_Lifespan = 3;
[Tooltip("The maximum number of objects that the explosions can detect.")]
[SerializeField] protected int m_MaxCollisionCount = 100;
[Tooltip("A set of AudioClips that can be played when the explosion occurs.")]
[SerializeField] protected AudioClipSet m_ExplosionAudioClipSet = new AudioClipSet();
[Tooltip("Unity event invoked when the explosion hits another object.")]
[SerializeField] protected UnityFloatVector3Vector3GameObjectEvent m_OnImpactEvent;
public bool ExplodeOnEnable { get { return m_ExplodeOnEnable; } set { m_ExplodeOnEnable = value; } }
public float Radius { get { return m_Radius; } set { m_Radius = value; } }
public float DamageAmount { get { return m_DamageAmount; } set { m_DamageAmount = value; } }
public float ImpactForce { get { return m_ImpactForce; } set { m_ImpactForce = value; } }
public int ImpactForceFrames { get { return m_ImpactForceFrames; } set { m_ImpactForceFrames = value; } }
public LayerMask ImpactLayers { get { return m_ImpactLayers; } set { m_ImpactLayers = value; } }
public bool LineOfSight { get { return m_LineOfSight; } set { m_LineOfSight = value; } }
public float Lifespan { get { return m_Lifespan; } set { m_Lifespan = value; } }
public AudioClipSet ExplosionAudioClipSet { get { return m_ExplosionAudioClipSet; } set { m_ExplosionAudioClipSet = value; } }
public UnityFloatVector3Vector3GameObjectEvent OnImpactEvent { get { return m_OnImpactEvent; } set { m_OnImpactEvent = value; } }
private GameObject m_GameObject;
private Transform m_Transform;
private HashSet