Reset() публичный Метод

Reset the stream position to the original position when the asset loader was created.
public Reset ( ) : void
Результат void
Пример #1
0
        /// <summary>Find the best <see cref="AssetFormat"/> for loading an <see cref="Asset"/>.</summary>
        /// <param name="matchStrength"></param>
        /// <param name="loader"></param>
        /// <param name="formats"></param>
        /// <param name="resolveConflict"></param>
        /// <returns></returns>
        public static AssetFormat LoadMatchAsset(out LoadMatchStrength matchStrength, AssetLoader loader, IEnumerable<AssetFormat> formats, ResolveLoadConflictCallback resolveConflict = null)
        {
            if (loader == null)
                throw new ArgumentNullException("context");
            if (formats == null)
                throw new ArgumentNullException("formats");

            AssetFormat bestFormat = null;
            LoadMatchStrength bestMatch = LoadMatchStrength.None;
            bool bestConflict = false;

            // Attempt to find the one best loader.
            foreach (AssetFormat format in formats) {
                if (!format.CanLoad || !format.IsEnabled)
                    continue;

                LoadMatchStrength match = format.LoadMatch(loader);
                loader.Reset();
                if (match <= LoadMatchStrength.None || match < bestMatch)
                    continue;

                if (match == bestMatch)
                    bestConflict = true;
                else {
                    bestFormat = format;
                    bestMatch = match;
                    bestConflict = false;
                }
            }

            matchStrength = bestMatch;

            // If a single best loader is found, return it.
            if (!bestConflict) {
                if (bestFormat == null)
                    throw new InvalidDataException("No loader could be found for " + loader.Name + ".");

                return bestFormat;
            }

            // Otherwise there are multiple formats with equal match strengths; gather those together.
            List<AssetFormat> conflicts = new List<AssetFormat>();

            foreach (AssetFormat format in formats) {
                if (!format.CanLoad || !format.IsEnabled)
                    continue;

                loader.Reset();
                LoadMatchStrength match = format.LoadMatch(loader);
                if (match == bestMatch)
                    conflicts.Add(format);
            }

            // Attempt to resolve the conflict.
            bestFormat = null;
            if (resolveConflict != null)
                bestFormat = resolveConflict(loader, conflicts, matchStrength);

            // If no resolution is found, throw an exception.
            if (bestFormat == null)
                throw CreateConflictException(loader, matchStrength, conflicts);

            // A resolution was found, so return the best format.
            return bestFormat;
        }
Пример #2
0
        /// <summary>Find the best <see cref="AssetFormat"/> for loading an <see cref="Asset"/>.</summary>
        /// <param name="matchStrength"></param>
        /// <param name="loader"></param>
        /// <param name="formats"></param>
        /// <param name="resolveConflict"></param>
        /// <returns></returns>
        public static AssetFormat LoadMatchAsset(out LoadMatchStrength matchStrength, AssetLoader loader, IEnumerable <AssetFormat> formats, ResolveLoadConflictCallback resolveConflict = null)
        {
            if (loader == null)
            {
                throw new ArgumentNullException("context");
            }
            if (formats == null)
            {
                throw new ArgumentNullException("formats");
            }

            AssetFormat       bestFormat = null;
            LoadMatchStrength bestMatch  = LoadMatchStrength.None;
            bool bestConflict            = false;

            // Attempt to find the one best loader.
            foreach (AssetFormat format in formats)
            {
                if (!format.CanLoad || !format.IsEnabled)
                {
                    continue;
                }

                LoadMatchStrength match = format.LoadMatch(loader);
                loader.Reset();
                if (match <= LoadMatchStrength.None || match < bestMatch)
                {
                    continue;
                }

                if (match == bestMatch)
                {
                    bestConflict = true;
                }
                else
                {
                    bestFormat   = format;
                    bestMatch    = match;
                    bestConflict = false;
                }
            }

            matchStrength = bestMatch;

            // If a single best loader is found, return it.
            if (!bestConflict)
            {
                if (bestFormat == null)
                {
                    throw new InvalidDataException("No loader could be found for " + loader.Name + ".");
                }

                return(bestFormat);
            }

            // Otherwise there are multiple formats with equal match strengths; gather those together.
            List <AssetFormat> conflicts = new List <AssetFormat>();

            foreach (AssetFormat format in formats)
            {
                if (!format.CanLoad || !format.IsEnabled)
                {
                    continue;
                }

                loader.Reset();
                LoadMatchStrength match = format.LoadMatch(loader);
                if (match == bestMatch)
                {
                    conflicts.Add(format);
                }
            }

            // Attempt to resolve the conflict.
            bestFormat = null;
            if (resolveConflict != null)
            {
                bestFormat = resolveConflict(loader, conflicts, matchStrength);
            }

            // If no resolution is found, throw an exception.
            if (bestFormat == null)
            {
                throw CreateConflictException(loader, matchStrength, conflicts);
            }

            // A resolution was found, so return the best format.
            return(bestFormat);
        }
Пример #3
0
        /// <summary>Attempt to detect the version of the resource map, returning it or <see cref="ResourceMapVersion.None"/> if this is not a resource map or is not known to be one.</summary>
        /// <param name="loader"></param>
        /// <returns></returns>
        public static ResourceMapVersion DetectVersion(AssetLoader loader)
        {
            var reader = loader.Reader;
            long length = loader.Length;

            // The filename must be "resource.map".
            if (string.Compare(System.IO.Path.GetFileName(loader.Name), "resource.map", true) != 0)
                return ResourceMapVersion.None;

            // Try SCI0.
            bool isSci0 = DetectVersionSci0(loader);
            loader.Reset();
            if (isSci0)
                return ResourceMapVersion.Sci0;

            // Try SCI1.
            bool isSci1 = DetectVersionSci1(loader);
            loader.Reset();
            if (isSci1)
                return ResourceMapVersion.Sci1;

            // Try SCI2
            bool isSci2 = DetectVersionSci2(loader);
            loader.Reset();
            if (isSci2)
                return ResourceMapVersion.Sci2;

            return ResourceMapVersion.None;
        }