@@ -171,7 +171,7 @@ public static void UnHookStateExited(FSMData data, Action<PlayMakerFSM> onStateE
171
171
}
172
172
}
173
173
/// <summary>
174
- /// Hook that gets called when a state is entered by a transition (could be global or local). The transition from which it happened is passed into the action.
174
+ /// Hook that gets called when a state is entered by a transition (could be global or local). The transition from which it happened is passed into the action.
175
175
/// </summary>
176
176
/// <param name="data">The data necessary to find the fsm to be edited</param>
177
177
/// <param name="onStateEnteredFromTransition">The action that will be invoked when the state is entered, the parameter passed into the action is the fsm and the transition from which the state enter happened</param>
@@ -260,9 +260,30 @@ public static FSMHookHandle<Action<PlayMakerFSM, string>> CreateStateEnteredViaT
260
260
public static FSMHookHandle < Action < PlayMakerFSM , string > > CreateStateExitedViaTransitionHook ( FSMData data , Action < PlayMakerFSM , string > onStateExitViaTransition ) =>
261
261
new ( StateExitedViaTransitionData , data , onStateExitViaTransition ) ;
262
262
263
+ private static string GetSceneName ( Fsm self )
264
+ {
265
+ if ( self == null )
266
+ {
267
+ return "" ;
268
+ }
269
+ if ( self . Owner == null )
270
+ {
271
+ return "" ;
272
+ }
273
+ if ( self . Owner . gameObject == null )
274
+ {
275
+ return "" ;
276
+ }
277
+ if ( self . Owner . gameObject . scene == null )
278
+ {
279
+ return "" ;
280
+ }
281
+ return self . Owner . gameObject . scene . name ;
282
+ }
283
+
263
284
private static void EnterState ( Action < Fsm , FsmState > orig , Fsm self , FsmState state )
264
285
{
265
- string sceneName = self . GameObject . scene . name ;
286
+ string sceneName = GetSceneName ( self ) ;
266
287
string gameObject = self . GameObjectName ;
267
288
string fsmName = self . Name ;
268
289
string stateName = state . Name ;
@@ -279,23 +300,22 @@ private static void EnterState(Action<Fsm, FsmState> orig, Fsm self, FsmState st
279
300
{
280
301
onStateEnter_3 . TryInvokeActions ( self . FsmComponent ) ;
281
302
}
282
-
303
+
283
304
orig ( self , state ) ;
284
305
}
285
-
306
+
286
307
private static bool DoTransition ( Func < Fsm , FsmTransition , bool , bool > orig , Fsm self , FsmTransition transition , bool isGlobal )
287
308
{
288
309
// a check in the normal code
289
310
if ( transition . ToFsmState == null )
290
311
{
291
312
return orig ( self , transition , isGlobal ) ;
292
313
}
293
-
294
- string sceneName = self . GameObject . scene . name ;
314
+
315
+ string sceneName = GetSceneName ( self ) ;
295
316
string gameObject = self . GameObjectName ;
296
317
string fsmName = self . Name ;
297
318
298
-
299
319
if ( StateExitedViaTransitionData . TryGetValue ( new FSMData ( sceneName , gameObject , fsmName , self . ActiveStateName ) , out var onStateExitedViaTransition_1 ) )
300
320
{
301
321
onStateExitedViaTransition_1 . TryInvokeActions ( self . FsmComponent , transition . EventName ) ;
@@ -308,8 +328,7 @@ private static bool DoTransition(Func<Fsm, FsmTransition, bool, bool> orig, Fsm
308
328
{
309
329
onStateExitedViaTransition_3 . TryInvokeActions ( self . FsmComponent , transition . EventName ) ;
310
330
}
311
-
312
-
331
+
313
332
if ( StateEnteredFromTransitionData . TryGetValue ( new FSMData ( sceneName , gameObject , fsmName , transition . ToState ) , out var onStateEnteredFromTransition_1 ) )
314
333
{
315
334
onStateEnteredFromTransition_1 . TryInvokeActions ( self . FsmComponent , transition . EventName ) ;
@@ -322,14 +341,13 @@ private static bool DoTransition(Func<Fsm, FsmTransition, bool, bool> orig, Fsm
322
341
{
323
342
onStateEnteredFromTransition_3 . TryInvokeActions ( self . FsmComponent , transition . EventName ) ;
324
343
}
325
-
326
-
344
+
327
345
return orig ( self , transition , isGlobal ) ;
328
346
}
329
-
347
+
330
348
private static void ExitState ( Action < Fsm , FsmState > orig , Fsm self , FsmState state )
331
349
{
332
- string sceneName = self . GameObject . scene . name ;
350
+ string sceneName = GetSceneName ( self ) ;
333
351
string gameObject = self . GameObjectName ;
334
352
string fsmName = self . Name ;
335
353
string stateName = state . Name ;
@@ -346,7 +364,7 @@ private static void ExitState(Action<Fsm, FsmState> orig, Fsm self, FsmState sta
346
364
{
347
365
onStateExit_3 . TryInvokeActions ( self . FsmComponent ) ;
348
366
}
349
-
367
+
350
368
orig ( self , state ) ;
351
369
}
352
370
@@ -368,7 +386,7 @@ private static void TryInvokeActions(this Action<PlayMakerFSM> action, PlayMaker
368
386
}
369
387
}
370
388
}
371
-
389
+
372
390
private static void TryInvokeActions ( this Action < PlayMakerFSM , string > action , PlayMakerFSM fsm , string transition )
373
391
{
374
392
if ( action != null )
0 commit comments