Updated Texture2D import and export
This commit is contained in:
parent
4cd9878a97
commit
a3d79f09b2
@ -6,12 +6,12 @@ using UnityEngine;
|
||||
|
||||
namespace ImageProcessingGraph.Editor.Nodes.Output
|
||||
{
|
||||
[NodeInfo("Texture Export", "Export/Export Texture", true)]
|
||||
[NodeInfo("Texture Export", "Export/Texture Export", true)]
|
||||
public class Texture2DOutput : BaseImageNode
|
||||
{
|
||||
[NodeAttributes.Input("")] public ImageData inputPixels;
|
||||
[NodeAttributes.Input("File Name")] public string fileName;
|
||||
[NodeAttributes.Input("File Path")] public string fileDirectory;
|
||||
[NodeAttributes.Input("File Directory")] public string fileDirectory;
|
||||
|
||||
public enum ExportType
|
||||
{
|
||||
@ -20,16 +20,36 @@ namespace ImageProcessingGraph.Editor.Nodes.Output
|
||||
}
|
||||
|
||||
[NodeAttributes.Input("Export Type")] public ExportType exportType;
|
||||
[NodeAttributes.Input("Texture Type")] public TextureImporterType textureType;
|
||||
|
||||
[NodeAttributes.Output("Output Texture")] public Texture2D textureOutput;
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
|
||||
switch (exportType)
|
||||
{
|
||||
case ExportType.Texture2D:
|
||||
AssetDatabase.CreateAsset(inputPixels.ToTexture2D(), $"{fileDirectory}/{fileName}.asset");
|
||||
string pathT2D = $"{fileDirectory}/{fileName}.asset";
|
||||
AssetDatabase.CreateAsset(inputPixels.ToTexture2D(), pathT2D);
|
||||
textureOutput = AssetDatabase.LoadAssetAtPath<Texture2D>(pathT2D);
|
||||
break;
|
||||
case ExportType.PNG:
|
||||
inputPixels.ExportPNG($"{fileDirectory}/{fileName}.png");
|
||||
string pathPNG = $"{fileDirectory}/{fileName}.png";
|
||||
inputPixels.ExportPNG(pathPNG);
|
||||
|
||||
AssetDatabase.ImportAsset(pathPNG);
|
||||
|
||||
TextureImporter textureImporter = AssetImporter.GetAtPath(pathPNG) as TextureImporter;
|
||||
if (textureImporter != null)
|
||||
{
|
||||
textureImporter.textureType = textureType;
|
||||
EditorUtility.SetDirty(AssetDatabase.LoadAssetAtPath<Texture2D>(pathPNG));
|
||||
textureImporter.SaveAndReimport();
|
||||
}
|
||||
AssetDatabase.ImportAsset(pathPNG);
|
||||
|
||||
textureOutput = AssetDatabase.LoadAssetAtPath<Texture2D>(pathPNG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
||||
public ImageData textureOutput;
|
||||
[NodeAttributes.Output("File Name")]
|
||||
public string fileName;
|
||||
[NodeAttributes.Output("File Path")]
|
||||
[NodeAttributes.Output("File Directory")]
|
||||
public string filePath;
|
||||
|
||||
public override void Process()
|
||||
@ -42,8 +42,8 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
||||
this.fileName = textureImport.name;
|
||||
this.filePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(textureImport));
|
||||
}
|
||||
else
|
||||
Debug.LogError("UH!");
|
||||
// else
|
||||
// Debug.LogError("UH!");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user