Skip to content

Commit 03dca7e

Browse files
committed
Fixed parameter node accessor mode update
1 parent 96f1e1d commit 03dca7e

File tree

9 files changed

+159
-129
lines changed

9 files changed

+159
-129
lines changed

Assets/Examples/CustomOutputExample.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ MonoBehaviour:
5555
serializedType: GraphProcessor.ProcessorView, com.alelievr.NodeGraphProcessor,
5656
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
5757
exposedParameters: []
58-
position: {x: 132, y: -18, z: 0}
59-
scale: {x: 1, y: 1, z: 1}
58+
position: {x: 208, y: 72, z: 0}
59+
scale: {x: 0.65751624, y: 0.65751624, z: 1}

Assets/Examples/ExposedPropertiesExample.asset

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,58 @@ MonoBehaviour:
1414
m_EditorClassIdentifier:
1515
serializedNodes:
1616
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
17-
jsonDatas: '{"GUID":"39fdf09f-b7ff-49f5-bfe5-c59e221c30b6","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":227.00003051757813,"y":445.00006103515627,"width":72.0,"height":95.0},"expanded":true,"debug":false}'
18-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
19-
jsonDatas: '{"GUID":"bd6e5486-333b-4d08-b049-1103e9b1dc20","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":216.17015075683595,"y":572.4877319335938,"width":72.0,"height":95.0},"expanded":false,"debug":false}'
20-
- type: ParameterNode, com.alelievr.NodeGraphProcessor, Version=0.0.0.0, Culture=neutral,
21-
PublicKeyToken=null
22-
jsonDatas: '{"GUID":"8bd321f8-b93c-4360-8b0c-d004d3604e97","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":45.368614196777347,"y":641.9660034179688,"width":100.0,"height":100.0},"expanded":false,"debug":false,"parameterGUID":"fc2400e0-1461-4ba2-9d60-9533b6417d88"}'
23-
- type: ParameterNode, com.alelievr.NodeGraphProcessor, Version=0.0.0.0, Culture=neutral,
24-
PublicKeyToken=null
25-
jsonDatas: '{"GUID":"dab6d88a-b3dc-4dc9-bd5f-1240771222bf","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":46.88090133666992,"y":519.470703125,"width":100.0,"height":100.0},"expanded":false,"debug":false,"parameterGUID":"9ae7b637-72eb-4fcf-90d9-c9bd11336a2b"}'
17+
jsonDatas: '{"GUID":"39fdf09f-b7ff-49f5-bfe5-c59e221c30b6","computeOrder":2,"canProcess":true,"position":{"serializedVersion":"2","x":415.0,"y":101.0,"width":72.0,"height":95.0},"expanded":true,"debug":false,"nodeLock":false}'
18+
- type: GraphProcessor.ParameterNode, com.alelievr.NodeGraphProcessor, Version=0.0.0.0,
19+
Culture=neutral, PublicKeyToken=null
20+
jsonDatas: '{"GUID":"e04c1751-9d7c-42c1-b140-77cf41fad3a9","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":255.0,"y":108.0,"width":73.0,"height":97.0},"expanded":false,"debug":false,"nodeLock":false,"parameterGUID":"hguieowhg","accessor":0}'
21+
- type: GraphProcessor.ParameterNode, com.alelievr.NodeGraphProcessor, Version=0.0.0.0,
22+
Culture=neutral, PublicKeyToken=null
23+
jsonDatas: '{"GUID":"3fd26d08-2596-42f5-996e-94c034f5a10b","computeOrder":4,"canProcess":true,"position":{"serializedVersion":"2","x":417.0,"y":248.0,"width":83.0,"height":97.0},"expanded":false,"debug":false,"nodeLock":false,"parameterGUID":"9ae7b637-72eb-4fcf-90d9-c9bd11336a2b","accessor":1}'
24+
- type: SubNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
25+
jsonDatas: '{"GUID":"1327efdb-6d08-421e-a601-67e39e1c4073","computeOrder":3,"canProcess":true,"position":{"serializedVersion":"2","x":292.0,"y":271.0,"width":98.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"inputA":42.0,"inputB":12.0,"output":30.0}'
26+
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
27+
jsonDatas: '{"GUID":"47e80399-61e7-4350-9ff3-aa91b54eabe3","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":191.0,"y":223.0,"width":73.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"output":42.0}'
28+
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
29+
jsonDatas: '{"GUID":"5a439c2f-4655-43ed-a6ae-e142b92b25ce","computeOrder":1,"canProcess":true,"position":{"serializedVersion":"2","x":193.0,"y":326.0,"width":73.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"output":12.0}'
2630
edges:
27-
- GUID: 33779579-bb15-444c-ad93-9cdb4ddc8ea0
31+
- GUID: 9da87722-5b0e-491d-af10-63206a3ca74e
2832
owner: {fileID: 11400000}
29-
inputNodeGUID: bd6e5486-333b-4d08-b049-1103e9b1dc20
30-
outputNodeGUID: 8bd321f8-b93c-4360-8b0c-d004d3604e97
31-
inputFieldName: obj
33+
inputNodeGUID: 1327efdb-6d08-421e-a601-67e39e1c4073
34+
outputNodeGUID: 5a439c2f-4655-43ed-a6ae-e142b92b25ce
35+
inputFieldName: inputB
3236
outputFieldName: output
3337
inputPortIdentifier:
34-
outputPortIdentifier: output
35-
- GUID: 3cab5bf1-528f-4325-849e-d82233fc7f62
38+
outputPortIdentifier:
39+
- GUID: cd6d29b2-5895-4265-bac2-12c7726ae674
40+
owner: {fileID: 11400000}
41+
inputNodeGUID: 1327efdb-6d08-421e-a601-67e39e1c4073
42+
outputNodeGUID: 47e80399-61e7-4350-9ff3-aa91b54eabe3
43+
inputFieldName: inputA
44+
outputFieldName: output
45+
inputPortIdentifier:
46+
outputPortIdentifier:
47+
- GUID: a8e11523-8a1b-4eb6-9aba-d35c0138a3da
3648
owner: {fileID: 11400000}
3749
inputNodeGUID: 39fdf09f-b7ff-49f5-bfe5-c59e221c30b6
38-
outputNodeGUID: dab6d88a-b3dc-4dc9-bd5f-1240771222bf
50+
outputNodeGUID: e04c1751-9d7c-42c1-b140-77cf41fad3a9
3951
inputFieldName: obj
4052
outputFieldName: output
4153
inputPortIdentifier:
4254
outputPortIdentifier: output
55+
- GUID: e3be1318-1249-4949-a2c9-1cacdd595afe
56+
owner: {fileID: 11400000}
57+
inputNodeGUID: 3fd26d08-2596-42f5-996e-94c034f5a10b
58+
outputNodeGUID: 1327efdb-6d08-421e-a601-67e39e1c4073
59+
inputFieldName: input
60+
outputFieldName: output
61+
inputPortIdentifier: input
62+
outputPortIdentifier:
4363
commentBlocks: []
4464
pinnedElements:
4565
- position:
4666
serializedVersion: 2
47-
x: 0
48-
y: 79
67+
x: 6
68+
y: 43
4969
width: 150
5070
height: 200
5171
opened: 1
@@ -54,8 +74,8 @@ MonoBehaviour:
5474
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
5575
- position:
5676
serializedVersion: 2
57-
x: 822
58-
y: 322
77+
x: 0
78+
y: 226
5979
width: 150
6080
height: 200
6181
opened: 1
@@ -77,7 +97,7 @@ MonoBehaviour:
7797
serializedValue:
7898
serializedType: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
7999
serializedName:
80-
serializedValue: 21
100+
serializedValue: 30
81101
input: 1
82102
- guid: fc2400e0-1461-4ba2-9d60-9533b6417d88
83103
name: New ColorParam
@@ -89,5 +109,5 @@ MonoBehaviour:
89109
serializedName:
90110
serializedValue: '{"r":1.0,"g":0.0,"b":0.0,"a":0.0}'
91111
input: 1
92-
position: {x: -105.5, y: -880.5, z: 0}
93-
scale: {x: 2, y: 2, z: 1}
112+
position: {x: 8, y: -51, z: 0}
113+
scale: {x: 1, y: 1, z: 1}

