示例#1
0
        /// <summary>
        /// Get a safe size for a control based on resolution of img.
        /// </summary>
        public static Vector2 GetSize(Texture2D texture, string textureName, bool allowXml = false)
        {
            if (!DaggerfallUnity.Settings.MeshAndTextureReplacement)
            {
                return(new Vector2(texture.width, texture.height));
            }

            if (allowXml)
            {
                // Get size from xml
                string path = Path.Combine(imgPath, textureName);
                if (XMLManager.XmlFileExists(path))
                {
                    var     xml = new XMLManager(path);
                    Vector2 size;
                    if (xml.TryGetVector2("width", "height", out size))
                    {
                        return(size);
                    }
                }
            }

            // Get size from Daggerfall image
            ImageData imageData = ImageReader.GetImageData(textureName, createTexture: false);

            return(new Vector2(imageData.width, imageData.height));
        }
示例#2
0
        /// <summary>
        /// Get a safe size for a control based on resolution of img.
        /// </summary>
        public static Vector2 GetSize(Texture2D texture, string textureName, bool allowXml = false)
        {
            if (allowXml)
            {
                // Get size from xml
                string path = Path.Combine(imgPath, textureName);
                if (XMLManager.XmlFileExists(path))
                {
                    var     xml = new XMLManager(path);
                    Vector2 size;
                    if (xml.TryGetVector2("width", "height", out size))
                    {
                        return(size);
                    }
                }
            }

            // Get size from vanilla image
            if (CustomImageExist(textureName))
            {
                ImageData imageData = ImageReader.GetImageData(textureName, createTexture: false);
                return(new Vector2(imageData.width, imageData.height));
            }

            // Get size from texture
            return(new Vector2(texture.width, texture.height));
        }
示例#3
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);
        }