diff options
| author | yum <yum.food.vr@gmail.com> | 2026-01-01 17:19:27 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-01-01 17:19:27 -0800 |
| commit | 2b5a62829cd53139d62b2f3ffa3a56f600e43733 (patch) | |
| tree | 81d74302ce9ac7ec5d8688bc3954bd061cfed805 /Scripts/Fold/Editor/KeyframeNodeView.cs | |
| parent | d06bf919efd978f018ddcb4e2d5807a7783fcc84 (diff) | |
Fold: Introduce keyframe node
Connect a GameObject and a chain of FoldNodes, then click the keyframe
button. Actual keyframe logic not yet implemented.
Diffstat (limited to 'Scripts/Fold/Editor/KeyframeNodeView.cs')
| -rw-r--r-- | Scripts/Fold/Editor/KeyframeNodeView.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Scripts/Fold/Editor/KeyframeNodeView.cs b/Scripts/Fold/Editor/KeyframeNodeView.cs new file mode 100644 index 0000000..75c7bfa --- /dev/null +++ b/Scripts/Fold/Editor/KeyframeNodeView.cs @@ -0,0 +1,45 @@ +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); + } +} |