Assets/com.alelievr.NodeGraphProcessor/Editor/GraphInspector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ void OnEnable()
1717
{
1818
graph = target as BaseGraph;
1919
graph.onExposedParameterListChanged += UpdateExposedParameters;
20+
graph.onExposedParameterModified += UpdateExposedParameters;
2021
}
2122

2223
void OnDisable()
2324
{
2425
graph.onExposedParameterListChanged -= UpdateExposedParameters;
26+
graph.onExposedParameterModified -= UpdateExposedParameters;
2527
}
2628

2729
public sealed override VisualElement CreateInspectorGUI()
@@ -61,6 +63,8 @@ protected void FillExposedParameters(VisualElement parameterContainer)
6163
}
6264
}
6365

66+
void UpdateExposedParameters(string guid) => UpdateExposedParameters();
67+
6468
void UpdateExposedParameters()
6569
{
6670
parameterContainer.Clear();

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseNodeView.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ void SyncPortCounts(IEnumerable< NodePort > ports, IEnumerable< PortView > portV
404404
{
405405
// Add missing port views
406406
if (!portViews.Any(pv => p.portData.identifier == pv.portData.identifier))
407-
AddPort(p.fieldInfo, Direction.Input, listener, p.portData);
407+
{
408+
Direction portDirection = nodeTarget.IsFieldInput(p.fieldName) ? Direction.Input : Direction.Output;
409+
AddPort(p.fieldInfo, portDirection, listener, p.portData);
410+
}
408411
}
409412
}
410413

Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/BaseNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ public void UpdatePortsForField(string fieldName)
168168
{
169169
// If the current port does not appear in the list of final ports, we remove it
170170
if (!finalPorts.Any(id => id == currentPort.portData.identifier))
171-
{
172171
RemovePort(fieldInfo.input, currentPort);
173-
}
174172
}
175173
}
176174
}
@@ -333,6 +331,8 @@ public NodePort GetPort(string fieldName, string identifier)
333331
});
334332
}
335333

