using GraphProcessor; using UnityEngine.UIElements; using UnityEngine; using System.Linq; [NodeCustomEditor(typeof(KeyframeNode))] public class KeyframeNodeView : BaseNodeView { Button generateButton; public override void Enable() { var node = nodeTarget as KeyframeNode; generateButton = new Button(() => { Debug.Log($"Generating Keyframe for '{node.targetObject.name}' using fold data from '{node.foldData.name}'"); }) { text = "Generate Keyframe" }; controlsContainer.Add(generateButton); // Subscribe to connection events. This lets us disable the button when // the keyframe node is not in a valid state. onPortConnected += (p) => RefreshButtonState(); onPortDisconnected += (p) => RefreshButtonState(); // Initial state check. // We use schedule to ensure ports are fully initialized before checking. schedule.Execute(RefreshButtonState).ExecuteLater(0); } void RefreshButtonState() { if (generateButton == null) return; // Enable the keyframing button once both ports are connected. bool targetConnected = GetPortViewsFromFieldName(nameof(KeyframeNode.targetObject)) .Any(pv => pv.GetEdges().Count > 0); bool foldConnected = GetPortViewsFromFieldName(nameof(KeyframeNode.foldData)) .Any(pv => pv.GetEdges().Count > 0); generateButton.SetEnabled(targetConnected && foldConnected); } }