public static T UnityLoad <T>(string path, int span) where T : class { // prepend "Resources" to the start of the path to prevent edge cases // where the same name file in StreamingAssets could conflict string resourcePath = PathUtil.Combine("Resources", path); Resource <T> res; if (checkCache(resourcePath, out res)) { return(res.Data); } // check if the asset can be processed as text if (_textAssetProcessors.ContainsKey(typeof(T))) { ITextAssetHandler handler = _textAssetProcessors[typeof(T)]; TextAsset textAsset = Resources.Load <TextAsset>(path); // check to see if we loaded successfully if (textAsset == null) { throw new ToriiResourceLoadException("Unable to load resource: '" + path + "'", typeof(T)); } res = new Resource <T>(span) { Data = (T)handler.Process(textAsset) }; // we don't need the text asset anymore Resources.UnloadAsset(textAsset); } else { // otherwise just load it using Unity's resource handling res = new Resource <T>(span, ResourceType.Unity) { Data = Resources.Load(path, typeof(T)) as T }; } if (res.Data == null) { throw new ToriiResourceLoadException("Unable to load resource: '" + path + "'", typeof(T)); } _resources[resourcePath] = res; return(res.Data); }
public static void RegisterTextAssetProcessor(ITextAssetHandler handler) { _textAssetProcessors[handler.HandlerType] = handler; }