Various Fixes
This commit is contained in:
parent
499d187c96
commit
4f348fe66a
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEditor.Experimental.GraphView;
|
using UnityEditor.Experimental.GraphView;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace ImageProcessingGraph.Editor
|
namespace ImageProcessingGraph.Editor
|
||||||
@ -8,6 +9,20 @@ namespace ImageProcessingGraph.Editor
|
|||||||
public class IPTPort : Port
|
public class IPTPort : Port
|
||||||
{
|
{
|
||||||
public FieldInfo fieldInfo;
|
public FieldInfo fieldInfo;
|
||||||
|
private VisualElement _exposedPropertyContainer;
|
||||||
|
|
||||||
|
public VisualElement ExposedPropertyContainer
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Debug.Log($"🔥 Someone is SETTING ExposedPropertyContainer to {value} 🔥");
|
||||||
|
_exposedPropertyContainer = value;
|
||||||
|
}
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _exposedPropertyContainer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected IPTPort(Orientation portOrientation, Direction portDirection, Capacity portCapacity, Type type) : base(portOrientation, portDirection, portCapacity, type)
|
protected IPTPort(Orientation portOrientation, Direction portDirection, Capacity portCapacity, Type type) : base(portOrientation, portDirection, portCapacity, type)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +115,7 @@ namespace ImageProcessingGraph.Editor
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
onFailed?.Invoke();
|
onFailed?.Invoke();
|
||||||
Debug.LogError(e);
|
//Debug.LogError(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,11 @@ namespace ImageProcessingGraph.Editor
|
|||||||
this.outputPort = new GraphPort(outputNodeGuid, outputPortID, outputNodeType);
|
this.outputPort = new GraphPort(outputNodeGuid, outputPortID, outputNodeType);
|
||||||
this.internalEdge = internalEdge;
|
this.internalEdge = internalEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetInternalEdge(Edge edge)
|
||||||
|
{
|
||||||
|
this.internalEdge = edge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
|
@ -42,6 +42,8 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
{
|
{
|
||||||
window.asset.Connections.Remove(VARIABLE);
|
window.asset.Connections.Remove(VARIABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((ImageProcessingGraphNodeVisual)edge.input.node).ToggleExposedVariable((IPTPort)edge.input, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +65,8 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
window.asset.Connections.Remove(VARIABLE);
|
window.asset.Connections.Remove(VARIABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((ImageProcessingGraphNodeVisual)edge.input.node).ToggleExposedVariable((IPTPort)edge.input, true);
|
||||||
|
|
||||||
|
|
||||||
this.m_EdgesToCreate.Clear();
|
this.m_EdgesToCreate.Clear();
|
||||||
this.m_EdgesToCreate.Add(edge);
|
this.m_EdgesToCreate.Add(edge);
|
||||||
|
@ -69,6 +69,16 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
CreateInputPorts(inputFieldInfo);
|
CreateInputPorts(inputFieldInfo);
|
||||||
CreateOutputPorts(outputFieldInfo);
|
CreateOutputPorts(outputFieldInfo);
|
||||||
|
|
||||||
|
foreach (Port input in InputPorts)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Port input in OutputPorts)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
errorStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Unity Image Processing/Node.uss");
|
errorStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Unity Image Processing/Node.uss");
|
||||||
if (errorStyleSheet == null)
|
if (errorStyleSheet == null)
|
||||||
{
|
{
|
||||||
@ -129,116 +139,117 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
// Exposes a variable on the port for editing when it's not connected
|
// Exposes a variable on the port for editing when it's not connected
|
||||||
public void ExposeVariableToPort(Port port, FieldInfo field)
|
public void ExposeVariableToPort(Port port, FieldInfo field)
|
||||||
{
|
{
|
||||||
// Only expose when the port is not connected
|
var ExposedPropertyContainer = ((IPTPort)port).ExposedPropertyContainer;
|
||||||
if (port.connections.Count() == 0)
|
Type containerType = null;
|
||||||
|
|
||||||
|
if (ExposedPropertyContainer == null)
|
||||||
{
|
{
|
||||||
var propertyFieldContainer = new VisualElement();
|
var NewElement = new VisualElement();
|
||||||
propertyFieldContainer.name = "property-field-container";
|
NewElement.name = "property-field-container";
|
||||||
var propertyField = CreatePropertyFieldForType(field.FieldType, field.GetValue(graphNode));
|
VisualElement the = CreatePropertyFieldForType(field.FieldType, field.GetValue(graphNode));
|
||||||
|
|
||||||
if (propertyField != null)
|
if(the != null)
|
||||||
{
|
containerType = the.GetType();
|
||||||
// Register a callback for when the value changes
|
|
||||||
if (propertyField.GetType() == typeof(IntegerField))
|
|
||||||
{
|
|
||||||
var intField = propertyField as IntegerField;
|
|
||||||
intField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is FloatField floatField)
|
|
||||||
{
|
|
||||||
floatField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is Toggle boolField)
|
|
||||||
{
|
|
||||||
boolField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is TextField stringField)
|
|
||||||
{
|
|
||||||
stringField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is ColorField colorField)
|
|
||||||
{
|
|
||||||
colorField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is Vector3Field vector3Field)
|
|
||||||
{
|
|
||||||
vector3Field.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is Vector2Field vector2Field)
|
|
||||||
{
|
|
||||||
vector2Field.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is ObjectField objectField)
|
|
||||||
{
|
|
||||||
objectField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField is EnumField enumField)
|
|
||||||
{
|
|
||||||
enumField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
field.SetValue(graphNode, evt.newValue); // 🎯 Update the field with the new enum value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (propertyField.GetType() == typeof(GreyscaleField))
|
|
||||||
{
|
|
||||||
var greyscaleField = propertyField as GreyscaleField;
|
|
||||||
greyscaleField.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
var value = (GreyscaleValue)field.GetValue(graphNode);
|
|
||||||
|
|
||||||
if(evt.newValue > greyscaleField.minMax.Item2)
|
NewElement.Add(the);
|
||||||
value.value = greyscaleField.minMax.Item2;
|
((IPTPort)port).ExposedPropertyContainer = the;
|
||||||
else if(evt.newValue < greyscaleField.minMax.Item1)
|
ExposedPropertyContainer = ((IPTPort)port).ExposedPropertyContainer;
|
||||||
value.value = greyscaleField.minMax.Item1;
|
|
||||||
|
|
||||||
value.value = (int)evt.newValue;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
propertyFieldContainer.Add(propertyField);
|
|
||||||
port.Add(propertyFieldContainer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If the port is connected, remove the exposed UI element
|
containerType = ExposedPropertyContainer.GetType();
|
||||||
List<VisualElement> children = new List<VisualElement>();
|
|
||||||
|
|
||||||
foreach (var child in port.Children())
|
|
||||||
{
|
|
||||||
children.Add(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
var existingPropertyFieldContainer = port.Q<VisualElement>("property-field-container");
|
|
||||||
if (existingPropertyFieldContainer != null)
|
|
||||||
{
|
|
||||||
port.Remove(existingPropertyFieldContainer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (containerType == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ExposedPropertyContainer.GetType() == typeof(IntegerField))
|
||||||
|
{
|
||||||
|
var intField = ExposedPropertyContainer as IntegerField;
|
||||||
|
intField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is FloatField floatField)
|
||||||
|
{
|
||||||
|
floatField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is Toggle boolField)
|
||||||
|
{
|
||||||
|
boolField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is TextField stringField)
|
||||||
|
{
|
||||||
|
stringField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is ColorField colorField)
|
||||||
|
{
|
||||||
|
colorField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is Vector3Field vector3Field)
|
||||||
|
{
|
||||||
|
vector3Field.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is Vector2Field vector2Field)
|
||||||
|
{
|
||||||
|
vector2Field.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is ObjectField objectField)
|
||||||
|
{
|
||||||
|
objectField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // Update the field with the new value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer is EnumField enumField)
|
||||||
|
{
|
||||||
|
enumField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
field.SetValue(graphNode, evt.newValue); // 🎯 Update the field with the new enum value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (ExposedPropertyContainer.GetType() == typeof(GreyscaleField))
|
||||||
|
{
|
||||||
|
var greyscaleField = ExposedPropertyContainer as GreyscaleField;
|
||||||
|
greyscaleField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
var value = (GreyscaleValue)field.GetValue(graphNode);
|
||||||
|
|
||||||
|
if (evt.newValue > greyscaleField.minMax.Item2)
|
||||||
|
value.value = greyscaleField.minMax.Item2;
|
||||||
|
else if (evt.newValue < greyscaleField.minMax.Item1) value.value = greyscaleField.minMax.Item1;
|
||||||
|
|
||||||
|
value.value = evt.newValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
port.Add(ExposedPropertyContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggleExposedVariable(Port port, bool value)
|
||||||
|
{
|
||||||
|
IPTPort iptPort = port as IPTPort;
|
||||||
|
if(iptPort.ExposedPropertyContainer != null)
|
||||||
|
iptPort.ExposedPropertyContainer.visible = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private VisualElement CreatePropertyFieldForType(Type type, object value)
|
private VisualElement CreatePropertyFieldForType(Type type, object value)
|
||||||
|
@ -70,6 +70,17 @@ namespace ImageProcessingGraph.Editor
|
|||||||
DrawNodes();
|
DrawNodes();
|
||||||
DrawConnections();
|
DrawConnections();
|
||||||
|
|
||||||
|
foreach (var conn in asset.Connections)
|
||||||
|
{
|
||||||
|
if (conn.internalEdge == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetNode(conn.inputPort.nodeID).ToggleExposedVariable(conn.internalEdge.input, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
graphViewChanged += OnGraphViewChanged;
|
graphViewChanged += OnGraphViewChanged;
|
||||||
Undo.undoRedoEvent += UndoEvent;
|
Undo.undoRedoEvent += UndoEvent;
|
||||||
}
|
}
|
||||||
@ -226,7 +237,7 @@ namespace ImageProcessingGraph.Editor
|
|||||||
private void UndoEvent(in UndoRedoInfo undo)
|
private void UndoEvent(in UndoRedoInfo undo)
|
||||||
{
|
{
|
||||||
DrawNodes();
|
DrawNodes();
|
||||||
|
DrawConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GraphViewChange OnGraphViewChanged(GraphViewChange graphviewchange)
|
private GraphViewChange OnGraphViewChanged(GraphViewChange graphviewchange)
|
||||||
@ -297,7 +308,7 @@ namespace ImageProcessingGraph.Editor
|
|||||||
IPTPort portOut = (IPTPort)edge.output;
|
IPTPort portOut = (IPTPort)edge.output;
|
||||||
|
|
||||||
if (portIn.fieldInfo != null)
|
if (portIn.fieldInfo != null)
|
||||||
inputNode.ExposeVariableToPort(edge.input, portOut.fieldInfo);
|
inputNode.ToggleExposedVariable(edge.input, false);
|
||||||
|
|
||||||
asset.Connections.Add(connection);
|
asset.Connections.Add(connection);
|
||||||
}
|
}
|
||||||
@ -317,12 +328,18 @@ namespace ImageProcessingGraph.Editor
|
|||||||
IPTPort portIn = (IPTPort)edge.input;
|
IPTPort portIn = (IPTPort)edge.input;
|
||||||
|
|
||||||
if(portIn.fieldInfo != null)
|
if(portIn.fieldInfo != null)
|
||||||
inputNode.ExposeVariableToPort(edge.input, portIn.fieldInfo);
|
inputNode.ToggleExposedVariable(edge.input, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawConnections()
|
private void DrawConnections()
|
||||||
{
|
{
|
||||||
|
foreach (KeyValuePair<Edge, GraphConnection> node in connectionDictionary)
|
||||||
|
{
|
||||||
|
RemoveElement(node.Key);
|
||||||
|
}
|
||||||
|
connectionDictionary.Clear();
|
||||||
|
|
||||||
if (asset.Connections != null)
|
if (asset.Connections != null)
|
||||||
{
|
{
|
||||||
foreach (GraphConnection conn in asset.Connections)
|
foreach (GraphConnection conn in asset.Connections)
|
||||||
@ -332,14 +349,15 @@ namespace ImageProcessingGraph.Editor
|
|||||||
|
|
||||||
if (inputNode != null && outputNode != null)
|
if (inputNode != null && outputNode != null)
|
||||||
{
|
{
|
||||||
Port inPort = inputNode.InputPorts[conn.inputPort.portID];
|
IPTPort inPort = inputNode.InputPorts[conn.inputPort.portID] as IPTPort;
|
||||||
Port outPort = outputNode.OutputPorts[conn.outputPort.portID];
|
IPTPort outPort = outputNode.OutputPorts[conn.outputPort.portID] as IPTPort;
|
||||||
|
|
||||||
Edge edge = inPort.ConnectTo(outPort);
|
Edge edge = inPort.ConnectTo(outPort);
|
||||||
AddElement(edge);
|
AddElement(edge);
|
||||||
connectionDictionary.Add(edge, conn);
|
connectionDictionary.Add(edge, conn);
|
||||||
|
conn.SetInternalEdge(edge);
|
||||||
|
|
||||||
|
((ImageProcessingGraphNodeVisual)inPort.node).ToggleExposedVariable(inPort, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user