コード例 #1
0
 private async Task ExportTexture(Dictionary <string, string> data, string folder, int group, string paramname, Material mat, Material defaultMat, bool isNormalMap = false)
 {
     WorkshopItemEditor.Loading(true, string.Concat("Exporting Texture ", paramname), "", 0f);
     UnityEngine.Texture texture = mat.GetTexture(paramname);
     if (texture != defaultMat.GetTexture(paramname))
     {
         if (texture != null)
         {
             texture = Facepunch.Utility.Texture.LimitSize(texture as Texture2D, this.Skinnable.Groups[group].MaxTextureSize, this.Skinnable.Groups[group].MaxTextureSize);
             if (isNormalMap)
             {
                 texture = Facepunch.Utility.Texture.CreateReadableCopy(texture as Texture2D, 0, 0);
                 (texture as Texture2D).DecompressNormals();
             }
             string str = string.Format("{0}{1}{2}", paramname, group, ".png");
             data.Add(paramname, str);
             texture.SaveAsPng(string.Concat(folder, "/", str));
             await Task.Delay(1);
         }
         else
         {
             data.Add(paramname, "none");
         }
     }
 }
コード例 #2
0
        private IEnumerator DoSaveFile()
        {
            TextureRow textureRow = null;

            yield return(textureRow.StartCoroutine(textureRow.Editor.FileDialog.Save(null, ".png", "SAVE FILE", null, true)));

            if (string.IsNullOrEmpty(textureRow.Editor.FileDialog.result))
            {
                yield break;
            }
            UnityEngine.Debug.Log(string.Concat("Save Png to ", textureRow.Editor.FileDialog.result));
            UnityEngine.Texture targetImage = textureRow.TargetImage.texture;
            if (textureRow.IsNormalMap)
            {
                targetImage = Facepunch.Utility.Texture.CreateReadableCopy(targetImage as Texture2D, 0, 0);
                (targetImage as Texture2D).DecompressNormals();
            }
            targetImage.SaveAsPng(textureRow.Editor.FileDialog.result);
            if (textureRow.IsNormalMap)
            {
                UnityEngine.Object.Destroy(targetImage);
            }
        }