Skip to content

Instantly share code, notes, and snippets.

@mattak
Created July 27, 2016 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattak/fac6b596406d557fd3c3a5497f2646f7 to your computer and use it in GitHub Desktop.
Save mattak/fac6b596406d557fd3c3a5497f2646f7 to your computer and use it in GitHub Desktop.
Lazy load for Unity Resource
using UnityEngine;
public class LazyResource<T> where T : UnityEngine.Object
{
public T _value;
public T Value
{
get
{
if (_value == null)
{
lock (this)
{
if (_value == null)
{
_value = Resources.Load<T>(path);
}
}
}
return _value;
}
}
private string path;
public LazyResource(string path)
{
this.path = path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment