using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.UI;

public class ToolSet : MonoBehaviour {
	public Tool defaultTool;
	public UnityEvent PreChange;
	public UnityEvent OnChanged;

	private Tool active;
	public Tool Active
	{
		get { return active; }
		set
		{
			PreChange.Invoke();
			if (value == null)
				value = defaultTool;
			if (active == value) return;
			if (active != null)
				active.DeActivate();
			active = value;
			OnChanged.Invoke();
		}
	}

	void Awake()
	{
		if (defaultTool != null)
			defaultTool.Activate();
	}

	public void Reset()
	{
		if (defaultTool != null)
			defaultTool.Activate();
		else
			Active = null;
	}

	//call this to set active to null without calling OnChanged
	public void Clear()
	{
		if (active != null)
			active.DeActivate();
		active = null;
	}
}
