|
| 1 | +using GraphProcessor.Utils; |
1 | 2 | using UnityEditor;
|
2 | 3 | using UnityEditor.UIElements;
|
3 | 4 | using UnityEngine;
|
|
6 | 7 | namespace GraphProcessor
|
7 | 8 | {
|
8 | 9 | [CustomEditor(typeof(SubGraph), true)]
|
9 |
| - public partial class SubGraphView : GraphInspector |
| 10 | + public class SubGraphView : GraphInspector |
10 | 11 | {
|
11 | 12 | protected SubGraph SubGraph => target as SubGraph;
|
12 | 13 | protected SubGraphPortSchema Schema => SubGraph.Schema;
|
@@ -40,19 +41,22 @@ private VisualElement DrawSchemaControlGUI()
|
40 | 41 | schemaField.RegisterCallback<ChangeEvent<Object>>((e) =>
|
41 | 42 | {
|
42 | 43 | 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) |
45 | 52 | {
|
46 |
| - if (prevSchemaValue != null) |
47 |
| - prevSchemaValue.OnPortsUpdated -= SubGraph.NotifyPortsChanged; |
48 |
| - schemaControls.visible = false; |
49 |
| - schemaControls.Clear(); |
| 53 | + schemaControls.Hide(); |
50 | 54 | }
|
51 |
| - else if (!schemaControls.visible && Schema != null) |
| 55 | + else |
52 | 56 | {
|
53 |
| - Schema.OnPortsUpdated += SubGraph.NotifyPortsChanged; |
| 57 | + newSchemaValue.OnPortsUpdated += SubGraph.NotifyPortsChanged; |
54 | 58 | schemaControls.Add(SubGraphSerializer.SchemaGUIUtil.DrawSchemaPortControlGUI());
|
55 |
| - schemaControls.visible = true; |
| 59 | + schemaControls.Show(); |
56 | 60 | }
|
57 | 61 | });
|
58 | 62 |
|
|
0 commit comments