/// <summary>
        /// Gets a custom material for a mobile billboard with textures and configuration imported from mods.
        /// </summary>
        /// <param name="archive">Archive index.</param>
        /// <param name="meshFilter">The MeshFilter of the billboard object.</param>
        /// <param name="importedTextures">All the imported textures for the archive.</param>
        /// <remarks>
        /// Seek the texture for the first frame of the first record. If found, it imports the entire archive.
        /// If this texture has an emission map the material is considered emissive and all emission maps are imported.
        /// </remarks>
        /// <returns>A material or null.</returns>
        public static Material GetMobileBillboardMaterial(int archive, MeshFilter meshFilter, ref MobileBillboardImportedTextures importedTextures)
        {
            if (!DaggerfallUnity.Settings.AssetInjection)
            {
                return(null);
            }

            Texture2D tex, emission;

            if (importedTextures.HasImportedTextures = LoadFromCacheOrImport(archive, 0, 0, true, true, out tex, out emission))
            {
                string renderMode = null;

                // Read xml configuration
                XMLManager xml;
                if (XMLManager.TryReadXml(ImagesPath, string.Format("{0:000}", archive), out xml))
                {
                    xml.TryGetString("renderMode", out renderMode);
                    importedTextures.IsEmissive = xml.GetBool("emission");
                }

                // Make material
                Material material = MakeBillboardMaterial(renderMode);

                // Enable emission
                ToggleEmission(material, importedTextures.IsEmissive |= emission != null);

                // Load texture file to get record and frame count
                string fileName    = TextureFile.IndexToFileName(archive);
                var    textureFile = new TextureFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, fileName), FileUsage.UseMemory, true);

                // Import all textures in this archive
                importedTextures.Albedo       = new Texture2D[textureFile.RecordCount][];
                importedTextures.EmissionMaps = importedTextures.IsEmissive ? new Texture2D[textureFile.RecordCount][] : null;
                for (int record = 0; record < textureFile.RecordCount; record++)
                {
                    int frames            = textureFile.GetFrameCount(record);
                    var frameTextures     = new Texture2D[frames];
                    var frameEmissionMaps = importedTextures.IsEmissive ? new Texture2D[frames] : null;

                    for (int frame = 0; frame < frames; frame++)
                    {
                        if (record != 0 || frame != 0)
                        {
                            LoadFromCacheOrImport(archive, record, frame, importedTextures.IsEmissive, true, out tex, out emission);
                        }

                        frameTextures[frame] = tex ?? ImageReader.GetTexture(fileName, record, frame, true);
                        if (frameEmissionMaps != null)
                        {
                            frameEmissionMaps[frame] = emission ?? frameTextures[frame];
                        }
                    }

                    importedTextures.Albedo[record] = frameTextures;
                    if (importedTextures.EmissionMaps != null)
                    {
                        importedTextures.EmissionMaps[record] = frameEmissionMaps;
                    }
                }

                // Update UV map
                SetUv(meshFilter);

                return(material);
            }

            return(null);
        }
        /// <summary>
        /// Import textures for all records and frames of a mobile billboard.
        /// </summary>
        public static void SetMobileBillboardImportedTextures(int archive, MeshFilter meshFilter, ref MobileBillboardImportedTextures importedTextures)
        {
            if (!DaggerfallUnity.Settings.AssetInjection)
            {
                return;
            }

            // Check first texture.
            Texture2D tex;
            bool      hasImportedTextures = LoadFromCacheOrImport(archive, 0, 0, out tex);

            if (importedTextures.HasImportedTextures = hasImportedTextures)
            {
                string fileName    = TextureFile.IndexToFileName(archive);
                var    textureFile = new TextureFile(Path.Combine(DaggerfallUnity.Instance.Arena2Path, fileName), FileUsage.UseMemory, true);

                // Import all textures in this archive
                var textures = new List <List <Texture2D> >();
                for (int record = 0; record < textureFile.RecordCount; record++)
                {
                    int frames        = textureFile.GetFrameCount(record);
                    var frameTextures = new List <Texture2D>();
                    for (int frame = 0; frame < frames; frame++)
                    {
                        if ((record != 0 || frame != 0) && !LoadFromCacheOrImport(archive, record, frame, out tex))
                        {
                            Debug.LogErrorFormat("Imported archive {0} does not contain texture for record {1}, frame {2}!", archive, record, frame);
                            tex = ImageReader.GetTexture(fileName, record, frame, true);
                        }
                        frameTextures.Add(tex);
                    }
                    textures.Add(frameTextures);
                }

                // Update UV map
                SetUv(meshFilter);

                // Save results
                importedTextures.Textures = textures;
            }
        }