Exemple #1
0
        private static bool GenerateIcon(GenerateIconsWithMipLevels.InputData inputData, string baseName, List <string> assetPathsOfAllIcons, Dictionary <int, Texture2D> mipTextures, FileInfo sourceFileInfo)
        {
            string text = inputData.targetFolder + "/" + baseName + " Icon.asset";
            bool   result;

            if (sourceFileInfo != null && File.Exists(text))
            {
                FileInfo fileInfo = new FileInfo(text);
                if (fileInfo.LastWriteTime > sourceFileInfo.LastWriteTime)
                {
                    result = false;
                    return(result);
                }
            }
            Debug.Log("Generating MIP levels for " + text);
            GenerateIconsWithMipLevels.EnsureFolderIsCreatedRecursively(Path.GetDirectoryName(text));
            Texture2D texture2D = GenerateIconsWithMipLevels.CreateIconWithMipLevels(inputData, baseName, assetPathsOfAllIcons, mipTextures);

            if (texture2D == null)
            {
                Debug.Log("CreateIconWithMipLevels failed");
                result = false;
            }
            else
            {
                texture2D.name = baseName + " Icon.png";
                AssetDatabase.CreateAsset(texture2D, text);
                inputData.generatedFileNames.Add(text);
                result = true;
            }
            return(result);
        }
Exemple #2
0
        public static void GenerateAllIconsWithMipLevels()
        {
            GenerateIconsWithMipLevels.InputData inputData = GenerateIconsWithMipLevels.GetInputData();
            GenerateIconsWithMipLevels.EnsureFolderIsCreated(inputData.targetFolder);
            float realtimeSinceStartup = Time.realtimeSinceStartup;

            GenerateIconsWithMipLevels.GenerateIconsWithMips(inputData);
            Debug.Log(string.Format("Generated {0} icons with mip levels in {1} seconds", inputData.generatedFileNames.Count, Time.realtimeSinceStartup - realtimeSinceStartup));
            GenerateIconsWithMipLevels.RemoveUnusedFiles(inputData.generatedFileNames);
            AssetDatabase.Refresh();
            InternalEditorUtility.RepaintAllViews();
        }
Exemple #3
0
        private static string[] GetBaseNames(GenerateIconsWithMipLevels.InputData inputData, List <string> files)
        {
            string[] array  = new string[files.Count];
            int      length = inputData.sourceFolder.Length;

            for (int i = 0; i < files.Count; i++)
            {
                array[i] = files[i].Substring(length, files[i].IndexOf(inputData.mipIdentifier) - length);
            }
            HashSet <string> hashSet = new HashSet <string>(array);

            array = new string[hashSet.Count];
            hashSet.CopyTo(array);
            return(array);
        }
Exemple #4
0
        private static void GenerateIconsWithMips(GenerateIconsWithMipLevels.InputData inputData)
        {
            List <string> iconAssetPaths = GenerateIconsWithMipLevels.GetIconAssetPaths(inputData.sourceFolder, inputData.mipIdentifier, inputData.mipFileExtension);

            if (iconAssetPaths.Count == 0)
            {
                Debug.LogWarning("No mip files found for generating icons! Searching in: " + inputData.sourceFolder + ", for files with extension: " + inputData.mipFileExtension);
            }
            string[] baseNames = GenerateIconsWithMipLevels.GetBaseNames(inputData, iconAssetPaths);
            string[] array     = baseNames;
            for (int i = 0; i < array.Length; i++)
            {
                string baseName = array[i];
                GenerateIconsWithMipLevels.GenerateIcon(inputData, baseName, iconAssetPaths, null, null);
            }
        }
Exemple #5
0
 public static void GenerateIconWithMipLevels(string assetPath, Dictionary <int, Texture2D> mipTextures, FileInfo fileInfo)
 {
     if (GenerateIconsWithMipLevels.VerifyIconPath(assetPath, true))
     {
         GenerateIconsWithMipLevels.InputData inputData = GenerateIconsWithMipLevels.GetInputData();
         float  realtimeSinceStartup = Time.realtimeSinceStartup;
         string text = assetPath.Replace(inputData.sourceFolder, "");
         text = text.Substring(0, text.LastIndexOf(inputData.mipIdentifier));
         List <string> iconAssetPaths = GenerateIconsWithMipLevels.GetIconAssetPaths(inputData.sourceFolder, inputData.mipIdentifier, inputData.mipFileExtension);
         GenerateIconsWithMipLevels.EnsureFolderIsCreated(inputData.targetFolder);
         if (GenerateIconsWithMipLevels.GenerateIcon(inputData, text, iconAssetPaths, mipTextures, fileInfo))
         {
             Debug.Log(string.Format("Generated {0} icon with mip levels in {1} seconds", text, Time.realtimeSinceStartup - realtimeSinceStartup));
         }
         InternalEditorUtility.RepaintAllViews();
     }
 }
