Skip to content

Commit a926eee

Browse files
committed
Fixed another issue with undo redo
1 parent 041c388 commit a926eee

File tree

3 files changed

+212
-63
lines changed

3 files changed

+212
-63
lines changed

Assets/Examples/CustomPushExample.asset

Lines changed: 194 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,19 @@ MonoBehaviour:
1212
m_Script: {fileID: 11500000, guid: 31390c44c9f3a3d40b424bf6821999a2, type: 3}
1313
m_Name: CustomPushExample
1414
m_EditorClassIdentifier:
15-
serializedNodes:
16-
- type: CircleRadians, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
17-
jsonDatas: '{"GUID":"7078860c-f7cb-4534-befd-da3c678d17ee","computeOrder":1,"position":{"serializedVersion":"2","x":159.0,"y":116.0,"width":116.0,"height":167.0},"expanded":false,"debug":false,"nodeLock":false,"outputRadians":[0.0,1.2566370964050294,2.5132741928100588,3.769911289215088,5.026548385620117]}'
18-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
19-
jsonDatas: '{"GUID":"0d8cd048-486b-4cce-9bd3-616bd2255d45","computeOrder":2,"position":{"serializedVersion":"2","x":496.0,"y":-3.399993896484375,"width":71.0,"height":95.0},"expanded":false,"debug":false,"nodeLock":false}'
20-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
21-
jsonDatas: '{"GUID":"e2203ce1-49be-41ea-814a-465faf267adb","computeOrder":2,"position":{"serializedVersion":"2","x":382.7353515625,"y":107.50852966308594,"width":107.0,"height":117.0},"expanded":false,"debug":false,"nodeLock":false}'
22-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
23-
jsonDatas: '{"GUID":"3b193543-3bd6-44d6-9664-115ecc6f2502","computeOrder":2,"position":{"serializedVersion":"2","x":382.8052978515625,"y":239.9835205078125,"width":107.0,"height":117.0},"expanded":false,"debug":false,"nodeLock":false}'
24-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
25-
jsonDatas: '{"GUID":"e3318e7b-5469-424c-ab54-9524e62907a8","computeOrder":2,"position":{"serializedVersion":"2","x":498.0,"y":273.0,"width":107.0,"height":117.0},"expanded":false,"debug":false,"nodeLock":false}'
26-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
27-
jsonDatas: '{"GUID":"83c994d8-6442-4e61-82e1-e83537229fda","computeOrder":2,"position":{"serializedVersion":"2","x":499.0,"y":137.0,"width":71.0,"height":95.0},"expanded":false,"debug":false,"nodeLock":false}'
28-
- type: MultiAddNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
29-
jsonDatas: '{"GUID":"6b00dec7-a9af-4c2c-91fe-edb8f892882f","computeOrder":2,"position":{"serializedVersion":"2","x":734.0,"y":-220.8800048828125,"width":123.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"output":0.0}'
30-
- type: FloatNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
31-
jsonDatas: '{"GUID":"02bc84c5-93ad-4a5e-b627-e930d133a1fd","computeOrder":1,"position":{"serializedVersion":"2","x":394.0,"y":-219.79998779296876,"width":72.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"output":0.0,"input":0.0}'
32-
- type: CustomPortsNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
33-
jsonDatas: '{"GUID":"1f8d14f7-5355-4734-8837-36668dd8e8ba","computeOrder":4,"position":{"serializedVersion":"2","x":730.0,"y":-102.0,"width":128.0,"height":125.0},"expanded":false,"debug":false,"nodeLock":false,"inputs":[],"outputs":[],"portCount":4}'
34-
- type: PrintNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
35-
jsonDatas: '{"GUID":"39f87d68-86a6-4b72-8a26-315c18d08525","computeOrder":5,"position":{"serializedVersion":"2","x":1027.0,"y":38.0,"width":100.0,"height":100.0},"expanded":false,"debug":false,"nodeLock":false}'
36-
- type: CustomPortsNode, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
37-
jsonDatas: '{"GUID":"137e400a-732b-4a4a-a216-ac084fe082d4","computeOrder":1,"position":{"serializedVersion":"2","x":733.1304321289063,"y":108.78262329101563,"width":138.0,"height":101.0},"expanded":false,"debug":false,"nodeLock":false,"inputs":[],"outputs":[],"portCount":3}'
15+
serializedNodes: []
16+
nodes:
17+
- id: 0
18+
- id: 1
19+
- id: 2
20+
- id: 3
21+
- id: 4
22+
- id: 5
23+
- id: 6
24+
- id: 7
25+
- id: 8
26+
- id: 9
27+
- id: 10
3828
edges:
3929
- GUID: 035ee169-e916-40b5-aecc-831d072ea9ab
4030
owner: {fileID: 11400000}
@@ -100,14 +90,6 @@ MonoBehaviour:
10090
outputFieldName: output
10191
inputPortIdentifier: 1
10292
outputPortIdentifier:
103-
- GUID: bc55dc8f-2a86-4f01-9bae-9ed04b041472
104-
owner: {fileID: 11400000}
105-
inputNodeGUID: 1f8d14f7-5355-4734-8837-36668dd8e8ba
106-
outputNodeGUID: 02bc84c5-93ad-4a5e-b627-e930d133a1fd
107-
inputFieldName: inputs
108-
outputFieldName: output
109-
inputPortIdentifier: 2
110-
outputPortIdentifier:
11193
- GUID: ad729fe3-5664-4163-a4e7-825262af1996
11294
owner: {fileID: 11400000}
11395
inputNodeGUID: 39f87d68-86a6-4b72-8a26-315c18d08525
@@ -116,6 +98,14 @@ MonoBehaviour:
11698
outputFieldName: outputs
11799
inputPortIdentifier:
118100
outputPortIdentifier:
101+
- GUID: 362c225a-5bfd-4adb-8327-7fb0e49be493
102+
owner: {fileID: 11400000}
103+
inputNodeGUID: 1f8d14f7-5355-4734-8837-36668dd8e8ba
104+
outputNodeGUID: 02bc84c5-93ad-4a5e-b627-e930d133a1fd
105+
inputFieldName: inputs
106+
outputFieldName: output
107+
inputPortIdentifier: 2
108+
outputPortIdentifier:
119109
groups: []
120110
stackNodes: []
121111
pinnedElements:
@@ -160,7 +150,178 @@ MonoBehaviour:
160150
serializedType: GraphProcessor.ProcessorView, com.alelievr.NodeGraphProcessor.Editor,
161151
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
162152
exposedParameters: []
163-
position: {x: 116, y: -31.999994, z: 0}
164-
scale: {x: 0.7561437, y: 0.7561437, z: 1}
153+
serializedParameterList: []
154+
stickyNotes: []
155+
position: {x: -99, y: 382, z: 0}
156+
scale: {x: 0.8695652, y: 0.8695652, z: 1}
165157
references:
166158
version: 1
159+
00000000:
160+
type: {class: CircleRadians, ns: , asm: Assembly-CSharp}
161+
data:
162+
GUID: 7078860c-f7cb-4534-befd-da3c678d17ee
163+
computeOrder: 0
164+
position:
165+
serializedVersion: 2
166+
x: 159
167+
y: 116
168+
width: 116
169+
height: 167
170+
expanded: 0
171+
debug: 0
172+
nodeLock: 0
173+
outputRadians:
174+
- 0
175+
- 1.2566371
176+
- 2.5132742
177+
- 3.7699113
178+
- 5.0265484
179+
00000001:
180+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
181+
data:
182+
GUID: 0d8cd048-486b-4cce-9bd3-616bd2255d45
183+
computeOrder: 1
184+
position:
185+
serializedVersion: 2
186+
x: 496
187+
y: -3.399994
188+
width: 71
189+
height: 95
190+
expanded: 0
191+
debug: 0
192+
nodeLock: 0
193+
00000002:
194+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
195+
data:
196+
GUID: e2203ce1-49be-41ea-814a-465faf267adb
197+
computeOrder: 2
198+
position:
199+
serializedVersion: 2
200+
x: 382.73535
201+
y: 107.50853
202+
width: 107
203+
height: 117
204+
expanded: 0
205+
debug: 0
206+
nodeLock: 0
207+
00000003:
208+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
209+
data:
210+
GUID: 3b193543-3bd6-44d6-9664-115ecc6f2502
211+
computeOrder: 3
212+
position:
213+
serializedVersion: 2
214+
x: 382.8053
215+
y: 239.98352
216+
width: 107
217+
height: 117
218+
expanded: 0
219+
debug: 0
220+
nodeLock: 0
221+
00000004:
222+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
223+
data:
224+
GUID: e3318e7b-5469-424c-ab54-9524e62907a8
225+
computeOrder: 4
226+
position:
227+
serializedVersion: 2
228+
x: 498
229+
y: 273
230+
width: 107
231+
height: 117
232+
expanded: 0
233+
debug: 0
234+
nodeLock: 0
235+
00000005:
236+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
237+
data:
238+
GUID: 83c994d8-6442-4e61-82e1-e83537229fda
239+
computeOrder: 5
240+
position:
241+
serializedVersion: 2
242+
x: 499
243+
y: 137
244+
width: 71
245+
height: 95
246+
expanded: 0
247+
debug: 0
248+
nodeLock: 0
249+
00000006:
250+
type: {class: MultiAddNode, ns: , asm: Assembly-CSharp}
251+
data:
252+
GUID: 6b00dec7-a9af-4c2c-91fe-edb8f892882f
253+
computeOrder: 7
254+
position:
255+
serializedVersion: 2
256+
x: 734
257+
y: -220.88
258+
width: 123
259+
height: 101
260+
expanded: 0
261+
debug: 0
262+
nodeLock: 0
263+
output: 0
264+
00000007:
265+
type: {class: FloatNode, ns: , asm: Assembly-CSharp}
266+
data:
267+
GUID: 02bc84c5-93ad-4a5e-b627-e930d133a1fd
268+
computeOrder: 6
269+
position:
270+
serializedVersion: 2
271+
x: 394
272+
y: -219.79999
273+
width: 72
274+
height: 101
275+
expanded: 0
276+
debug: 0
277+
nodeLock: 0
278+
output: 0
279+
input: 0
280+
00000008:
281+
type: {class: CustomPortsNode, ns: , asm: Assembly-CSharp}
282+
data:
283+
GUID: 1f8d14f7-5355-4734-8837-36668dd8e8ba
284+
computeOrder: 8
285+
position:
286+
serializedVersion: 2
287+
x: 730
288+
y: -102
289+
width: 128
290+
height: 125
291+
expanded: 0
292+
debug: 0
293+
nodeLock: 0
294+
inputs: []
295+
outputs: []
296+
portCount: 5
297+
00000009:
298+
type: {class: PrintNode, ns: , asm: Assembly-CSharp}
299+
data:
300+
GUID: 39f87d68-86a6-4b72-8a26-315c18d08525
301+
computeOrder: 9
302+
position:
303+
serializedVersion: 2
304+
x: 1027
305+
y: 38
306+
width: 100
307+
height: 100
308+
expanded: 0
309+
debug: 0
310+
nodeLock: 0
311+
0000000A:
312+
type: {class: CustomPortsNode, ns: , asm: Assembly-CSharp}
313+
data:
314+
GUID: 137e400a-732b-4a4a-a216-ac084fe082d4
315+
computeOrder: 10
316+
position:
317+
serializedVersion: 2
318+
x: 733.13043
319+
y: 108.78262
320+
width: 138
321+
height: 101
322+
expanded: 0
323+
debug: 0
324+
nodeLock: 0
325+
inputs: []
326+
outputs: []
327+
portCount: 3

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -996,28 +996,6 @@ void SyncPortOrder(IEnumerable< NodePort > ports, IEnumerable< PortView > portVi
996996
}
997997
}
998998

