Example #1
0
        public static void SetEnemyScale(int archive, int record, ref Vector2 size)
        {
            string path = Path.Combine(texturesPath, GetName(archive, record));

            if (!XMLManager.XmlFileExists(path))
            {
                return;
            }

            var     xml   = new XMLManager(path);
            Vector2 scale = xml.GetVector2("scaleX", "scaleY", Vector2.zero);

            size.x *= scale.x;
            size.y *= scale.y;
        }
Example #2
0
        /// <summary>
        /// Read size associated with a texture from xml.
        /// </summary>
        public static bool TryGetSize(string textureName, out Vector2 size)
        {
            if (DaggerfallUnity.Settings.MeshAndTextureReplacement)
            {
                string path = Path.Combine(texturesPath, textureName);
                if (XMLManager.XmlFileExists(path))
                {
                    var xml = new XMLManager(path);
                    if (xml.TryGetVector2("width", "height", out size))
                    {
                        return(true);
                    }
                }
            }

            size = new Vector2();
            return(false);
        }
        /// <summary>
        /// Import additional custom components of material.
        /// </summary>
        /// <param name="archive">Archive index</param>
        /// <param name="record">Record index</param>
        /// <param name="frame">Texture frame</param>
        /// <param name="material">Material.</param>
        public static void CustomizeMaterial(int archive, int record, int frame, Material material)
        {
            // MetallicGloss map
            Texture2D metallicGloss;

            if (TryImportTextureFromLooseFiles(archive, record, frame, TextureMap.MetallicGloss, true, out metallicGloss))
            {
                metallicGloss.filterMode = MainFilterMode;
                material.EnableKeyword(KeyWords.MetallicGlossMap);
                material.SetTexture(Uniforms.MetallicGlossMap, metallicGloss);
            }

            // Height Map
            Texture2D height;

            if (TryImportTextureFromLooseFiles(archive, record, frame, TextureMap.Height, true, out height))
            {
                height.filterMode = MainFilterMode;
                material.EnableKeyword(KeyWords.HeightMap);
                material.SetTexture(Uniforms.HeightMap, height);
            }

            // Properties
            string path = Path.Combine(texturesPath, GetName(archive, record, frame));

            if (XMLManager.XmlFileExists(path))
            {
                var xml = new XMLManager(path);

                // Metallic parameter
                float metallic;
                if (xml.TryGetFloat("metallic", out metallic))
                {
                    material.SetFloat(Uniforms.Metallic, metallic);
                }

                // Smoothness parameter
                float smoothness;
                if (xml.TryGetFloat("smoothness", out smoothness))
                {
                    material.SetFloat(Uniforms.Glossiness, smoothness);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Import custom texture and label settings for buttons
        /// </summary>
        /// <param name="button">Button</param>
        /// <param name="colorName">Name of texture</param>
        static public bool TryCustomizeButton(ref Button button, string colorName)
        {
            Texture2D tex;

            if (!TryImportTexture(colorName, out tex))
            {
                return(false);
            }

            // Load texture
            button.BackgroundTexture            = tex;
            button.BackgroundTexture.filterMode = (FilterMode)DaggerfallUnity.Settings.GUIFilterMode;

            // Load settings from Xml
            string path = Path.Combine(texturesPath, colorName);

            if (XMLManager.XmlFileExists(path))
            {
                var xml = new XMLManager(path);

                string value;
                if (xml.TryGetString("customtext", out value))
                {
                    if (value == "true") // Set custom color for text
                    {
                        button.Label.TextColor = xml.GetColor(button.Label.TextColor);
                    }
                    else if (value == "notext") // Disable text. This is useful if text is drawn on texture
                    {
                        button.Label.Text = string.Empty;
                    }
                }
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Set custom material on billboard gameobject.
        /// </summary>
        /// <paran name="go">Billboard gameobject.</param>
        /// <param name="archive">Archive index.</param>
        /// <param name="record">Record index.</param>
        static public void SetBillboardCustomMaterial(GameObject go, ref DaggerfallBillboard.BillboardSummary summary)
        {
            // Variables
            int numberOfFrames;
            int archive = summary.Archive;
            int record  = summary.Record;
            //string name = GetName(archive, record);
            var       meshRenderer = go.GetComponent <MeshRenderer>();
            Texture2D albedoTexture, emissionMap;

            // Check if billboard is emissive
            bool isEmissive = meshRenderer.material.GetTexture("_EmissionMap");

            // UVs
            Vector2 uv = Vector2.zero;

            // Get properties from Xml
            string path = Path.Combine(texturesPath, GetName(archive, record));

            if (XMLManager.XmlFileExists(path))
            {
                var xml = new XMLManager(path);

                // Set billboard scale
                Transform transform = go.GetComponent <Transform>();
                transform.localScale = xml.GetVector3("scaleX", "scaleY", transform.localScale);
                summary.Size.x      *= transform.localScale.x;
                summary.Size.y      *= transform.localScale.y;

                // Get UV
                uv = xml.GetVector2("uvX", "uvY", uv);
            }

            // Update UV
            SetUv(go.GetComponent <MeshFilter>(), uv.x, uv.y);

            // Get material from cache or import from disk
            MaterialReader materialReader = DaggerfallUnity.Instance.MaterialReader;
            CachedMaterial cachedMaterialOut;

            if (materialReader.GetCachedMaterialCustomBillboard(archive, record, 0, out cachedMaterialOut))
            {
                // Get and set material
                meshRenderer.material = cachedMaterialOut.material;

                // Get other properties
                numberOfFrames = cachedMaterialOut.singleFrameCount;
                albedoTexture  = cachedMaterialOut.albedoMap;
                emissionMap    = cachedMaterialOut.emissionMap;
            }
            else
            {
                // Get textures from disk
                LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record);

                // Main texture
                meshRenderer.material.SetTexture("_MainTex", albedoTexture);

                // Emission maps for lights
                if (isEmissive)
                {
                    meshRenderer.material.SetTexture("_EmissionMap", emissionMap);
                }

                // Get number of frames on disk
                numberOfFrames = NumberOfAvailableFrames(archive, record);

                // Save material in cache
                CachedMaterial newcm = new CachedMaterial()
                {
                    albedoMap        = albedoTexture,
                    emissionMap      = emissionMap,
                    material         = meshRenderer.material,
                    singleFrameCount = numberOfFrames
                };
                materialReader.SetCachedMaterialCustomBillboard(archive, record, 0, newcm);
            }

            // Import textures for each frame if billboard is animated
            summary.CustomBillboard = new CustomBillboard();
            summary.CustomBillboard.isCustomAnimated = numberOfFrames > 1;
            if (summary.CustomBillboard.isCustomAnimated)
            {
                List <Texture2D> albedoTextures = new List <Texture2D>();
                List <Texture2D> emissionmaps   = new List <Texture2D>();

                // Frame zero
                albedoTextures.Add(albedoTexture);
                if (isEmissive)
                {
                    emissionmaps.Add(emissionMap);
                }

                // Other frames
                for (int frame = 1; frame < numberOfFrames; frame++)
                {
                    if (materialReader.GetCachedMaterialCustomBillboard(archive, record, frame, out cachedMaterialOut))
                    {
                        // Get textures from cache
                        albedoTexture = cachedMaterialOut.albedoMap;
                        emissionMap   = cachedMaterialOut.emissionMap;
                    }
                    else
                    {
                        // Get textures from disk
                        LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record, frame);

                        // Save textures in cache
                        CachedMaterial newcm = new CachedMaterial()
                        {
                            albedoMap   = albedoTexture,
                            emissionMap = emissionMap,
                        };
                        materialReader.SetCachedMaterialCustomBillboard(archive, record, frame, newcm);
                    }

                    albedoTextures.Add(albedoTexture);
                    if (isEmissive)
                    {
                        emissionmaps.Add(emissionMap);
                    }
                }

                // Set textures and properties
                summary.CustomBillboard.MainTexture    = albedoTextures;
                summary.CustomBillboard.EmissionMap    = emissionmaps;
                summary.CustomBillboard.NumberOfFrames = numberOfFrames;
                summary.CustomBillboard.isEmissive     = isEmissive;
            }
        }