Skip to content

Commit

Permalink
Update If.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
S2NX7 committed Aug 23, 2023
1 parent d906920 commit 2c3e6b1
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions Runtime/Fundamentals/Nodes/Logic/Branching/If.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using UnityEngine;
using Unity.VisualScripting;
using System.Collections;
using System;

namespace Bolt.Addons.Community.Fundamentals
namespace Unity.VisualScripting.Community
{
[UnitTitle("If")]
[UnitCategory("Community/Control")]
[TypeIcon(typeof(Unity.VisualScripting.If))]
public class If : Unit
[RenamedFrom("Bolt.Addons.Community.Fundamentals.If")]
[RenamedFrom("Bolt.Addons.Community.Fundamentals.BetterIf")]
public class BetterIf : Unit
{
[DoNotSerialize]
[PortLabelHidden]
Expand All @@ -21,11 +25,12 @@ public class If : Unit
[DoNotSerialize]
public ControlOutput False;
[DoNotSerialize]
[PortLabel("Next")]
public ControlOutput Finished;

protected override void Definition()
{
In = ControlInput(nameof(In), Enter);
In = ControlInputCoroutine(nameof(In), Enter, EnterCoroutine);
True = ControlOutput(nameof(True));
False = ControlOutput(nameof(False));
Finished = ControlOutput(nameof(Finished));
Expand All @@ -35,32 +40,40 @@ protected override void Definition()
Succession(In, True);
Succession(In, False);
Succession(In, Finished);
Requirement(Condition, In);
}

private ControlOutput Enter(Flow flow)
private IEnumerator EnterCoroutine(Flow flow)
{
bool condition = flow.GetValue<bool>(Condition);

if (flow.isCoroutine)
if (condition)
{
GraphReference reference = flow.stack.ToReference();
Flow _flow = Flow.New(reference);
_flow.StartCoroutine(Finished);
yield return True;
}
else
{
flow.Invoke(Finished);
yield return False;
}

yield return Finished;
}

private ControlOutput Enter(Flow flow)
{
bool condition = flow.GetValue<bool>(Condition);

if (condition)
{
return True;
flow.Invoke(True);
}
else
{
return False;
flow.Invoke(False);
}


return Finished;

}
}
}
}

0 comments on commit 2c3e6b1

Please sign in to comment.