KonTrax
3/7/2015 - 8:43 AM

From http://www.reddit.com/r/Unity3D/comments/2xyy53/how_do_you_use_resources_in_your_projects/

[AdvancedInspector, Serializable]
public class WeakReference
{
    [SerializeField]
    private string path;

    [Inspect]
    public UnityEngine.Object Object
    {
        get { return Resources.Load(path); }
#if UNITY_EDITOR
        set 
        {
            if (value == null)
            {
                path = "";
                return;
            }

            string fullPath = AssetDatabase.GetAssetPath(value);
            string[] paths = fullPath.Split('.')[0].Split(new string[] { "/Resources/" }, StringSplitOptions.RemoveEmptyEntries);
            if (paths.Length == 1)
            {
                path = paths[0];
                return;
            }

            path = paths[1];
        }
#endif
    }

    public static implicit operator UnityEngine.Object(WeakReference reference)
    {
        return reference.Object;
    }

    public WeakReference() { }

#if UNITY_EDITOR
    public static implicit operator WeakReference(UnityEngine.Object source)
    {
        return new WeakReference(source);
    }

    public WeakReference(UnityEngine.Object source)
    {
        Object = source;
    }
#endif
}