예제 #1
0
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            for (int a = 0; a < importedAssets.Length; ++a)
            {
                string imagePath = importedAssets[a];
                string ext       = Path.GetExtension(imagePath).ToLowerInvariant();

                //images with the ignore string in their filename will not be imported
                string name = Path.GetFileNameWithoutExtension(imagePath).ToLowerInvariant();
                if (name.Contains("_noimport"))
                {
                    continue;
                }

                HDRProcessor.ImageReader readImage = null;
                ext = ext.ToLowerInvariant();
                if (ext.Equals(".pfm") || ext.Equals(".pbm"))
                {
                    readImage = readPFM;
                }
                else if (ext.Equals(".hdr") || ext.Equals(".rgbe") || ext.Equals(".xyze"))
                {
                    readImage = readHDR;
                }

                if (readImage != null)
                {
                    string    texPath = Path.ChangeExtension(imagePath, ".png");
                    Texture2D tex     = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D;
                    if (!tex)
                    {
                        tex = new Texture2D(32, 32);
                        AssetDatabase.CreateAsset(tex, texPath);
                    }
                    SerializedObject srTex = new SerializedObject(tex);
                    Util.setReadable(ref srTex, true);
                    if (readImage(ref tex, imagePath))
                    {
                        Util.writePNG(ref tex, texPath);
                        AssetDatabase.Refresh();
                        AssetDatabase.SaveAssets();
                    }
                    else
                    {
                        Debug.LogError("Failed to import custom image file.");
                        AssetDatabase.DeleteAsset(texPath);
                    }
                }
            }
        }
예제 #2
0
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            //sanity check
            if (RGBMList.Count > 1000)
            {
                Debug.LogWarning("HDR Processor did not get to fixing all imported RGBM files. " + RGBMList.Count + " files missed.");
                RGBMList.Clear();
            }
            for (int a = 0; a < importedAssets.Length; ++a)
            {
                string imagePath = importedAssets[a];
                string ext       = Path.GetExtension(imagePath).ToLowerInvariant();

                //images with the ignore string in their filename will not be imported
                string name = Path.GetFileNameWithoutExtension(imagePath).ToLowerInvariant();
                if (name.Contains("_noimport"))
                {
                    continue;
                }

                HDRProcessor.ImageReader readImage = null;
                ext = ext.ToLowerInvariant();
                if (ext.Equals(".pfm") || ext.Equals(".pbm"))
                {
                    readImage = readPFM;
                }
                else if (ext.Equals(".hdr") || ext.Equals(".rgbe") || ext.Equals(".xyze"))
                {
                    readImage = readHDR;
                }

                if (readImage != null)
                {
                    string texPath = Path.ChangeExtension(imagePath, ".png");

                    //mark this file as needing some RGBM post-processing
                    int hash = texPath.GetHashCode();
                    if (!RGBMList.Contains(hash))
                    {
                        RGBMList.Add(hash);
                    }

                    Texture2D tex = AssetDatabase.LoadAssetAtPath(texPath, typeof(Texture2D)) as Texture2D;
                    if (!tex)
                    {
                        tex = new Texture2D(32, 32);
                        AssetDatabase.CreateAsset(tex, texPath);
                    }

                    SerializedObject srTex = new SerializedObject(tex);
                    mset.Util.setReadable(srTex, true);
                    if (readImage(ref tex, imagePath))
                    {
                        mset.Util.writePNG(ref tex, texPath);
                        AssetDatabase.Refresh();
                        AssetDatabase.SaveAssets();
                    }
                    else
                    {
                        Debug.LogError("Failed to import custom image file \"" + imagePath + "\"");
                        AssetDatabase.DeleteAsset(texPath);
                    }
                }
            }
        }