示例#1
0
        string SaveTextureAsset(Texture2D texture, bool isHdr)
        {
#if UNITY_EDITOR
            string dataPath = WG_Helper.RemoveFirstFolderFromPath(textureAssetFolder) + "lightmap_" + texture.GetInstanceID().ToString() + (isHdr ? ".exr" : ".png");
            string filePath = Application.dataPath + "/" + dataPath;
            if (isHdr)
            {
                //Debug.Log("Save exr " + filePath);
                //Debug.Log("center pixel: " + texture.GetPixel(texture.width / 2, texture.height / 2).ToString());
                byte[] _bytes = texture.EncodeToEXR();
                File.WriteAllBytes(filePath, _bytes);
                AssetDatabase.ImportAsset("Assets/" + dataPath, ImportAssetOptions.ForceUpdate);
                return("Assets/" + dataPath);
            }
            else
            {
                byte[] _bytes = texture.EncodeToPNG();
                File.WriteAllBytes(filePath, _bytes);
                AssetDatabase.ImportAsset("Assets/" + dataPath, ImportAssetOptions.ForceUpdate);
                return("Assets/" + dataPath);
            }
            #else
            return("");
            #endif
        }
示例#2
0
 string SaveMinimapAsset(Texture2D texture)
 {
     #if UNITY_EDITOR
     byte[] _bytes   = texture.EncodeToPNG();
     string dataPath = WG_Helper.RemoveFirstFolderFromPath(minimapAssetFolder) + texture.name + ".png";
     string filePath = Application.dataPath + "/" + dataPath;
     File.WriteAllBytes(filePath, _bytes);
     string assetPath = "Assets/" + dataPath;
     AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
     return(assetPath);
     #else
     return("");
     #endif
 }