namespace Zinnia.Data.Operation
{
using UnityEngine;
using Zinnia.Extension;
///
/// Destroys the .
///
public class GameObjectDestroyer : MonoBehaviour
{
[Tooltip("The object to destroy.")]
[SerializeField]
private GameObject target;
///
/// The object to destroy.
///
public GameObject Target
{
get
{
return target;
}
set
{
target = value;
}
}
[Tooltip("Whether to destroy the GameObject immediately or at the end of the frame.")]
[SerializeField]
private bool destroyAtEndOfFrame = true;
///
/// Whether to destroy the immediately or at the end of the frame
///
public bool DestroyAtEndOfFrame
{
get
{
return destroyAtEndOfFrame;
}
set
{
destroyAtEndOfFrame = value;
}
}
///
/// Sets the to the given and then destroys it.
///
/// The object to destroy.
public virtual void DoDestroy(GameObject givenTarget)
{
if (!this.IsValidState())
{
return;
}
Target = givenTarget;
DoDestroy();
}
///
/// Destroys the .
///
public virtual void DoDestroy()
{
if (!this.IsValidState())
{
return;
}
if (DestroyAtEndOfFrame)
{
Destroy(Target);
}
else
{
DestroyImmediate(Target);
}
}
}
}