334+
public bool IsFieldInput(string fieldName) => nodeFields[fieldName].input;
335+
336336
#endregion
337337
}
338338
}

Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/ParameterNode.cs

Lines changed: 99 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,101 +5,104 @@
55
using System.Linq;
66
using System;
77

8-
[System.Serializable]
9-
public class ParameterNode : BaseNode
8+
namespace GraphProcessor
109
{
11-
[Input]
12-
public object input;
13-
14-
[Output]
15-
public object output;
16-
17-
public override string name => "huifehfgw";
18-
19-
// We serialize the GUID of the exposed parameter in the graph so we can retrieve the true ExposedParameter from the graph
20-
[SerializeField, HideInInspector]
21-
public string parameterGUID;
22-
23-
public ExposedParameter parameter { get; private set; }
24-
25-
public event Action onParameterChanged;
26-
27-
public ParameterAccessor accessor;
28-
29-
protected override void Enable()
30-
{
31-
// load the parameter
32-
LoadExposedParameter();
33-
34-
graph.onExposedParameterModified += OnParamChanged;
35-
if (onParameterChanged != null)
36-
onParameterChanged?.Invoke();
37-
}
38-
39-
void LoadExposedParameter()
40-
{
41-
parameter = graph.GetExposedParameterFromGUID(parameterGUID);
42-
43-
if (parameter == null)
44-
{
45-
Debug.Log("Property \"" + parameterGUID + "\" Can't be found !");
46-
47-
// Delete this node as the property can't be found
48-
graph.RemoveNode(this);
49-
return;
50-
}
51-
52-
output = parameter.serializedValue.value;
53-
}
54-
55-
void OnParamChanged(string modifiedParameterName)
56-
{
57-
if (parameter?.name == modifiedParameterName)
58-
{
59-
onParameterChanged?.Invoke();
60-
}
61-
}
62-
63-
[CustomPortBehavior(nameof(output))]
64-
IEnumerable<PortData> GetOutputPort(List<SerializableEdge> edges)
65-
{
66-
if (accessor == ParameterAccessor.GET)
67-
{
68-
yield return new PortData
69-
{
70-
identifier = "output",
71-
displayName = "Value",
72-
displayType = (parameter == null) ? typeof(object) : Type.GetType(parameter.type),
73-
};
74-
}
75-
}
76-
77-
[CustomPortBehavior(nameof(input))]
78-
IEnumerable<PortData> GetInputPort(List<SerializableEdge> edges)
79-
{
80-
if (accessor == ParameterAccessor.SET)
81-
{
82-
yield return new PortData
83-
{
84-
identifier = "input",
85-
displayName = "Value",
86-
displayType = (parameter == null) ? typeof(object) : Type.GetType(parameter.type),
87-
};
88-
}
89-
}
90-
91-
92-
protected override void Process()
93-
{
94-
if (accessor == ParameterAccessor.GET)
95-
output = parameter?.serializedValue.value;
96-
else
97-
parameter.serializedValue.value = input;
98-
}
10+
[System.Serializable]
11+
public class ParameterNode : BaseNode
12+
{
13+
[Input]
14+
public object input;
15+
16+
[Output]
17+
public object output;
18+
19+
public override string name => "Parameter";
20+
21+
// We serialize the GUID of the exposed parameter in the graph so we can retrieve the true ExposedParameter from the graph
22+
[SerializeField, HideInInspector]
23+
public string parameterGUID;
24+
25+
public ExposedParameter parameter { get; private set; }
26+
27+
public event Action onParameterChanged;
28+
29+
public ParameterAccessor accessor;
30+
31+
protected override void Enable()
32+
{
33+
// load the parameter
34+
LoadExposedParameter();
35+
36+
graph.onExposedParameterModified += OnParamChanged;
37+
if (onParameterChanged != null)
38+
onParameterChanged?.Invoke();
39+
}
40+
41+
void LoadExposedParameter()
42+
{
43+
parameter = graph.GetExposedParameterFromGUID(parameterGUID);
44+
45+
if (parameter == null)
46+
{
47+
Debug.Log("Property \"" + parameterGUID + "\" Can't be found !");
48+
49+
// Delete this node as the property can't be found
50+
graph.RemoveNode(this);
51+
return;
52+
}
53+
54+
output = parameter.serializedValue.value;
55+
}
56+
57+
void OnParamChanged(string modifiedParameterName)
58+
{
59+
if (parameter?.name == modifiedParameterName)
60+
{
61+
onParameterChanged?.Invoke();
62+
}
63+
}
64+
65+
[CustomPortBehavior(nameof(output))]
66+
IEnumerable<PortData> GetOutputPort(List<SerializableEdge> edges)
67+
{
68+
if (accessor == ParameterAccessor.Get)
69+
{
70+
yield return new PortData
71+
{
72+
identifier = "output",
73+
displayName = "Value",
74+
displayType = (parameter == null) ? typeof(object) : Type.GetType(parameter.type),
75+
};
76+
}
77+
}
78+
79+
[CustomPortBehavior(nameof(input))]
80+
IEnumerable<PortData> GetInputPort(List<SerializableEdge> edges)
81+
{
82+
if (accessor == ParameterAccessor.Set)
83+
{
84+
yield return new PortData
85+
{
86+
identifier = "input",
87+
displayName = "Value",
88+
displayType = (parameter == null) ? typeof(object) : Type.GetType(parameter.type),
89+
};
90+
}
91+
}
92+
93+
94+
protected override void Process()
95+
{
96+
if (accessor == ParameterAccessor.Get)
97+
output = parameter?.serializedValue.value;
98+
else
99+
graph.UpdateExposedParameter(parameter.guid, input);
100+
}
101+
}
102+
103+
public enum ParameterAccessor
104+
{
105+
Get,
106+
Set
107+
}
99108
}
100-
101-
public enum ParameterAccessor
102-
{
103-
GET,
104-
SET
105-
}

Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ public void UpdateExposedParameter(string guid, object value)
229229
string valueType = value.GetType().AssemblyQualifiedName;
230230

231231
if (valueType != param.type)
232-
throw new Exception("Type mismatch when updating parameter " + name + ": from " + param.type + " to " + valueType);
232+
throw new Exception("Type mismatch when updating parameter " + param.name + ": from " + param.type + " to " + valueType);
233233

234234
param.serializedValue.value = value;
235-
onExposedParameterModified.Invoke(name);
235+
onExposedParameterModified.Invoke(param.guid);
236236
}
237237

238238
public void UpdateExposedParameterName(ExposedParameter parameter, string name)

Packages/manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"com.unity.ads": "2.0.8",
44
"com.unity.analytics": "3.3.2",
55
"com.unity.collab-proxy": "1.2.16",
6-
"com.unity.package-manager-ui": "2.1.2",
6+
"com.unity.package-manager-ui": "2.2.0",
77
"com.unity.purchasing": "2.0.6",
88
"com.unity.textmeshpro": "2.0.1",
9-
"com.unity.timeline": "1.0.0",
109
"com.unity.modules.ai": "1.0.0",
1110
"com.unity.modules.animation": "1.0.0",
1211
"com.unity.modules.assetbundle": "1.0.0",

0 commit comments

Comments
 (0)