Skip to content

Commit 5e1d768

Browse files
authored
genericised ProcessRules
1 parent ff0d732 commit 5e1d768

File tree

1 file changed

+23
-91
lines changed

1 file changed

+23
-91
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/MixedRealityInputManager.cs

Lines changed: 23 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Core.Definitions.Devices;
@@ -1746,49 +1746,40 @@ public void RaiseDictationError(IMixedRealityInputSource source, string dictatio
17461746

17471747
#region Rules
17481748

1749-
private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction, bool criteria)
1749+
private MixedRealityInputAction ProcessRules_Internal<T1, T2>(MixedRealityInputAction inputAction, T1[] inputActionRules, T2 criteria) where T1 : struct, IInputActionRule<T2>
17501750
{
1751-
if (CurrentInputActionRulesProfile != null)
1751+
for (int i = 0; i < inputActionRules.Length; i++)
17521752
{
1753-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesDigital;
1754-
1755-
for (int i = 0; i < digitalRules.Length; i++)
1753+
if (inputActionRules[i].BaseAction == inputAction && inputActionRules[i].Criteria.Equals(criteria))
17561754
{
1757-
if (digitalRules[i].BaseAction == inputAction && digitalRules[i].Criteria == criteria)
1755+
if (inputActionRules[i].RuleAction == inputAction)
17581756
{
1759-
if (digitalRules[i].RuleAction == inputAction)
1760-
{
1761-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1762-
return inputAction;
1763-
}
1764-
1765-
return digitalRules[i].RuleAction;
1757+
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1758+
return inputAction;
17661759
}
1760+
1761+
return inputActionRules[i].RuleAction;
17671762
}
17681763
}
17691764

17701765
return inputAction;
17711766
}
17721767

1773-
private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction, float criteria)
1768+
private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction, bool criteria)
17741769
{
17751770
if (CurrentInputActionRulesProfile != null)
17761771
{
1777-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesSingleAxis;
1772+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesDigital, criteria);
1773+
}
17781774

1779-
for (int i = 0; i < digitalRules.Length; i++)
1780-
{
1781-
if (digitalRules[i].BaseAction == inputAction && digitalRules[i].Criteria.Equals(criteria))
1782-
{
1783-
if (digitalRules[i].RuleAction == inputAction)
1784-
{
1785-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1786-
return inputAction;
1787-
}
1775+
return inputAction;
1776+
}
17881777

1789-
return digitalRules[i].RuleAction;
1790-
}
1791-
}
1778+
private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction, float criteria)
1779+
{
1780+
if (CurrentInputActionRulesProfile != null)
1781+
{
1782+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesSingleAxis, criteria);
17921783
}
17931784

17941785
return inputAction;
@@ -1798,24 +1789,7 @@ private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction
17981789
{
17991790
if (CurrentInputActionRulesProfile != null)
18001791
{
1801-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesDualAxis;
1802-
1803-
for (int i = 0; i < digitalRules.Length; i++)
1804-
{
1805-
if (digitalRules[i].BaseAction == inputAction)
1806-
{
1807-
if (digitalRules[i].Criteria == criteria)
1808-
{
1809-
if (digitalRules[i].RuleAction == inputAction)
1810-
{
1811-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1812-
return inputAction;
1813-
}
1814-
1815-
return digitalRules[i].RuleAction;
1816-
}
1817-
}
1818-
}
1792+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesDualAxis, criteria);
18191793
}
18201794

18211795
return inputAction;
@@ -1825,21 +1799,7 @@ private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction
18251799
{
18261800
if (CurrentInputActionRulesProfile != null)
18271801
{
1828-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesVectorAxis;
1829-
1830-
for (int i = 0; i < digitalRules.Length; i++)
1831-
{
1832-
if (digitalRules[i].BaseAction == inputAction && digitalRules[i].Criteria == criteria)
1833-
{
1834-
if (digitalRules[i].RuleAction == inputAction)
1835-
{
1836-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1837-
return inputAction;
1838-
}
1839-
1840-
return digitalRules[i].RuleAction;
1841-
}
1842-
}
1802+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesVectorAxis, criteria);
18431803
}
18441804

18451805
return inputAction;
@@ -1849,21 +1809,7 @@ private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction
18491809
{
18501810
if (CurrentInputActionRulesProfile != null)
18511811
{
1852-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesQuaternionAxis;
1853-
1854-
for (int i = 0; i < digitalRules.Length; i++)
1855-
{
1856-
if (digitalRules[i].BaseAction == inputAction && digitalRules[i].Criteria == criteria)
1857-
{
1858-
if (digitalRules[i].RuleAction == inputAction)
1859-
{
1860-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1861-
return inputAction;
1862-
}
1863-
1864-
return digitalRules[i].RuleAction;
1865-
}
1866-
}
1812+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesQuaternionAxis, criteria);
18671813
}
18681814

18691815
return inputAction;
@@ -1873,21 +1819,7 @@ private MixedRealityInputAction ProcessRules(MixedRealityInputAction inputAction
18731819
{
18741820
if (CurrentInputActionRulesProfile != null)
18751821
{
1876-
var digitalRules = CurrentInputActionRulesProfile.InputActionRulesPoseAxis;
1877-
1878-
for (int i = 0; i < digitalRules.Length; i++)
1879-
{
1880-
if (digitalRules[i].BaseAction == inputAction && digitalRules[i].Criteria == criteria)
1881-
{
1882-
if (digitalRules[i].RuleAction == inputAction)
1883-
{
1884-
Debug.LogError("Input Action Rule cannot be the same as the rule's Base Action!");
1885-
return inputAction;
1886-
}
1887-
1888-
return digitalRules[i].RuleAction;
1889-
}
1890-
}
1822+
ProcessRules_Internal(inputAction, CurrentInputActionRulesProfile.InputActionRulesPoseAxis, criteria);
18911823
}
18921824

18931825
return inputAction;

0 commit comments

Comments
 (0)