Skip to content

Commit db05baa

Browse files
Merge pull request #85 from PaulNonatomic/develop
Develop
2 parents 1e87ead + 138f74e commit db05baa

7 files changed

Lines changed: 28 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## [0.6.5-beta] - Aug 16, 2024
4+
- Updated frame delay of DelayState transition to 0
5+
- Fix for add nodes multiple times when entering runtime
6+
- Fix for unuseful error thrown when sub state-machines ref is missing
7+
38
## [0.6.4-beta] - Aug 12, 2024
49
- Fix for rogue tilda
510
- Added relay states

Editor/NodeGraph/NodeGraphStateManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public virtual void SaveState()
7777

7878
public void SetModel(NodeGraphDataModel model)
7979
{
80+
if (!model) return;
81+
8082
Model = model;
8183
SaveState();
8284
}

Editor/NodeGraph/NodeGraphView.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public NodeGraphView(string id)
3333

3434
public virtual void PopulateGraph(NodeGraphDataModel model)
3535
{
36-
if (!model) return;
37-
3836
StateManager.SetModel(model);
3937
ClearGraph();
4038
}
@@ -117,7 +115,7 @@ private void HandleModelChanged(NodeGraphDataModel model)
117115
PopulateGraph(model);
118116
}
119117

120-
private void ClearGraph()
118+
protected virtual void ClearGraph()
121119
{
122120
DeleteElements(graphElements);
123121
}

Editor/StateGraph/VisualElements/StateGraphView.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ public void PopulateGraph(NodeGraphDataModel model, bool recentre)
4848
_toolBar.SetModel(stateModel);
4949
_footerBar.SetGridPosition(StateManager.GridPosition);
5050
_footerBar.SetModel(stateModel);
51-
51+
5252
base.PopulateGraph(model);
5353
AddEntryNode(stateModel);
5454

55+
//A delay is required to allow the entry node time to be added
5556
EditorApplication.delayCall += () =>
5657
{
58+
//It's possible that the delayCall is invoked multiple times when entering run time
59+
//This just prevents adding the nodes multiple times
60+
if (nodes.ToList().Count > 0) return;
61+
5762
AddNodes(stateModel);
5863
AddEdges(stateModel);
5964

Runtime/StateGraph/States/BaseSubStateMachineState.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,32 @@ public override void OnAwakeState()
2828

2929
public override void OnStartState()
3030
{
31-
SubStateMachine.Start();
31+
SubStateMachine?.Start();
3232
}
3333

3434
public override void OnEnterState()
3535
{
36+
if(SubStateMachine == null) return;
37+
3638
SubStateMachine.Model.SetParent(SubStateMachine.Model);
3739
SubStateMachine.OnComplete += OnSubStateComplete;
3840
SubStateMachine.Enter();
3941
}
4042

4143
public override void OnUpdateState()
4244
{
43-
SubStateMachine.Update();
45+
SubStateMachine?.Update();
4446
}
4547

4648
public override void OnFixedUpdateState()
4749
{
48-
SubStateMachine.FixedUpdate();
50+
SubStateMachine?.FixedUpdate();
4951
}
5052

5153
public override void OnExitState()
5254
{
55+
if(SubStateMachine == null) return;
56+
5357
SubStateMachine.OnComplete -= OnSubStateComplete;
5458
SubStateMachine.Exit();
5559
}
@@ -58,7 +62,7 @@ public override void OnDestroyState()
5862
{
5963
ReplaceModelWithOriginalModel();
6064

61-
SubStateMachine.OnDestroy();
65+
SubStateMachine?.OnDestroy();
6266
}
6367

6468
protected virtual void CreateStateMachine()

Runtime/StateGraph/States/DelayState.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nonatomic.VSM2.StateGraph.States
88
[NodeWidth(width:190), NodeColor(NodeColor.Teal), NodeIcon(NodeIcon.Clock)]
99
public class DelayState : BaseDelayState
1010
{
11-
[Transition]
11+
[Transition(frameDelay:0)]
1212
public event Action OnComplete;
1313

1414
[NonSerialized]
@@ -22,16 +22,14 @@ public override void OnEnterState()
2222
public override void OnUpdateState()
2323
{
2424
_elapsedTime += Time.deltaTime;
25-
26-
if (_elapsedTime >= Duration)
27-
{
28-
OnComplete?.Invoke();
29-
}
25+
26+
if (_elapsedTime < Duration) return;
27+
OnComplete?.Invoke();
3028
}
3129

3230
public override void OnExitState()
3331
{
34-
32+
//...
3533
}
3634
}
3735
}

Runtime/StateGraph/States/SubStateMachineState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Nonatomic.VSM2.StateGraph.States
55
{
66
public class SubStateMachineState : BaseSubStateMachineState
77
{
8-
[Transition]
8+
[Transition(frameDelay:0)]
99
public event Action OnComplete;
1010

1111
protected override void OnSubStateComplete(State state, StateMachineModel model)

0 commit comments

Comments
 (0)