@@ -1305,101 +1305,104 @@ internal bool ResolveBindingsIfNecessary()
13051305 /// </remarks>
13061306 internal void ResolveBindings ( )
13071307 {
1308- k_ResolveBindingsProfilerMarker . Auto ( ) ;
1309- // Make sure that if we trigger callbacks as part of disabling and re-enabling actions,
1310- // we don't trigger a re-resolve while we're already resolving bindings.
1311- using ( InputActionRebindingExtensions . DeferBindingResolution ( ) )
1308+ using ( k_ResolveBindingsProfilerMarker . Auto ( ) )
13121309 {
1313- // In case we have actions that are currently enabled, we temporarily retain the
1314- // UnmanagedMemory of our InputActionState so that we can sync action states after
1315- // we have re-resolved bindings.
1316- var oldMemory = new InputActionState . UnmanagedMemory ( ) ;
1317- try
1310+ // Make sure that if we trigger callbacks as part of disabling and re-enabling actions,
1311+ // we don't trigger a re-resolve while we're already resolving bindings.
1312+ using ( InputActionRebindingExtensions . DeferBindingResolution ( ) )
13181313 {
1319- OneOrMore < InputActionMap , ReadOnlyArray < InputActionMap > > actionMaps ;
1314+ // In case we have actions that are currently enabled, we temporarily retain the
1315+ // UnmanagedMemory of our InputActionState so that we can sync action states after
1316+ // we have re-resolved bindings.
1317+ var oldMemory = new InputActionState . UnmanagedMemory ( ) ;
1318+ try
1319+ {
1320+ OneOrMore < InputActionMap , ReadOnlyArray < InputActionMap > > actionMaps ;
13201321
1321- // Start resolving.
1322- var resolver = new InputBindingResolver ( ) ;
1322+ // Start resolving.
1323+ var resolver = new InputBindingResolver ( ) ;
13231324
1324- // If we're part of an asset, we share state and thus binding resolution with
1325- // all maps in the asset.
1326- var needFullResolve = m_State == null ;
1327- if ( m_Asset != null )
1328- {
1329- actionMaps = m_Asset . actionMaps ;
1330- Debug . Assert ( actionMaps . Count > 0 , "Asset referred to by action map does not have action maps" ) ;
1325+ // If we're part of an asset, we share state and thus binding resolution with
1326+ // all maps in the asset.
1327+ var needFullResolve = m_State == null ;
1328+ if ( m_Asset != null )
1329+ {
1330+ actionMaps = m_Asset . actionMaps ;
1331+ Debug . Assert ( actionMaps . Count > 0 , "Asset referred to by action map does not have action maps" ) ;
13311332
1332- // If there's a binding mask set on the asset, apply it.
1333- resolver . bindingMask = m_Asset . m_BindingMask ;
1333+ // If there's a binding mask set on the asset, apply it.
1334+ resolver . bindingMask = m_Asset . m_BindingMask ;
13341335
1335- foreach ( var map in actionMaps )
1336+ foreach ( var map in actionMaps )
1337+ {
1338+ needFullResolve |= map . bindingResolutionNeedsFullReResolve ;
1339+ map . needToResolveBindings = false ;
1340+ map . bindingResolutionNeedsFullReResolve = false ;
1341+ map . controlsForEachActionInitialized = false ;
1342+ }
1343+ }
1344+ else
13361345 {
1337- needFullResolve |= map . bindingResolutionNeedsFullReResolve ;
1338- map . needToResolveBindings = false ;
1339- map . bindingResolutionNeedsFullReResolve = false ;
1340- map . controlsForEachActionInitialized = false ;
1346+ // Standalone action map (possibly a hidden one created for a singleton action).
1347+ // Gets its own private state.
1348+
1349+ actionMaps = this ;
1350+ needFullResolve |= bindingResolutionNeedsFullReResolve ;
1351+ needToResolveBindings = false ;
1352+ bindingResolutionNeedsFullReResolve = false ;
1353+ controlsForEachActionInitialized = false ;
13411354 }
1342- }
1343- else
1344- {
1345- // Standalone action map (possibly a hidden one created for a singleton action).
1346- // Gets its own private state.
1347-
1348- actionMaps = this ;
1349- needFullResolve |= bindingResolutionNeedsFullReResolve ;
1350- needToResolveBindings = false ;
1351- bindingResolutionNeedsFullReResolve = false ;
1352- controlsForEachActionInitialized = false ;
1353- }
13541355
1355- // If we already have a state, re-use the arrays we have already allocated.
1356- // NOTE: We will install the arrays on the very same InputActionState instance below. In the
1357- // case where we didn't have to grow the arrays, we should end up with zero GC allocations
1358- // here.
1359- var hasEnabledActions = false ;
1360- InputControlList < InputControl > activeControls = default ;
1361- if ( m_State != null )
1362- {
1363- // Grab a clone of the current memory. We clone because disabling all the actions
1364- // in the map will alter the memory state and we want the state before we start
1365- // touching it.
1366- oldMemory = m_State . memory . Clone ( ) ;
1356+ // If we already have a state, re-use the arrays we have already allocated.
1357+ // NOTE: We will install the arrays on the very same InputActionState instance below. In the
1358+ // case where we didn't have to grow the arrays, we should end up with zero GC allocations
1359+ // here.
1360+ var hasEnabledActions = false ;
1361+ InputControlList < InputControl > activeControls = default ;
1362+ if ( m_State != null )
1363+ {
1364+ // Grab a clone of the current memory. We clone because disabling all the actions
1365+ // in the map will alter the memory state and we want the state before we start
1366+ // touching it.
1367+ oldMemory = m_State . memory . Clone ( ) ;
13671368
1368- m_State . PrepareForBindingReResolution ( needFullResolve , ref activeControls , ref hasEnabledActions ) ;
1369+ m_State . PrepareForBindingReResolution ( needFullResolve , ref activeControls , ref hasEnabledActions ) ;
13691370
1370- // Reuse the arrays we have so that we can avoid managed memory allocations, if possible.
1371- resolver . StartWithPreviousResolve ( m_State , isFullResolve : needFullResolve ) ;
1371+ // Reuse the arrays we have so that we can avoid managed memory allocations, if possible.
1372+ resolver . StartWithPreviousResolve ( m_State , isFullResolve : needFullResolve ) ;
13721373
1373- // Throw away old memory.
1374- m_State . memory . Dispose ( ) ;
1375- }
1374+ // Throw away old memory.
1375+ m_State . memory . Dispose ( ) ;
1376+ }
1377+
1378+ // Resolve all maps in the asset.
1379+ foreach ( var map in actionMaps )
1380+ resolver . AddActionMap ( map ) ;
13761381
1377- // Resolve all maps in the asset.
1378- foreach ( var map in actionMaps )
1379- resolver . AddActionMap ( map ) ;
1382+ // Install state.
1383+ if ( m_State == null )
1384+ {
1385+ m_State = new InputActionState ( ) ;
1386+ m_State . Initialize ( resolver ) ;
1387+ }
1388+ else
1389+ {
1390+ m_State . ClaimDataFrom ( resolver ) ;
1391+ }
13801392
1381- // Install state.
1382- if ( m_State == null )
1383- {
1384- m_State = new InputActionState ( ) ;
1385- m_State . Initialize ( resolver ) ;
1386- }
1387- else
1388- {
1389- m_State . ClaimDataFrom ( resolver ) ;
1393+ if ( m_Asset != null )
1394+ {
1395+ foreach ( var map in actionMaps )
1396+ map . m_State = m_State ;
1397+ m_Asset . m_SharedStateForAllMaps = m_State ;
1398+ }
1399+
1400+ m_State . FinishBindingResolution ( hasEnabledActions , oldMemory , activeControls , isFullResolve : needFullResolve ) ;
13901401 }
1391- if ( m_Asset != null )
1402+ finally
13921403 {
1393- foreach ( var map in actionMaps )
1394- map . m_State = m_State ;
1395- m_Asset . m_SharedStateForAllMaps = m_State ;
1404+ oldMemory . Dispose ( ) ;
13961405 }
1397-
1398- m_State . FinishBindingResolution ( hasEnabledActions , oldMemory , activeControls , isFullResolve : needFullResolve ) ;
1399- }
1400- finally
1401- {
1402- oldMemory . Dispose ( ) ;
14031406 }
14041407 }
14051408 }
0 commit comments