Skip to content

Commit 4cb2682

Browse files
committed
changed variable/setMultiply to variable/set
1 parent fe04297 commit 4cb2682

14 files changed

Lines changed: 98 additions & 115 deletions

File tree

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Flow/OnceUnitExport.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Unity.VisualScripting;
33
using UnityEditor;
4+
using UnityGLTF.Interactivity.Export;
45
using UnityGLTF.Interactivity.Schema;
56

67
namespace UnityGLTF.Interactivity.VisualScripting.Export
@@ -37,22 +38,18 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
3738
// Once.After flow to Branch when true
3839
branch.FlowOut(Flow_BranchNode.IdFlowOutTrue).MapToControlOutput(once.after);
3940

40-
var setVar = unitExporter.CreateNode<Variable_SetNode>();
41-
42-
setVar.Configuration["variable"].Value = varIndex;
43-
setVar.ValueInConnection[Variable_SetNode.IdInputValue].Value = true;
41+
var setVar = VariablesHelpers.SetVariable(unitExporter, varIndex, out var setVarSocket, out var setVarFlowIn, out var setVarFlowOut);
42+
setVarSocket.SetValue(true);
4443
// Set OnceVariable to true when Branch is false
45-
branch.FlowOut(Flow_BranchNode.IdFlowOutFalse).ConnectToFlowDestination(setVar.FlowIn(Variable_SetNode.IdFlowIn));
44+
branch.FlowOut(Flow_BranchNode.IdFlowOutFalse).ConnectToFlowDestination(setVarFlowIn);
4645
// Map once.once out flow to SetVariable outflow
47-
setVar.FlowOut(Variable_SetNode.IdFlowOut).MapToControlOutput(once.once);
46+
setVarFlowOut.MapToControlOutput(once.once);
4847

4948
if (once.reset.hasAnyConnection)
5049
{
51-
var resetVar = unitExporter.CreateNode<Variable_SetNode>();
52-
53-
resetVar.Configuration["variable"].Value = varIndex;
54-
resetVar.ValueInConnection[Variable_SetNode.IdInputValue].Value = false;
55-
resetVar.FlowIn(Variable_SetNode.IdFlowIn).MapToControlInput(once.reset);
50+
var resetVar = VariablesHelpers.SetVariable(unitExporter, varIndex, out var setVarResetSocket, out var setVarResetFlowIn, out var setVarResetFlowOut);
51+
setVarResetSocket.SetValue(false);
52+
setVarResetFlowIn.MapToControlInput(once.reset);
5653
}
5754
return true;
5855
}

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Flow/SelectOnFlowUnitExporter.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
4141

4242
for (int i = 0; i < unit.branchCount; i++)
4343
{
44-
var setVar = VariablesHelpersVS.SetVariable(unitExporter, varIndex, unit.valueInputs[i], unit.controlInputs[i], unit.exit);
44+
var setVar = VariablesHelpers.SetVariable(unitExporter, varIndex, out var setVarSocket, out var setVarFlowIn, out var setVarFlowOut);
4545
setVarNodes.Add(setVar);
46-
setVar.ValueIn(Variable_SetNode.IdInputValue).socket.Value.Type = -1;
46+
setVarFlowIn.MapToControlInput(unit.controlInputs[i]);
47+
setVarFlowOut.MapToControlOutput(unit.exit);
48+
setVarSocket.MapToInputPort(unit.valueInputs[i]);
49+
setVarSocket.socket.Value.Type = -1;
4750
}
4851

