[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
}