TagTool.Cache.ResourceReference.ChangeLocation C# (CSharp) Méthode

ChangeLocation() public méthode

Changes the location of the resource by changing its location flags.
Unsupported resource location
public ChangeLocation ( ResourceLocation newLocation ) : void
newLocation ResourceLocation The new location.
Résultat void
        public void ChangeLocation(ResourceLocation newLocation)
        {
            OldLocationFlags &= ~OldResourceLocationFlags.LocationMask;
            NewLocationFlags &= ~NewResourceLocationFlags.LocationMask;
            switch (newLocation)
            {
                case ResourceLocation.Resources:
                    OldLocationFlags |= OldResourceLocationFlags.InResources;
                    NewLocationFlags |= NewResourceLocationFlags.InResources;
                    break;
                case ResourceLocation.Textures:
                    OldLocationFlags |= OldResourceLocationFlags.InTextures;
                    NewLocationFlags |= NewResourceLocationFlags.InTextures;
                    break;
                case ResourceLocation.TexturesB:
                    OldLocationFlags |= OldResourceLocationFlags.InTexturesB;
                    NewLocationFlags |= NewResourceLocationFlags.InTexturesB;
                    break;
                case ResourceLocation.Audio:
                    OldLocationFlags |= OldResourceLocationFlags.InAudio;
                    NewLocationFlags |= NewResourceLocationFlags.InAudio;
                    break;
                case ResourceLocation.Video:
                    OldLocationFlags |= OldResourceLocationFlags.InVideo;
                    NewLocationFlags |= NewResourceLocationFlags.InVideo;
                    break;
                case ResourceLocation.RenderModels:
                    NewLocationFlags |= NewResourceLocationFlags.InRenderModels;
                    break;
                case ResourceLocation.Lightmaps:
                    NewLocationFlags |= NewResourceLocationFlags.InLightmaps;
                    break;
                default:
                    throw new ArgumentException("Unsupported resource location");
            }
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Adds a new resource to a cache.
        /// </summary>
        /// <param name="resource">The resource reference to initialize.</param>
        /// <param name="location">The location where the resource should be stored.</param>
        /// <param name="dataStream">The stream to read the resource data from.</param>
        /// <exception cref="System.ArgumentNullException">resource</exception>
        /// <exception cref="System.ArgumentException">The input stream is not open for reading;dataStream</exception>
        public void Add(ResourceReference resource, ResourceLocation location, Stream dataStream)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }
            if (!dataStream.CanRead)
            {
                throw new ArgumentException("The input stream is not open for reading", "dataStream");
            }

            resource.ChangeLocation(location);
            var cache = GetCache(resource);

            using (var stream = cache.File.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                var dataSize = (int)(dataStream.Length - dataStream.Position);
                var data     = new byte[dataSize];
                dataStream.Read(data, 0, dataSize);
                uint compressedSize;
                resource.Index            = cache.Cache.Add(stream, data, out compressedSize);
                resource.CompressedSize   = compressedSize;
                resource.DecompressedSize = (uint)dataSize;
                resource.DisableChecksum();
            }
        }
All Usage Examples Of TagTool.Cache.ResourceReference::ChangeLocation