Skip to content

Commit a43351f

Browse files
author
Daniel Burgess
committed
BUG Schema duplicating UI when changed
1 parent 7635d0e commit a43351f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/SubGraph/SubGraphGUIUtility.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ public SubGraphGUIUtility(SubGraph subGraph)
2323

2424
public SubGraph SubGraph => _subgraph;
2525
public SubGraphOptionsGUIUtility OptionsGUIUtil => new(SubGraph);
26-
public SubGraphSchemaGUIUtility SchemaGUIUtil => SubGraph.Schema ? new(SubGraph.Schema) : null;
26+
private SubGraphSchemaGUIUtility _schemaGUIUtil;
27+
public SubGraphSchemaGUIUtility SchemaGUIUtil =>
28+
PropertyUtils.LazyLoad(
29+
ref _schemaGUIUtil,
30+
() => SubGraph.Schema ? new(SubGraph.Schema) : null,
31+
(x) => x == null || SubGraph.Schema != x.Schema
32+
);
2733

2834
public SerializedObject SubGraphObject =>
2935
PropertyUtils.LazyLoad(

Assets/com.alelievr.NodeGraphProcessor/Editor/Views/SubGraph/SubGraphView.cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GraphProcessor.Utils;
12
using UnityEditor;
23
using UnityEditor.UIElements;
34
using UnityEngine;
@@ -6,7 +7,7 @@
67
namespace GraphProcessor
78
{
89
[CustomEditor(typeof(SubGraph), true)]
9-
public partial class SubGraphView : GraphInspector
10+
public class SubGraphView : GraphInspector
1011
{
1112
protected SubGraph SubGraph => target as SubGraph;
1213
protected SubGraphPortSchema Schema => SubGraph.Schema;
@@ -40,19 +41,22 @@ private VisualElement DrawSchemaControlGUI()
4041
schemaField.RegisterCallback<ChangeEvent<Object>>((e) =>
4142
{
4243
SubGraphPortSchema prevSchemaValue = e.previousValue as SubGraphPortSchema;
43-
// We check visibility due to this callback sometimes being called twice.
44-
if (schemaControls.visible && Schema == null)
44+
SubGraphPortSchema newSchemaValue = e.newValue as SubGraphPortSchema;
45+
46+
if (prevSchemaValue == newSchemaValue) return;
47+
if (prevSchemaValue) prevSchemaValue.OnPortsUpdated -= SubGraph.NotifyPortsChanged;
48+
49+
schemaControls.Clear();
50+
51+
if (!newSchemaValue)
4552
{
46-
if (prevSchemaValue != null)
47-
prevSchemaValue.OnPortsUpdated -= SubGraph.NotifyPortsChanged;
48-
schemaControls.visible = false;
49-
schemaControls.Clear();
53+
schemaControls.Hide();
5054
}
51-
else if (!schemaControls.visible && Schema != null)
55+
else
5256
{
53-
Schema.OnPortsUpdated += SubGraph.NotifyPortsChanged;
57+
newSchemaValue.OnPortsUpdated += SubGraph.NotifyPortsChanged;
5458
schemaControls.Add(SubGraphSerializer.SchemaGUIUtil.DrawSchemaPortControlGUI());
55-
schemaControls.visible = true;
59+
schemaControls.Show();
5660
}
5761
});
5862

0 commit comments

Comments
 (0)