diff --git a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs index b009911..7c1e3e9 100644 --- a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs +++ b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs @@ -5,6 +5,7 @@ using UnityEditor.Callbacks; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using ImageProcessingGraph.Editor.Nodes.Types.Image.Variable_Node; using UnityEditor.Experimental.GraphView; using Debug = UnityEngine.Debug; @@ -47,6 +48,8 @@ namespace ImageProcessingGraph.Editor public void RunGraph() { + + var bleh = GetAllVariableNodesWithTypes(); OnRun?.Invoke(); // Create and start the stopwatch to measure time @@ -72,7 +75,6 @@ namespace ImageProcessingGraph.Editor failed = true; } - // Stop the stopwatch after running the nodes stopwatch.Stop(); // Log the elapsed time @@ -81,6 +83,30 @@ namespace ImageProcessingGraph.Editor AssetDatabase.Refresh(); } + public List<(BaseImageNode node, System.Type type)> GetAllVariableNodesWithTypes() + { + var result = new List<(BaseImageNode node, System.Type type)>(); + + foreach (var node in nodes) + { + var nodeType = node.GetType(); + var baseType = nodeType.BaseType; + + if (baseType != null && baseType.IsGenericType) + { + if (baseType.GetGenericTypeDefinition() == typeof(VariableNode<>)) + { + var genericArgument = baseType.GetGenericArguments()[0]; + result.Add((node, genericArgument)); + } + } + } + + return result; + } + + + /// /// Computes a topological execution order of nodes based on their dependencies. diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes.meta b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes.meta new file mode 100644 index 0000000..3ea4978 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fd58cf45d01e429abcb9b8f4e3894b7a +timeCreated: 1746240608 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs new file mode 100644 index 0000000..eee3e8a --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs @@ -0,0 +1,43 @@ +using System.IO; +using ImageProcessingGraph.Editor.Nodes.NodeAttributes; +using UnityEditor; +using UnityEngine; + +namespace ImageProcessingGraph.Editor.Nodes.Types.Image.From_Path_Nodes +{ + public class FromPathNode : BaseImageNode where T : UnityEngine.Object + { + [NodeAttributes.Input("Path")] public string path; + [NodeAttributes.Output("Output")] public T output; + + public override void Process() + { + if (string.IsNullOrEmpty(path)) + { + throw new System.ArgumentException("Path is empty or null. Cannot load asset."); + } + + output = AssetDatabase.LoadAssetAtPath(path); + + if (output == null) + { + throw new System.Exception($"Failed to load asset of type {typeof(T)} at path: {path}."); + } + } + + public override void CleanUp() + { + output = null; + path = null; + } + } + + [NodeInfo("Load Texture2D From path", "Load From Path/Texture2D")] + public class Texture2DFromPath : FromPathNode { } + + [NodeInfo("Load Mesh From path", "Load From Path/Mesh")] + public class MeshFromPath : FromPathNode { } + + [NodeInfo("Load Prefab From path", "Load From Path/Prefab")] + public class PrefabFromPath : FromPathNode { } +} \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs.meta b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs.meta new file mode 100644 index 0000000..b5bd81e --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/From Path Nodes/FromPathNode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dbdf66c38fa94127a4665bf6fd1ac011 +timeCreated: 1746240631 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node.meta new file mode 100644 index 0000000..9b3cba2 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 899a77acab6b46d9af23756a397e7eea +timeCreated: 1746228396 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs new file mode 100644 index 0000000..bcea714 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs @@ -0,0 +1,34 @@ +using ImageProcessingGraph.Editor.Nodes.NodeAttributes; +using UnityEngine; + +namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Variable_Node +{ + public class VariableNode : BaseImageNode + { + public T input; + [NodeAttributes.Output("Output")] public T output; + + public override void Process() + { + if(input != null) + this.output = input; + else + throw new System.NullReferenceException($"Input to VariableNode<{typeof(T).Name}> is null"); + } + + public override void CleanUp() + { + input = default; + output = default; + } + } + + [NodeInfo("Texture2D Variable", "Variable/Texture2D")] + public class Texture2DVariableNode : VariableNode { } + + [NodeInfo("Mesh Variable", "Variable/Mesh")] + public class MeshVariableNode : VariableNode { } + + [NodeInfo("Prefab Variable", "Variable/Prefab")] + public class PrefabVariableNode : VariableNode { } +} \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs.meta new file mode 100644 index 0000000..0f4ca4d --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Variable Node/VariableNode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b10ad5cecfc74b548431deb876d3cb9a +timeCreated: 1746228592 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Windows/Documentation.meta b/Editor/Scripts/Editor/Windows/Documentation.meta new file mode 100644 index 0000000..9b2dfa5 --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 024feeef7368f444696e947391b79685 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs new file mode 100644 index 0000000..21c33d6 --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs @@ -0,0 +1,21 @@ +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; + +public class ImageProcessingGraphDocumentationWindow : EditorWindow +{ + [SerializeField] + private VisualTreeAsset m_VisualTreeAsset = default; + + [MenuItem("Window/UI Toolkit/ImageProcessingGraphDocumentationWindow")] + public static void ShowExample() + { + ImageProcessingGraphDocumentationWindow wnd = GetWindow(); + wnd.titleContent = new GUIContent("IPT Documentation"); + } + + public void CreateGUI() + { + + } +} diff --git a/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs.meta b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs.meta new file mode 100644 index 0000000..21d2bb8 --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 819da168f89268440b928bc0eb32e67e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - m_VisualTreeAsset: {fileID: 9197481963319205126, guid: 880795e34c2278d49b48c227716214de, type: 3} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss new file mode 100644 index 0000000..218263a --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss @@ -0,0 +1,5 @@ +.custom-label { + font-size: 20px; + -unity-font-style: bold; + color: rgb(68, 138, 255); +} \ No newline at end of file diff --git a/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss.meta b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss.meta new file mode 100644 index 0000000..4c24f74 --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3d894085df56784383eca98ee7c9077 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 diff --git a/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uxml b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uxml new file mode 100644 index 0000000..8a9dcdd --- /dev/null +++ b/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uxml @@ -0,0 +1,3 @@ + +