Skip to content

Commit

Permalink
Added workaround for node view with list bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alelievr committed Jul 14, 2021
1 parent eb3d182 commit 35a0514
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Assets/Examples/DefaultNodes/Nodes/ListNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GraphProcessor;
using System.Linq;

[System.Serializable, NodeMenuItem("Custom/List")]
public class ListNode : BaseNode
{
[Output(name = "Out")]
public Vector4 output;

[Input(name = "In"), SerializeField]
public Vector4 input;

public List<GameObject> objs = new List<GameObject>();

public override string name => "List";

protected override void Process()
{
output = input;
}
}
11 changes: 11 additions & 0 deletions Assets/Examples/DefaultNodes/Nodes/ListNode.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ void UpdateTitle()
title = (nodeTarget.GetCustomName() == null) ? nodeTarget.GetType().Name : nodeTarget.GetCustomName();
}

public void UpdateNodeSerializedPropertyBindings()
{

}

void InitializeSettings()
{
// Initialize settings button:
Expand Down Expand Up @@ -270,6 +265,21 @@ void OnGeometryChanged(GeometryChangedEvent evt)
settingsContainer.style.left = settingsButtonLayout.xMin - layout.width + 20f;
}
}

// Workaround for bug in GraphView that makes the node selection border way too big
VisualElement selectionBorder, nodeBorder;
internal void EnableSyncSelectionBorderHeight()
{
if (selectionBorder == null || nodeBorder == null)
{
selectionBorder = this.Q("selection-border");
nodeBorder = this.Q("node-border");

schedule.Execute(() => {
selectionBorder.style.height = nodeBorder.localBound.height;
}).Every(17);
}
}

void CreateSettingButton()
{
Expand Down Expand Up @@ -681,7 +691,6 @@ protected virtual void DrawDefaultInspector(bool fromInspector = false)
continue;
}


//skip if the field is an input/output and not marked as SerializedField
bool hasInputAttribute = field.GetCustomAttribute(typeof(InputAttribute)) != null;
bool hasInputOrOutputAttribute = hasInputAttribute || field.GetCustomAttribute(typeof(OutputAttribute)) != null;
Expand Down Expand Up @@ -852,6 +861,9 @@ protected VisualElement AddControlField(FieldInfo field, string label = null, bo
element.AddToClassList("DrawerField_2020_3");
#endif

if (typeof(IList).IsAssignableFrom(field.FieldType))
EnableSyncSelectionBorderHeight();

element.RegisterValueChangeCallback(e => {
UpdateFieldVisibility(field.Name, field.GetValue(nodeTarget));
valueChangedCallback?.Invoke();
Expand Down

0 comments on commit 35a0514

Please sign in to comment.