Skip to content

Commit

Permalink
Merge pull request #7 from Brian-Jiang/v1.0.1
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
Brian-Jiang committed May 10, 2024
2 parents 7d98dff + f555775 commit f763b38
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Runtime/Loaders/ResourcesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
namespace SmartReference.Runtime {
public class ResourcesLoader: ISmartReferenceLoader {
public Object Load(string path, Type type) {
return Resources.Load(path, type);
var resourcesPath = GetResourcesPath(path);
return Resources.Load(resourcesPath, type);
}

public void LoadAsync(string path, Type type, Action<Object> callback) {
var request = Resources.LoadAsync(path, type);
var resourcesPath = GetResourcesPath(path);
var request = Resources.LoadAsync(resourcesPath, type);
request.completed += _ => callback?.Invoke(request.asset);
}

private string GetResourcesPath(string path) {
var index = path.LastIndexOf("Resources/", StringComparison.Ordinal);
if (index == -1) {
Debug.LogError($"[SmartReference] ResourcesLoader: Path {path} is not in Resources folder");
return path;
}

var extensionIndex = path.LastIndexOf(".", StringComparison.Ordinal);
return path[(index + "Resources/".Length)..extensionIndex];
}
}
}

0 comments on commit f763b38

Please sign in to comment.