using UnityEngine;
using System;

public class ReusablePrefab : IReusable
{
	public static explicit operator GameObject (ReusablePrefab value)
	{
		return value.Value;
	}
	
	private bool mAvailable = false;
	
	public string Name
	{
		get;
		private set;
	}
	
	public GameObject Value
	{
		get;
		private set;
	}
	
	public ReusablePrefab (GameObject value)
	{
		if (value == null)
		{
			throw new ArgumentNullException("reusable");
		}
		Value = value;
		Name = value.name;
	}

	#region IReusable implementation
	public event EventHandler<EventArgs> Destroyed;
	
	public void Dispose()
	{
		Available = true;
	}

	public void Destroy ()
	{
		Available = false;
		
		if (Destroyed != null)
		{
			Destroyed(this, EventArgs.Empty);
		}
	}

	public bool Available
	{
		get { return mAvailable; }
		private set { mAvailable = value; }
	}
	#endregion
}