Exemple #6
0
 public static void GenerateSelectedIconsWithMips()
 {
     if (Selection.activeInstanceID == 0)
     {
         Debug.Log("Ensure to select a mip texture..." + Selection.activeInstanceID);
     }
     else
     {
         GenerateIconsWithMipLevels.InputData inputData = GenerateIconsWithMipLevels.GetInputData();
         int    activeInstanceID = Selection.activeInstanceID;
         string assetPath        = AssetDatabase.GetAssetPath(activeInstanceID);
         if (GenerateIconsWithMipLevels.VerifyIconPath(assetPath, true))
         {
             float  realtimeSinceStartup = Time.realtimeSinceStartup;
             string text = assetPath.Replace(inputData.sourceFolder, "");
             text = text.Substring(0, text.LastIndexOf(inputData.mipIdentifier));
             List <string> iconAssetPaths = GenerateIconsWithMipLevels.GetIconAssetPaths(inputData.sourceFolder, inputData.mipIdentifier, inputData.mipFileExtension);
             GenerateIconsWithMipLevels.EnsureFolderIsCreated(inputData.targetFolder);
             GenerateIconsWithMipLevels.GenerateIcon(inputData, text, iconAssetPaths, null, null);
             Debug.Log(string.Format("Generated {0} icon with mip levels in {1} seconds", text, Time.realtimeSinceStartup - realtimeSinceStartup));
             InternalEditorUtility.RepaintAllViews();
         }
     }
 }
Exemple #7
0
        private static Texture2D CreateIconWithMipLevels(GenerateIconsWithMipLevels.InputData inputData, string baseName, List <string> assetPathsOfAllIcons, Dictionary <int, Texture2D> mipTextures)
        {
            List <string>    list  = assetPathsOfAllIcons.FindAll((string o) => o.IndexOf('/' + baseName + inputData.mipIdentifier) >= 0);
            List <Texture2D> list2 = new List <Texture2D>();

            foreach (string current in list)
            {
                int       key = GenerateIconsWithMipLevels.MipLevelForAssetPath(current, inputData.mipIdentifier);
                Texture2D texture2D;
                if (mipTextures != null && mipTextures.ContainsKey(key))
                {
                    texture2D = mipTextures[key];
                }
                else
                {
                    texture2D = GenerateIconsWithMipLevels.GetTexture2D(current);
                }
                if (texture2D != null)
                {
                    list2.Add(texture2D);
                }
                else
                {
                    Debug.LogError("Mip not found " + current);
                }
            }
            list2.Sort(delegate(Texture2D first, Texture2D second)
            {
                int result2;
                if (first.width == second.width)
                {
                    result2 = 0;
                }
                else if (first.width < second.width)
                {
                    result2 = 1;
                }
                else
                {
                    result2 = -1;
                }
                return(result2);
            });
            int num  = 99999;
            int num2 = 0;

            foreach (Texture2D current2 in list2)
            {
                int width = current2.width;
                if (width > num2)
                {
                    num2 = width;
                }
                if (width < num)
                {
                    num = width;
                }
            }
            Texture2D result;

            if (num2 == 0)
            {
                result = null;
            }
            else
            {
                Texture2D texture2D2 = new Texture2D(num2, num2, TextureFormat.RGBA32, true, false);
                if (GenerateIconsWithMipLevels.BlitMip(texture2D2, list2, 0))
                {
                    texture2D2.Apply(true);
                    int num3 = num2;
                    for (int i = 1; i < texture2D2.mipmapCount; i++)
                    {
                        num3 /= 2;
                        if (num3 < num)
                        {
                            break;
                        }
                        GenerateIconsWithMipLevels.BlitMip(texture2D2, list2, i);
                    }
                    texture2D2.Apply(false, true);
                    result = texture2D2;
                }
                else
                {
                    result = texture2D2;
                }
            }
            return(result);
        }