999-
// void UpdatePortConnections(List< PortView > portViews)
1000-
// {
1001-
// foreach (var pv in portViews)
1002-
// {
1003-
// Debug.Log("pv: " + pv.portName);
1004-
1005-
// // Go over all connected edges and disconnect them if the serialized edge have been removed
1006-
// // This can happens when the new port type is incompatible with the old one.
1007-
// foreach (var edge in pv.GetEdges().ToList())
1008-
// {
1009-
// // TODO: check edge connection compatibility !
1010-
// Debug.Log("Edge !");
1011-
// if (owner.graph.edges.Contains(edge.serializedEdge))
1012-
// {
1013-
// owner.Disconnect(edge);
1014-
// // owner.RemoveElement(edge);
1015-
// // base.RefreshPorts(); // We don't call this.RefreshPorts because it will cause an infinite loop
1016-
// }
1017-
// }
1018-
// }
1019-
// }
1020-
1021999
public virtual new bool RefreshPorts()
10221000
{
10231001
// If a port behavior was attached to one port, then
@@ -1028,6 +1006,9 @@ void SyncPortOrder(IEnumerable< NodePort > ports, IEnumerable< PortView > portVi
10281006

10291007
void UpdatePortViewWithPorts(NodePortContainer ports, List< PortView > portViews)
10301008
{
1009+
if (ports.Count == 0 && portViews.Count == 0) // Nothing to update
1010+
return;
1011+
10311012
// When there is no current portviews, we can't zip the list so we just add all
10321013
if (portViews.Count == 0)
10331014
SyncPortCounts(ports, new PortView[]{});

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,13 @@ public virtual void InitializePorts()
249249
{
250250
InitializeCustomPortTypeMethods();
251251

252-
inputPorts.Clear();
253-
outputPorts.Clear();
254252
foreach (var key in OverrideFieldOrder(nodeFields.Values.Select(k => k.info)))
255253
{
256254
var nodeField = nodeFields[key.Name];
257255

258256
if (HasCustomBehavior(nodeField))
259257
{
260-
UpdatePortsForField(nodeField.fieldName);
258+
UpdatePortsForField(nodeField.fieldName, sendPortUpdatedEvent: false);
261259
}
262260
else
263261
{
@@ -336,7 +334,7 @@ public bool UpdateAllPortsLocal()
336334
/// Update the ports related to one C# property field (only for this node)
337335
/// </summary>
338336
/// <param name="fieldName"></param>
339-
public bool UpdatePortsForFieldLocal(string fieldName)
337+
public bool UpdatePortsForFieldLocal(string fieldName, bool sendPortUpdatedEvent = true)
340338
{
341339
bool changed = false;
342340

@@ -426,7 +424,8 @@ void AddPortData(PortData portData)
426424
return p1Index.CompareTo(p2Index);
427425
});
428426

429-
onPortsUpdated?.Invoke(fieldName);
427+
if (sendPortUpdatedEvent)
428+
onPortsUpdated?.Invoke(fieldName);
430429

431430
return changed;
432431
}
@@ -446,7 +445,7 @@ bool HasCustomBehavior(NodeFieldInformation info)
446445
/// Update the ports related to one C# property field and all connected nodes in the graph
447446
/// </summary>
448447
/// <param name="fieldName"></param>
449-
public bool UpdatePortsForField(string fieldName)
448+
public bool UpdatePortsForField(string fieldName, bool sendPortUpdatedEvent = true)
450449
{
451450
bool changed = false;
452451

@@ -469,7 +468,7 @@ public bool UpdatePortsForField(string fieldName)
469468

470469
foreach (var field in fields)
471470
{
472-
if (node.UpdatePortsForFieldLocal(field))
471+
if (node.UpdatePortsForFieldLocal(field, sendPortUpdatedEvent))
473472
{
474473
foreach (var port in node.IsFieldInput(field) ? (NodePortContainer)node.inputPorts : node.outputPorts)
475474
{
@@ -493,7 +492,15 @@ public bool UpdatePortsForField(string fieldName)
493492

494493
HashSet<BaseNode> portUpdateHashSet = new HashSet<BaseNode>();
495494

496-
internal void DisableInternal() => ExceptionToLog.Call(() => Disable());
495+
internal void DisableInternal()
496+
{
497+
// port containers are initialized in the OnEnable
498+
inputPorts.Clear();
499+
outputPorts.Clear();
500+
501+
ExceptionToLog.Call(() => Disable());
502+
}
503+
497504
internal void DestroyInternal() => ExceptionToLog.Call(() => Destroy());
498505

499506
/// <summary>

0 commit comments

Comments
 (0)