private static string CloneAndResizeToFile(PlayerSettings.WSAImageType type, PlayerSettings.WSAImageScale scale)
        {
            string texturePath = GetUWPImageTypeTexture(type, scale);

            if (string.IsNullOrEmpty(texturePath))
            {
                return(string.Empty);
            }

            var iconSize = GetUWPImageTypeSize(type, scale);

            if (iconSize == Vector2.zero)
            {
                return(string.Empty);
            }

            if (iconSize.x == 1240 && iconSize.y == 1240 || iconSize.x == 2480 && iconSize.y == 1200)
            {
                return(texturePath);
            }

            string filePath = string.Format("{0}/{1}_{2}x{3}.png", _outputDirectoryName, type.ToString(), iconSize.x, iconSize.y);

            filePath = filePath.Replace(Application.dataPath, "Assets");

            // Create copy of original image
            try
            {
                AssetDatabase.CopyAsset(texturePath, filePath);
                var clone = AssetDatabase.LoadAssetAtPath <Texture2D>(filePath);

                if (clone == null)
                {
                    Debug.LogError("Unable to load texture at " + filePath);
                    return(string.Empty);
                }

                // Resize clone to desired size
                TextureScale.Bilinear(clone, (int)iconSize.x, (int)iconSize.y);
                clone.Compress(true);
                AssetDatabase.SaveAssets();

                if (clone.GetRawTextureData().Length > 204800)
                {
                    Debug.LogWarningFormat("{0} exceeds the minimum file size of 204,800 bytes, please use a smaller image for generating your icons.", clone.name);
                    return(string.Empty);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                return(string.Empty);
            }

            return(filePath);
        }
예제 #2
0
        private Texture2D CloneAndResizeToTexture(Texture2D texture, Vector2 iconSize)
        {
            // Create copy of original image
            var clone = Instantiate(texture);

            // Resize clone to desired size
            TextureScale.Bilinear(clone, (int)iconSize.x, (int)iconSize.y);

            return(clone);
        }
예제 #3
0
        private static string CloneAndResizeToFile(PlayerSettings.WSAImageType type, PlayerSettings.WSAImageScale scale)
        {
            string texturePath = GetUWPImageTypeTexture(type, scale);

            if (string.IsNullOrEmpty(texturePath))
            {
                return(string.Empty);
            }

            var iconSize = GetUWPImageTypeSize(type, scale);

            if (iconSize == Vector2.zero)
            {
                return(string.Empty);
            }

            if (iconSize.x == 1240 && iconSize.y == 1240 || iconSize.x == 2480 && iconSize.y == 1200)
            {
                return(texturePath);
            }

            string filePath = string.Format("{0}/{1}_AppIcon_{2}x{3}.png", _outputDirectoryName, Application.productName, iconSize.x, iconSize.y);

            filePath = filePath.Replace(Application.dataPath, "Assets");

            if (File.Exists(filePath))
            {
                return(filePath);
            }

            // Create copy of original image
            try
            {
                AssetDatabase.CopyAsset(texturePath, filePath);
                var clone = AssetDatabase.LoadAssetAtPath <Texture2D>(filePath);

                if (clone == null)
                {
                    Debug.LogError("Unable to load texture at " + filePath);
                    return(string.Empty);
                }

                // Resize clone to desired size
                TextureScale.Bilinear(clone, (int)iconSize.x, (int)iconSize.y);

                // Crop
                Color[] pix = clone.GetPixels(0, 0, (int)iconSize.x, (int)iconSize.y);
                clone = new Texture2D((int)iconSize.x, (int)iconSize.y, TextureFormat.ARGB32, false);
                clone.SetPixels(pix);
                clone.Apply();

                var rawData = clone.EncodeToPNG();
                File.WriteAllBytes(filePath, rawData);

                if (rawData.Length > 204800)
                {
                    Debug.LogWarningFormat("{0} exceeds the minimum file size of 204,800 bytes, please use a smaller image for generating your icons.", filePath);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                return(string.Empty);
            }

            return(filePath);
        }