Skip to content

Commit

Permalink
Fix #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero committed Jan 3, 2025
1 parent 8830720 commit efbd52b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions Unity/Assets/Actions/ActionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ bool shouldForce()
public void SetForce(float afterSeconds, string query, string? state, bool ephemeralContext = false)
=> SetForce(afterSeconds, () => query, () => state, ephemeralContext);

private void SendForce()
public void Force()
{
if (CurrentState != State.Registered) return;

CurrentState = State.Forced;
_shouldForceFunc = null;
WebsocketConnection.TrySend(new ActionsForce(_forceQueryGetter!(), _forceStateGetter!(), _forceEphemeralContext, _actions));
Expand Down Expand Up @@ -238,6 +240,17 @@ private void OnDestroy()
End();
}

public void End()
{
if (CurrentState >= State.Ended) return;

NeuroActionHandler.UnregisterActions(_actions);
_shouldForceFunc = null;
_shouldEndFunc = null;
CurrentState = State.Ended;
Destroy(this);
}

#endregion

#region Handling
Expand All @@ -251,7 +264,7 @@ public ExecutionResult Result(ExecutionResult result)
if (CurrentState >= State.Ended) throw new InvalidOperationException("Cannot handle a result after the ActionWindow has ended.");

if (result.Successful) End();
// else if (CurrentState == State.Forced) SendForce(); // Vedal is now responsible for retrying forces
// else if (CurrentState == State.Forced) Force(); // Vedal is now responsible for retrying forces

return result;
}
Expand All @@ -262,7 +275,7 @@ private void Update()

if (_shouldForceFunc != null && _shouldForceFunc())
{
SendForce();
Force();
}

if (_shouldEndFunc != null && _shouldEndFunc())
Expand All @@ -271,15 +284,6 @@ private void Update()
}
}

private void End()
{
NeuroActionHandler.UnregisterActions(_actions);
_shouldForceFunc = null;
_shouldEndFunc = null;
CurrentState = State.Ended;
Destroy(this);
}

#endregion
}
}
2 changes: 1 addition & 1 deletion Unity/Assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Neuro SDK",
"description": "Neuro SDK for Unity",
"author": "Vedal AI",
"version": "1.1.6",
"version": "1.1.7",
"unity": "2022.3",
"dependencies": {
"com.cysharp.unitask": "2.5.10",
Expand Down

0 comments on commit efbd52b

Please sign in to comment.