Various Fixes
This commit is contained in:
parent
499d187c96
commit
4f348fe66a
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace ImageProcessingGraph.Editor
|
||||
@ -8,6 +9,20 @@ namespace ImageProcessingGraph.Editor
|
||||
public class IPTPort : Port
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -115,7 +115,7 @@ namespace ImageProcessingGraph.Editor
|
||||
catch (Exception e)
|
||||
{
|
||||
onFailed?.Invoke();
|
||||
Debug.LogError(e);
|
||||
//Debug.LogError(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,11 @@ namespace ImageProcessingGraph.Editor
|
||||
this.outputPort = new GraphPort(outputNodeGuid, outputPortID, outputNodeType);
|
||||
this.internalEdge = internalEdge;
|
||||
}
|
||||
|
||||
public void SetInternalEdge(Edge edge)
|
||||
{
|
||||
this.internalEdge = edge;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
@ -42,6 +42,8 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
((ImageProcessingGraphNodeVisual)edge.input.node).ToggleExposedVariable((IPTPort)edge.input, true);
|
||||
|
||||
|
||||
this.m_EdgesToCreate.Clear();
|
||||
this.m_EdgesToCreate.Add(edge);
|
||||
|
@ -23,7 +23,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
private ImageProcessingGraphViewWindow window;
|
||||
|
||||
private StyleSheet errorStyleSheet;
|
||||
|
||||
|
||||
public ImageProcessingGraphNodeVisual(BaseImageNode node, ImageProcessingGraphViewWindow window)
|
||||
{
|
||||
this.AddToClassList("image-node-visual");
|
||||
@ -68,6 +68,16 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
|
||||
CreateInputPorts(inputFieldInfo);
|
||||
CreateOutputPorts(outputFieldInfo);
|
||||
|
||||
foreach (Port input in InputPorts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
foreach (Port input in OutputPorts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
errorStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Unity Image Processing/Node.uss");
|
||||
if (errorStyleSheet == null)
|
||||
@ -129,118 +139,119 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
// Exposes a variable on the port for editing when it's not connected
|
||||
public void ExposeVariableToPort(Port port, FieldInfo field)
|
||||
{
|
||||
// Only expose when the port is not connected
|
||||
if (port.connections.Count() == 0)
|
||||
var ExposedPropertyContainer = ((IPTPort)port).ExposedPropertyContainer;
|
||||
Type containerType = null;
|
||||
|
||||
if (ExposedPropertyContainer == null)
|
||||
{
|
||||
var propertyFieldContainer = new VisualElement();
|
||||
propertyFieldContainer.name = "property-field-container";
|
||||
var propertyField = CreatePropertyFieldForType(field.FieldType, field.GetValue(graphNode));
|
||||
|
||||
if (propertyField != null)
|
||||
{
|
||||
// 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)
|
||||
value.value = greyscaleField.minMax.Item2;
|
||||
else if(evt.newValue < greyscaleField.minMax.Item1)
|
||||
value.value = greyscaleField.minMax.Item1;
|
||||
|
||||
value.value = (int)evt.newValue;
|
||||
});
|
||||
}
|
||||
|
||||
propertyFieldContainer.Add(propertyField);
|
||||
port.Add(propertyFieldContainer);
|
||||
}
|
||||
var NewElement = new VisualElement();
|
||||
NewElement.name = "property-field-container";
|
||||
VisualElement the = CreatePropertyFieldForType(field.FieldType, field.GetValue(graphNode));
|
||||
|
||||
if(the != null)
|
||||
containerType = the.GetType();
|
||||
|
||||
NewElement.Add(the);
|
||||
((IPTPort)port).ExposedPropertyContainer = the;
|
||||
ExposedPropertyContainer = ((IPTPort)port).ExposedPropertyContainer;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the port is connected, remove the exposed UI element
|
||||
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);
|
||||
}
|
||||
containerType = ExposedPropertyContainer.GetType();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (type == typeof(int))
|
||||
|
@ -70,6 +70,17 @@ namespace ImageProcessingGraph.Editor
|
||||
DrawNodes();
|
||||
DrawConnections();
|
||||
|
||||
foreach (var conn in asset.Connections)
|
||||
{
|
||||
if (conn.internalEdge == null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//GetNode(conn.inputPort.nodeID).ToggleExposedVariable(conn.internalEdge.input, true);
|
||||
|
||||
}
|
||||
|
||||
graphViewChanged += OnGraphViewChanged;
|
||||
Undo.undoRedoEvent += UndoEvent;
|
||||
}
|
||||
@ -226,7 +237,7 @@ namespace ImageProcessingGraph.Editor
|
||||
private void UndoEvent(in UndoRedoInfo undo)
|
||||
{
|
||||
DrawNodes();
|
||||
|
||||
DrawConnections();
|
||||
}
|
||||
|
||||
private GraphViewChange OnGraphViewChanged(GraphViewChange graphviewchange)
|
||||
@ -297,7 +308,7 @@ namespace ImageProcessingGraph.Editor
|
||||
IPTPort portOut = (IPTPort)edge.output;
|
||||
|
||||
if (portIn.fieldInfo != null)
|
||||
inputNode.ExposeVariableToPort(edge.input, portOut.fieldInfo);
|
||||
inputNode.ToggleExposedVariable(edge.input, false);
|
||||
|
||||
asset.Connections.Add(connection);
|
||||
}
|
||||
@ -317,12 +328,18 @@ namespace ImageProcessingGraph.Editor
|
||||
IPTPort portIn = (IPTPort)edge.input;
|
||||
|
||||
if(portIn.fieldInfo != null)
|
||||
inputNode.ExposeVariableToPort(edge.input, portIn.fieldInfo);
|
||||
inputNode.ToggleExposedVariable(edge.input, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawConnections()
|
||||
{
|
||||
foreach (KeyValuePair<Edge, GraphConnection> node in connectionDictionary)
|
||||
{
|
||||
RemoveElement(node.Key);
|
||||
}
|
||||
connectionDictionary.Clear();
|
||||
|
||||
if (asset.Connections != null)
|
||||
{
|
||||
foreach (GraphConnection conn in asset.Connections)
|
||||
@ -332,14 +349,15 @@ namespace ImageProcessingGraph.Editor
|
||||
|
||||
if (inputNode != null && outputNode != null)
|
||||
{
|
||||
Port inPort = inputNode.InputPorts[conn.inputPort.portID];
|
||||
Port outPort = outputNode.OutputPorts[conn.outputPort.portID];
|
||||
IPTPort inPort = inputNode.InputPorts[conn.inputPort.portID] as IPTPort;
|
||||
IPTPort outPort = outputNode.OutputPorts[conn.outputPort.portID] as IPTPort;
|
||||
|
||||
Edge edge = inPort.ConnectTo(outPort);
|
||||
AddElement(edge);
|
||||
connectionDictionary.Add(edge, conn);
|
||||
conn.SetInternalEdge(edge);
|
||||
|
||||
|
||||
((ImageProcessingGraphNodeVisual)inPort.node).ToggleExposedVariable(inPort, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user