4952
void PostTypeResolving(bool lastTry = false)
5053
{
5154
int typeIndex = -1;
5255
foreach (var setVarNode in setVarNodes)
5356
{
54-
typeIndex = unitExporter.vsExportContext.GetValueTypeForInput(setVarNode, Variable_SetNode.IdInputValue);
57+
typeIndex = unitExporter.vsExportContext.GetValueTypeForInput(setVarNode, setVarNode.FirstValueIn().socket.Key);
5558
if (typeIndex != -1)
5659
break;
5760
}
@@ -69,7 +72,7 @@ void PostTypeResolving(bool lastTry = false)
6972
getVar.ValueOut(Variable_GetNode.IdOutputValue).ExpectedType(ExpectedType.GtlfType(typeIndex));
7073
foreach (var n in setVarNodes)
7174
{
72-
n.ValueIn(Variable_SetNode.IdInputValue).SetType(TypeRestriction.LimitToType(typeIndex));
75+
n.FirstValueIn().SetType(TypeRestriction.LimitToType(typeIndex));
7376
}
7477
}
7578

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Helpers/VariablesHelpersVS.cs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,28 @@ public class VariablesHelpersVS : VariablesHelpers
88
{
99
public static GltfInteractivityExportNode SetVariableStaticValue(INodeExporter unitExporter, int id, object value, ControlInput flowIn, ControlOutput flowOut)
1010
{
11-
var node = unitExporter.CreateNode<Variable_SetNode>();
12-
13-
var variableType = unitExporter.Context.variables[id].Type;
14-
node.FlowIn(Variable_SetNode.IdFlowIn).MapToControlInput(flowIn);
15-
node.FlowOut(Variable_SetNode.IdFlowOut).MapToControlOutput(flowOut);
16-
node.ValueIn(Variable_SetNode.IdInputValue).SetValue(value).SetType(TypeRestriction.LimitToType(variableType));
17-
18-
node.Configuration["variable"].Value = id;
11+
var node = SetVariableStaticValue(unitExporter, id, value, out var flowInSocket, out var flowOutScoket);
12+
flowInSocket.MapToControlInput(flowIn);
13+
flowOutScoket.MapToControlOutput(flowOut);
1914
return node;
2015
}
2116

22-
2317
public static GltfInteractivityExportNode SetVariable(INodeExporter unitExporter, int id, ValueInput value, ControlInput flowIn, ControlOutput flowOut)
2418
{
25-
var node = unitExporter.CreateNode<Variable_SetNode>();
19+
var node = SetVariable(unitExporter, id, out var valueSocket, out var flowInSocket, out var flowOutSocket);
20+
flowInSocket.MapToControlInput(flowIn);
21+
flowOutSocket.MapToControlOutput(flowOut);
22+
valueSocket.MapToInputPort(value);
2623

27-
var variableType = unitExporter.Context.variables[id].Type;
28-
node.FlowIn(Variable_SetNode.IdFlowIn).MapToControlInput(flowIn);
29-
node.FlowOut(Variable_SetNode.IdFlowOut).MapToControlOutput(flowOut);
30-
node.ValueIn(Variable_SetNode.IdInputValue).MapToInputPort(value).SetType(TypeRestriction.LimitToType(variableType));
31-
32-
node.Configuration["variable"].Value = id;
3324
return node;
3425
}
3526

3627
public static GltfInteractivityExportNode SetVariable(INodeExporter unitExporter, int id, ValueOutRef valueSource, ControlInput flowIn, ControlOutput flowOut)
3728
{
38-
var node = unitExporter.CreateNode<Variable_SetNode>();
39-
40-
var variableType = unitExporter.Context.variables[id].Type;
41-
node.FlowIn(Variable_SetNode.IdFlowIn).MapToControlInput(flowIn);
42-
node.FlowOut(Variable_SetNode.IdFlowOut).MapToControlOutput(flowOut);
43-
node.ValueIn(Variable_SetNode.IdInputValue).ConnectToSource(valueSource)
44-
.SetType(TypeRestriction.LimitToType(variableType));
45-
node.Configuration["variable"].Value = id;
29+
var node = SetVariable(unitExporter, id, out var valueSocket, out var flowInSocket, out var flowOutSocket);
30+
flowInSocket.MapToControlInput(flowIn);
31+
flowOutSocket.MapToControlOutput(flowOut);
32+
valueSocket.ConnectToSource(valueSource);
4633
return node;
4734
}
4835

Editor/Scripts/Interactivity/VisualScriptingExport/UnitExporters/Variables/SetVariableUnitExport.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Unity.VisualScripting;
44
using UnityEditor;
5+
using UnityGLTF.Interactivity.Export;
56
using UnityGLTF.Interactivity.Schema;
67

78
namespace UnityGLTF.Interactivity.VisualScripting.Export
@@ -20,19 +21,18 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
2021
{
2122
var unit = unitExporter.unit as SetVariable;
2223

23-
var node = unitExporter.CreateNode<Variable_SetNode>();
2424

2525
var variableIndex = unitExporter.vsExportContext.AddVariableIfNeeded(unit);
26+
var node = VariablesHelpers.SetVariable(unitExporter, variableIndex, out var valueSocket, out var flowIn, out var flowOut);
2627

2728
var variableType = unitExporter.vsExportContext.variables[variableIndex].Type;
2829
unitExporter.MapOutFlowConnectionWhenValid(unit.assigned, Variable_SetNode.IdFlowOut, node);
2930

3031
node.Configuration["variable"].Value = variableIndex;
31-
32-
unitExporter.MapInputPortToSocketName(unit.input, Variable_SetNode.IdInputValue, node);
33-
unitExporter.MapInputPortToSocketName(unit.assign, Variable_SetNode.IdFlowIn, node);
3432

35-
node.ValueIn(Variable_SetNode.IdInputValue).SetType(TypeRestriction.LimitToType(variableType));
33+
valueSocket.MapToInputPort(unit.input);
34+
flowIn.MapToControlInput(unit.assign);
35+
3636
bool inputIsLiteral = !unit.input.hasDefaultValue && unit.input.hasValidConnection &&
3737
(unit.input.connections.First().source.unit is Literal
3838
|| unit.input.connections.First().source.unit is Null);
@@ -45,7 +45,7 @@ public bool InitializeInteractivityNodes(UnitExporter unitExporter)
4545

4646
var getVarNode = unitExporter.CreateNode<Variable_GetNode>();
4747

48-
getVarNode.Configuration["variable"].Value = variableIndex;
48+
getVarNode.Configuration[Variable_GetNode.IdConfigVarIndex].Value = variableIndex;
4949
unitExporter.MapValueOutportToSocketName(unit.output, Variable_GetNode.IdOutputValue, getVarNode);
5050

5151
getVarNode.OutputValueSocket[Variable_GetNode.IdOutputValue].expectedType = ExpectedType.GtlfType(variableType);

Runtime/Scripts/Interactivity/Export/CleanUp/VariableGetOnlyToValueInputCleanUp.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ private static void Register()
1919
public void OnCleanUp(CleanUpTask task)
2020
{
2121
var varGetNodes = task.context.Nodes.FindAll(node => node.Schema is Variable_GetNode);
22-
var varSetNodes = task.context.Nodes.FindAll(node => node.Schema is Variable_SetNode);
23-
var varSetMultiNodes = task.context.Nodes.FindAll(node => node.Schema is Variable_SetMultipleNode);
22+
var varSetMultiNodes = task.context.Nodes.FindAll(node => node.Schema is Variable_SetNode);
2423
var varSetIntNodes = task.context.Nodes.FindAll(node => node.Schema is Variable_InterpolateNode);
2524

26-
var varSetAndIntNodes = varSetNodes.Concat(varSetIntNodes);
2725

2826
var varIdsToRemove = new HashSet<int>();
2927
var varGetNodesToRemove = new List<GltfInteractivityExportNode>();
@@ -34,13 +32,13 @@ public void OnCleanUp(CleanUpTask task)
3432

3533
var isInMulti = varSetMultiNodes.Any(n =>
3634
{
37-
var arr = n.Configuration[Variable_SetMultipleNode.IdConfigVarIndices].Value as int[];
35+
var arr = n.Configuration[Variable_SetNode.IdConfigVarIndices].Value as int[];
3836
return arr.Contains(varId);
3937
});
4038
if (isInMulti)
4139
continue;
4240

43-
if (!varSetAndIntNodes.Any(n => n.Configuration[Variable_SetNode.IdConfigVarIndex].Value.Equals(varId)))
41+
if (!varSetIntNodes.Any(n => n.Configuration[Variable_InterpolateNode.IdConfigVariable].Value.Equals(varId)))
4442
varIdsToRemove.Add(varId);
4543
}
4644

Runtime/Scripts/Interactivity/Export/GltfInteractivityExportNode.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ public FlowOutRef FlowOut()
104104
throw new System.Exception("No default 'out' socket found in output flow sockets. Schema: " + Schema.Op);
105105
}
106106

107+
public ValueInRef FirstValueIn()
108+
{
109+
var firstItem = ValueInConnection.FirstOrDefault();
110+
if (firstItem.Value == null)
111+
return null;
112+
113+
return new ValueInRef(this, firstItem);
114+
}
107115

108116
public ValueOutRef FirstValueOut()
109117
{

Runtime/Scripts/Interactivity/Export/Helpers/FlowHelpers.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void CreateCustomForLoopWithFlowStep(INodeExporter exporter,
2121
var startSequ = exporter.CreateNode<Flow_SequenceNode>();
2222
flowIn = startSequ.FlowIn(Flow_SequenceNode.IdFlowIn);
2323

24-
var setStartIndexVar = VariablesHelpers.SetVariable(exporter, indexVar);
24+
var setStartIndexVar = VariablesHelpers.SetVariable(exporter, indexVar, out startIndex, out _, out _);
2525
var branch = exporter.CreateNode<Flow_BranchNode>();
2626

2727
startSequ.FlowOut("1").ConnectToFlowDestination(setStartIndexVar.FlowIn(Variable_SetNode.IdFlowIn));
@@ -31,8 +31,6 @@ public static void CreateCustomForLoopWithFlowStep(INodeExporter exporter,
3131
loopBodyOut = branch.FlowOut(Flow_BranchNode.IdFlowOutTrue);
3232

3333

34-
startIndex = setStartIndexVar.ValueIn(Variable_SetNode.IdInputValue);
35-
3634
var ascendingCondition = exporter.CreateNode<Math_LeNode>();
3735
startIndex = startIndex.Link(ascendingCondition.ValueIn("a"));
3836
endIndex = ascendingCondition.ValueIn("b");
@@ -45,8 +43,8 @@ public static void CreateCustomForLoopWithFlowStep(INodeExporter exporter,
4543
step = addNode.ValueIn("b").SetType(TypeRestriction.LimitToInt);
4644
addNode.FirstValueOut().ExpectedType(ExpectedType.Int);
4745

48-
var setCurrentIndexVar = VariablesHelpers.SetVariable(exporter, indexVar);
49-
setCurrentIndexVar.ValueIn(Variable_SetNode.IdInputValue).ConnectToSource(addNode.FirstValueOut());
46+
var setCurrentIndexVar = VariablesHelpers.SetVariable(exporter, indexVar, out var setCurrentIndexVarSocket, out _, out _);
47+
setCurrentIndexVarSocket.ConnectToSource(addNode.FirstValueOut());
5048

5149
var sequence = exporter.CreateNode<Flow_SequenceNode>();
5250

@@ -83,15 +81,13 @@ public static void CreateCustomForLoop(INodeExporter exporter,
8381
"ForLoopIndex" + System.Guid.NewGuid().ToString(), 0, GltfTypes.Int);
8482

8583
var whileNode = exporter.CreateNode<Flow_WhileNode>();
86-
var setStartIndexVar = VariablesHelpers.SetVariable(exporter, indexVar);
84+
var setStartIndexVar = VariablesHelpers.SetVariable(exporter, indexVar, out startIndex, out _, out _);
8785

8886
flowIn = setStartIndexVar.FlowIn(Variable_SetNode.IdFlowIn);
8987
setStartIndexVar.FlowOut(Variable_SetNode.IdFlowOut)
9088
.ConnectToFlowDestination(whileNode.FlowIn(Flow_WhileNode.IdFlowIn));
9189
completed = whileNode.FlowOut(Flow_WhileNode.IdCompleted);
9290

93-
startIndex = setStartIndexVar.ValueIn(Variable_SetNode.IdInputValue);
94-
9591
var ascendingCondition = exporter.CreateNode<Math_LeNode>();
9692
startIndex = startIndex.Link(ascendingCondition.ValueIn("a"));
9793
endIndex = ascendingCondition.ValueIn("b");
@@ -104,8 +100,8 @@ public static void CreateCustomForLoop(INodeExporter exporter,
104100
step = addNode.ValueIn("b").SetType(TypeRestriction.LimitToInt);
105101
addNode.FirstValueOut().ExpectedType(ExpectedType.Int);
106102

107-
var setCurrentIndexVar = VariablesHelpers.SetVariable(exporter, indexVar);
108-
setCurrentIndexVar.ValueIn(Variable_SetNode.IdInputValue).ConnectToSource(addNode.FirstValueOut());
103+
var setCurrentIndexVar = VariablesHelpers.SetVariable(exporter, indexVar, out var setCurrentIndexVarSocket, out _, out _);
104+
setCurrentIndexVarSocket.ConnectToSource(addNode.FirstValueOut());
109105

110106
var sequence = exporter.CreateNode<Flow_SequenceNode>();
111107
whileNode.FlowOut(Flow_WhileNode.IdLoopBody)
@@ -136,21 +132,20 @@ public static void CreateConditionalWaiting(INodeExporter exporter,
136132
bool waitForTrue,
137133
out FlowOutRef flowOutWhenDone)
138134
{
139-
var setVarStart = exporter.CreateNode<Variable_SetNode>();
140-
var setVarFinish = exporter.CreateNode<Variable_SetNode>();
141135
var getVar = exporter.CreateNode<Variable_GetNode>();
142136
var varId = exporter.Context.AddVariableWithIdIfNeeded("waitWhile" + System.Guid.NewGuid(), false,
143137
GltfTypes.Bool);
144138
var tick = exporter.CreateNode<Event_OnTickNode>();
145139
var branch = exporter.CreateNode<Flow_BranchNode>();
146140
var waitingBranch = exporter.CreateNode<Flow_BranchNode>();
147141

148-
setVarStart.Configuration[Variable_SetNode.IdConfigVarIndex].Value = varId;
149-
setVarFinish.Configuration[Variable_SetNode.IdConfigVarIndex].Value = varId;
150-
setVarFinish.ValueIn(Variable_SetNode.IdInputValue).SetValue(false);
151-
setVarStart.ValueIn(Variable_SetNode.IdInputValue).SetValue(true);
142+
var setVarStart = VariablesHelpers.SetVariable(exporter, varId, out var setVarStartSocket, out _, out _);
143+
setVarStartSocket.SetValue(true);
144+
145+
var setVarFinish = VariablesHelpers.SetVariable(exporter, varId, out var setVarFinishSocket, out _, out _);
146+
setVarFinishSocket.SetValue(false);
152147

153-
getVar.Configuration[Variable_SetNode.IdConfigVarIndex].Value = varId;
148+
getVar.Configuration[Variable_GetNode.IdConfigVarIndex].Value = varId;
154149

155150
flowIn = setVarStart.FlowIn(Variable_SetNode.IdFlowIn);
156151
setVarStart.FlowOut(Variable_SetNode.IdFlowOut)

0 commit comments

Comments
 (0)