Created
July 27, 2016 09:00
-
-
Save mattak/fac6b596406d557fd3c3a5497f2646f7 to your computer and use it in GitHub Desktop.
Lazy load for Unity Resource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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