summaryrefslogtreecommitdiffstats
path: root/Scripts
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-01-02 03:06:28 -0800
committeryum <yum.food.vr@gmail.com>2026-01-02 03:06:28 -0800
commit4e625ab92e96f71c803d2d92c5213d5e933ab116 (patch)
tree6303c124f4f4b89daff28930788b45153d78217f /Scripts
parent2b5a62829cd53139d62b2f3ffa3a56f600e43733 (diff)
Fold: Keyframe node shows errors when input wrong type
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/Fold/Editor/KeyframeNodeView.cs102
1 files changed, 75 insertions, 27 deletions
diff --git a/Scripts/Fold/Editor/KeyframeNodeView.cs b/Scripts/Fold/Editor/KeyframeNodeView.cs
index 75c7bfa..c35b215 100644
--- a/Scripts/Fold/Editor/KeyframeNodeView.cs
+++ b/Scripts/Fold/Editor/KeyframeNodeView.cs
@@ -6,40 +6,88 @@ using System.Linq;
[NodeCustomEditor(typeof(KeyframeNode))]
public class KeyframeNodeView : BaseNodeView
{
- Button generateButton;
+ Button generateButton;
+ const string ERROR_MSG_NO_GAMEOBJECT = "GameObject input has wrong type";
+ const string ERROR_MSG_NO_RENDERER = "GameObject must have a MeshRenderer component";
- public override void Enable()
+ public override void Enable()
+ {
+ var node = nodeTarget as KeyframeNode;
+
+ generateButton = new Button(OnGenerateClick)
{
- var node = nodeTarget as KeyframeNode;
+ text = "Generate Keyframe"
+ };
+ controlsContainer.Add(generateButton);
+
+ // Update validation on connectivity changes.
+ onPortConnected += _ => Validate();
+ onPortDisconnected += _ => Validate();
+
+ // Check periodically in case the value in the GameObjectNode changes.
+ // Best effort.
+ schedule.Execute(Validate).Every(200);
- generateButton = new Button(() => {
- Debug.Log($"Generating Keyframe for '{node.targetObject.name}' using fold data from '{node.foldData.name}'");
- })
- {
- text = "Generate Keyframe"
- };
+ Validate();
+ }
- controlsContainer.Add(generateButton);
+ void OnGenerateClick()
+ {
+ var go = GetConnectedGameObject();
+ // The button should be disabled if invalid, but safety check:
+ if (go == null || go.GetComponent<MeshRenderer>() == null) return;
- // 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();
+ var foldNode = GetConnectedFoldNode();
+ Debug.Log($"Generating Keyframe for '{go.name}' using Fold Data: {(foldNode != null ? foldNode.name : "None")}");
+ // TODO
+ }
- // Initial state check.
- // We use schedule to ensure ports are fully initialized before checking.
- schedule.Execute(RefreshButtonState).ExecuteLater(0);
+ GameObject GetConnectedGameObject()
+ {
+ var portView = GetFirstPortViewFromFieldName(nameof(KeyframeNode.targetObject));
+ if (portView == null || portView.GetEdges().Count == 0) return null;
+
+ var edge = portView.GetEdges().First();
+ var outputNode = (edge.output.node as BaseNodeView)?.nodeTarget;
+
+ if (outputNode is GameObjectNode goNode) {
+ return goNode.output;
}
+ return null;
+ }
- 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);
+ BaseFoldNode GetConnectedFoldNode()
+ {
+ var portView = GetFirstPortViewFromFieldName(nameof(KeyframeNode.foldData));
+ if (portView == null || portView.GetEdges().Count == 0) return null;
+
+ var edge = portView.GetEdges().First();
+ return (edge.output.node as BaseNodeView)?.nodeTarget as BaseFoldNode;
+ }
+
+ void Validate()
+ {
+ var go = GetConnectedGameObject();
+ bool hasTargetConnection = GetFirstPortViewFromFieldName(nameof(KeyframeNode.targetObject))?.GetEdges().Count > 0;
+ bool hasFoldConnection = GetFirstPortViewFromFieldName(nameof(KeyframeNode.foldData))?.GetEdges().Count > 0;
+
+ // Clear previous error.
+ RemoveMessageView(ERROR_MSG_NO_RENDERER);
+ RemoveMessageView(ERROR_MSG_NO_GAMEOBJECT);
+
+ bool isValid = false;
+ if (hasTargetConnection) {
+ if (go == null) {
+ // Has connection but it's not a GameObject.
+ AddMessageView(ERROR_MSG_NO_GAMEOBJECT, NodeMessageType.Error);
+ } else if (go.GetComponent<MeshRenderer>() == null) {
+ AddMessageView(ERROR_MSG_NO_RENDERER, NodeMessageType.Error);
+ } else {
+ isValid = true;
+ }
}
+
+ generateButton.SetEnabled(isValid && hasFoldConnection);
+ }
}
+