Skip to content

Commit c6abcb5

Browse files
committed
Fix visibleIf attribute
1 parent a42b533 commit c6abcb5

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using GraphProcessor;
5+
using System.Linq;
6+
7+
[System.Serializable, NodeMenuItem("Custom/VisibleIfAttributeNode")]
8+
public class VisibleIfAttributeNode : BaseNode
9+
{
10+
public enum Test1
11+
{
12+
A,
13+
B,
14+
C,
15+
D
16+
}
17+
18+
public enum Test2
19+
{
20+
T1,
21+
T2,
22+
T3,
23+
}
24+
25+
public Test1 t1;
26+
27+
[VisibleIf(nameof(t1), Test1.A)]
28+
public float f1;
29+
[VisibleIf(nameof(t1), Test1.B)]
30+
public int f2;
31+
32+
[VisibleIf(nameof(t1), Test1.C)]
33+
public string s1;
34+
[VisibleIf(nameof(t1), Test1.C)]
35+
public Test2 t2;
36+
37+
[Input(name = "In")]
38+
public float input;
39+
40+
[Output(name = "Out")]
41+
public float output;
42+
43+
public override string name => "VisibleIfAttributeNode";
44+
45+
protected override void Process()
46+
{
47+
output = input * 42;
48+
}
49+
}

Assets/Examples/DefaultNodes/Nodes/VisibleIfAttributeNode.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ private void AddEmptyField(FieldInfo field, bool fromInspector)
747747

748748
void UpdateFieldVisibility(string fieldName, object newValue)
749749
{
750+
if (newValue == null)
751+
return;
750752
if (visibleConditions.TryGetValue(fieldName, out var list))
751753
{
752754
foreach (var elem in list)
@@ -839,6 +841,10 @@ protected VisualElement AddControlField(FieldInfo field, string label = null, bo
839841
var element = new PropertyField(FindSerializedProperty(field.Name), showInputDrawer ? "" : label);
840842
element.Bind(owner.serializedGraph);
841843

844+
element.RegisterValueChangeCallback(e => {
845+
UpdateFieldVisibility(field.Name, field.GetValue(nodeTarget));
846+
});
847+
842848
// Disallow picking scene objects when the graph is not linked to a scene
843849
if (element != null && !owner.graph.IsLinkedToScene())
844850
{

0 commit comments

Comments
 (0)