Exemple #1
0
        public virtual async UniTask <IReadOnlyCollection <Resource <TResource> > > LoadAllAsync(string path = null)
        {
            var result     = new List <Resource <TResource> >();
            var addedPaths = new HashSet <string>();
            var loadTasks  = new List <UniTask <Resource <TResource> > >();
            var loadData   = new Dictionary <string, (ProvisionSource, string)>();

            foreach (var source in ProvisionSources)
            {
                var fullPath             = source.BuildFullPath(path);
                var locatedResourcePaths = await source.Provider.LocateResourcesAsync <TResource>(fullPath);

                foreach (var locatedResourcePath in locatedResourcePaths)
                {
                    var localPath = source.BuildLocalPath(locatedResourcePath);

                    if (addedPaths.Contains(localPath))
                    {
                        continue;
                    }
                    else
                    {
                        addedPaths.Add(localPath);
                    }

                    if (IsLoaded(localPath))
                    {
                        result.Add(GetLoadedOrNull(localPath));
                        continue;
                    }

                    loadTasks.Add(source.Provider.LoadResourceAsync <TResource>(locatedResourcePath));
                    loadData[locatedResourcePath] = (source, localPath);
                }
            }

            var resources = await UniTask.WhenAll(loadTasks);

            foreach (var resource in resources)
            {
                var(source, localPath) = loadData[resource.Path];
                LoadedResources.Add(new LoadedResource(resource, source));
                OnResourceLoaded?.Invoke(localPath);
                result.Add(resource);
            }

            return(result);
        }
Exemple #2
0
        public virtual async UniTask <Resource <TResource> > LoadAsync(string path)
        {
            if (IsLoaded(path))
            {
                return(GetLoadedOrNull(path));
            }

            foreach (var source in ProvisionSources)
            {
                var fullPath = source.BuildFullPath(path);
                if (!await source.Provider.ResourceExistsAsync <TResource>(fullPath))
                {
                    continue;
                }

                var resource = await source.Provider.LoadResourceAsync <TResource>(fullPath);

                LoadedResources.Add(new LoadedResource(resource, source));
                OnResourceLoaded?.Invoke(path);
                return(resource);
            }

            return(Resource <TResource> .Invalid);
        }
Exemple #3
0
 private static void Internal_onResourceLoaded(RRefBase p0)
 {
     OnResourceLoaded?.Invoke(p0);
 }