using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class OnDemandLoader { public static T Load(string path) where T : Object { T returnValue = null; try { if (!resourceCache.ContainsKey(path)) { resourceCache[path] = Resources.Load(path); } returnValue = (T)resourceCache[path]; } catch { Debug.LogError($"Cast of{typeof(T)} cannot be done. Path: {path}"); } return returnValue; } public static T[] LoadAll(string path) where T : Object { if (!allResourceCache.ContainsKey(path)) allResourceCache[path] = Resources.LoadAll(path); return (T[])allResourceCache[path]; } static Dictionary resourceCache = new Dictionary(); static Dictionary allResourceCache = new Dictionary(); }