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
|
namespace ImageProcessingGraph.Editor.Nodes.Output
|
||||||
{
|
{
|
||||||
[NodeInfo("Texture Export", "Export/Export Texture", true)]
|
[NodeInfo("Texture Export", "Export/Texture Export", true)]
|
||||||
public class Texture2DOutput : BaseImageNode
|
public class Texture2DOutput : BaseImageNode
|
||||||
{
|
{
|
||||||
[NodeAttributes.Input("")] public ImageData inputPixels;
|
[NodeAttributes.Input("")] public ImageData inputPixels;
|
||||||
[NodeAttributes.Input("File Name")] public string fileName;
|
[NodeAttributes.Input("File Name")] public string fileName;
|
||||||
[NodeAttributes.Input("File Path")] public string fileDirectory;
|
[NodeAttributes.Input("File Directory")] public string fileDirectory;
|
||||||
|
|
||||||
public enum ExportType
|
public enum ExportType
|
||||||
{
|
{
|
||||||
@ -20,16 +20,36 @@ namespace ImageProcessingGraph.Editor.Nodes.Output
|
|||||||
}
|
}
|
||||||
|
|
||||||
[NodeAttributes.Input("Export Type")] public ExportType exportType;
|
[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()
|
public override void Process()
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (exportType)
|
switch (exportType)
|
||||||
{
|
{
|
||||||
case ExportType.Texture2D:
|
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;
|
break;
|
||||||
case ExportType.PNG:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
|||||||
public ImageData textureOutput;
|
public ImageData textureOutput;
|
||||||
[NodeAttributes.Output("File Name")]
|
[NodeAttributes.Output("File Name")]
|
||||||
public string fileName;
|
public string fileName;
|
||||||
[NodeAttributes.Output("File Path")]
|
[NodeAttributes.Output("File Directory")]
|
||||||
public string filePath;
|
public string filePath;
|
||||||
|
|
||||||
public override void Process()
|
public override void Process()
|
||||||
@ -42,8 +42,8 @@ namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
|||||||
this.fileName = textureImport.name;
|
this.fileName = textureImport.name;
|
||||||
this.filePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(textureImport));
|
this.filePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(textureImport));
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
Debug.LogError("UH!");
|
// Debug.LogError("UH!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user