Пример #1
0
        public IAsset GetUnresolved(string name)
        {
            var candidatesWithTimes       = _rawAssetLoader.LoadRawAssetCandidatesWithModificationDates(name);
            var loaders                   = _assetLoaders.ToArray();
            var failedDueToCompilation    = false;
            var hasMoreThanZeroCandidates = false;

            var candidates = candidatesWithTimes.OrderByDescending(x => x.Value).Select(x => x.Key).ToList();

            foreach (var candidate in candidates)
            {
                hasMoreThanZeroCandidates = true;

                foreach (var loader in loaders)
                {
                    var canLoad = false;
                    try
                    {
                        canLoad = loader.CanLoad(candidate);
                    }
                    catch (Exception)
                    {
                    }

                    if (canLoad)
                    {
                        var result = loader.Load(name, candidate);

                        if (!this.SkipCompilation)
                        {
                            _transparentAssetCompiler.Handle(result);

                            if (result.SourceOnly && (!this.AllowSourceOnly || name == "font.Default"))
                            {
                                // We can't have source only assets past this point.  The compilation
                                // failed, but we definitely do have a source representation, so let's
                                // keep that around if we need to throw an exception.
                                failedDueToCompilation = true;
                                Console.WriteLine(
                                    "WARNING: Unable to compile " + name
                                    + " at runtime (a compiled version may be used).");
                                break;
                            }
                        }

                        return(result);
                    }
                }
            }

            if (failedDueToCompilation)
            {
                throw new AssetNotCompiledException(name);
            }

            if (!hasMoreThanZeroCandidates)
            {
                throw new AssetNotFoundException(name);
            }

            // NOTE: We don't use asset defaults with the local asset manager, if it
            // doesn't exist, the load fails.
            throw new InvalidOperationException(
                      "Unable to load asset '" + name + "'.  " + "No loader for this asset could be found.");
        }