using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class AttachedValues : MonoBehaviour
{
	public Dictionary<string, object> attachedValues = new Dictionary<string, object> ();
}

public static class AttachedValuesHelper
{
	public static void SetAttachedValue (this Transform transform, string key, object value)
	{
		transform.gameObject.SetAttachedValue (key, value);
	}
	
	public static void SetAttachedValue (this GameObject gameObject, string key, object value)
	{
		var av = gameObject.GetComponent<AttachedValues> ();
		if (av == null) {
			av = gameObject.AddComponent<AttachedValues> ();
		}
		av.attachedValues [key] = value;
	}
	
	public static object GetAttachedValue (this Transform transform, string key)
	{
		return transform.gameObject.GetAttachedValue (key);
	}
	
	
	public static object GetAttachedValue (this GameObject gameObject, string key)
	{
		object result = null;
		var av = gameObject.GetComponent<AttachedValues> ();
		if (av != null) {
			if (av.attachedValues.TryGetValue (key, out result) == false) {
				result = null;
			}
		}
		return result;
	}
	
}
